feat: Replacement of the autopairs plugin using snippets, extension of

snippets (mainly python) and cleanup of keymappings for snippets.
This commit is contained in:
2026-06-11 06:46:40 -05:00
parent c3fad7d51f
commit 4d291369e3
6 changed files with 74 additions and 46 deletions

View File

@@ -3,9 +3,9 @@ return {
pylsp = { pylsp = {
plugins = { plugins = {
pycodestyle = { pycodestyle = {
enabled = false, enabled = true,
ignore = { ignore = {
'E501' 'E501' -- line-too-long
}, },
maxLineLength = 120, maxLineLength = 120,
}, },
@@ -13,7 +13,6 @@ return {
enabled = true, enabled = true,
args = { args = {
'--disable=line-too-long', '--disable=line-too-long',
'--disable=missing-function-docstring'
}, },
} }
} }

View File

@@ -17,13 +17,11 @@ vim.schedule(function()
require('plugins.render-markdown') -- Render markdown directly in neovim require('plugins.render-markdown') -- Render markdown directly in neovim
vim.pack.add({ vim.pack.add({
'https://github.com/windwp/nvim-autopairs', -- Autocomplete symbol pairs when typing
'https://github.com/tpope/vim-surround', -- Change surrounding characters (doesn't need setup called) 'https://github.com/tpope/vim-surround', -- Change surrounding characters (doesn't need setup called)
'https://github.com/tpope/vim-fugitive', -- _The_ Git integration plugin people have been using forever 'https://github.com/tpope/vim-fugitive', -- _The_ Git integration plugin people have been using forever
'https://github.com/habamax/vim-godot' -- Godot specific bindings and debug 'https://github.com/habamax/vim-godot' -- Godot specific bindings and debug
}) })
require('nvim-autopairs').setup() -- Automatic pair completion of paranteticals, braces, quotes, etc.
require('plugins.dap') -- DAP debugging plugin require('plugins.dap') -- DAP debugging plugin
require('plugins.dap-python') -- Debug plugin settings specifically for python require('plugins.dap-python') -- Debug plugin settings specifically for python

View File

@@ -1,5 +1,5 @@
vim.pack.add({ vim.pack.add({
-- 'https://github.com/saadparwaiz1/cmp_luasnip', 'https://github.com/saadparwaiz1/cmp_luasnip',
'https://github.com/rafamadriz/friendly-snippets', 'https://github.com/rafamadriz/friendly-snippets',
'https://github.com/L3MON4D3/LuaSnip' 'https://github.com/L3MON4D3/LuaSnip'
}) })
@@ -18,7 +18,8 @@ local function luasnip_dependency_update()
if out.code == 0 then if out.code == 0 then
vim.notify('LuaSnip jsregexp built successfully!', vim.log.levels.INFO) vim.notify('LuaSnip jsregexp built successfully!', vim.log.levels.INFO)
else else
vim.notify('Failed to build LuaSnip jsregexp:\n' .. (out.stderr or out.stdout or ''), vim.log.levels.ERROR) vim.notify('Failed to build LuaSnip jsregexp:\n' .. (out.stderr or out.stdout or ''),
vim.log.levels.ERROR)
end end
end) end)
end) end)
@@ -42,6 +43,6 @@ require('luasnip.loaders.from_vscode').lazy_load()
require('luasnip.loaders.from_lua').lazy_load({ paths = "./snippets" }) require('luasnip.loaders.from_lua').lazy_load({ paths = "./snippets" })
-- TODO: Figure out keymappings that make sense -- TODO: Figure out keymappings that make sense
vim.keymap.set({ 'i' }, '<C-k>', function() require('luasnip').expand() end, { silent = true }) vim.keymap.set({ 'i' }, '<C-K>', function() require('luasnip').expand() end, { silent = true })
vim.keymap.set({ 'i', 's' }, '<C-l>', function() require('luasnip').jump(1) end, { silent = true }) vim.keymap.set({ 'i', 's' }, '<C-L>', function() require('luasnip').jump(1) end, { silent = true })
vim.keymap.set({ 'i', 's' }, '<C-j>', function() require('luasnip').jump(-1) end, { silent = true }) vim.keymap.set({ 'i', 's' }, '<C-H>', function() require('luasnip').jump(-1) end, { silent = true })

36
nvim/snippets/all.lua Normal file
View File

@@ -0,0 +1,36 @@
-- require('luasnip.session.snippet_collection').clear_snippets('all')
local ls = require('luasnip')
local s = ls.snippet
local sn = ls.snippet_node
local i = ls.insert_node
local t = ls.text_node
local c = ls.choice_node
local r = ls.restore_node
-- Replacement of autopairs
local function pair(pair_begin, pair_end)
-- Auto-pair using snippets
return s({ trig = pair_begin, wordTrig = false }, {
t({ pair_begin }),
c(1, {
r(1, "content", i(1)),
sn(nil, { t({"", "\t"}), r(1, "content", i(1)), t({ "", "" }) }),
}),
t({ pair_end }),
})
end
ls.add_snippets('all', {
pair('(', ')'),
pair('{', '}'),
pair('[', ']'),
pair('<', '>'),
pair("'", "'"),
pair('"', '"'),
pair('`', '`'),
}, {
type = 'autosnippets',
key = 'all_auto',
})
-- end autopairs

View File

@@ -1,44 +1,36 @@
local ls = require('luasnip') local ls = require('luasnip')
local s = ls.snippet local s = ls.snippet
-- local sn = ls.snippet_node
local i = ls.insert_node local i = ls.insert_node
local t = ls.text_node local t = ls.text_node
local l = require('luasnip.extras').lambda -- local l = require('luasnip.extras').lambda
local fmt = require('luasnip.extras.fmt').fmt local fmt = require('luasnip.extras.fmt').fmt
local ts_post = require('luasnip.extras.treesitter_postfix').treesitter_postfix -- local ts_post = require('luasnip.extras.treesitter_postfix').treesitter_postfix
return { ls.add_snippets('python', {
ts_post({ s('docstring single', {
matchTSNode = { t("''' "), i(0, 'text'), t(" '''")
query = [[ }),
(function_definition s('def', fmt([[
parameters: (parameters) @params def {func}({args}) -> {ret}:
return_type: (type) @return ''' {doc} '''
) @prefix {body}
]],
query_lang = "python",
},
trig = "docstring",
}, fmt([[
''' {}
Keyword arguments:
{} () -
Return:
{} - {}
'''
]], { ]], {
i(1, 'Description'), func = i(1, 'fname'),
l(l.LS_TSCAPTURE_PARAMS), args = i(2),
l(l.LS_TSCAPTURE_RETURN), ret = i(3, 'None'),
l(l.LS_TSDATA), doc = i(4, 'docstring'),
body = i(5, 'pass'),
}, {
})), })),
-- s( s('ternary', {
-- { trig = "thingy" }, i(1, 'then'), t(' if '), i(2, 'condition'), t(' else '), i(3, 'else')
-- { t('Woot!') } }),
-- ), s('tuple ternary', fmt([[
-- s( ({if_true}, {if_false})[{condition}]
-- { trig = 'thingy2' }, ]], {
-- { t('Woot2!') } if_true = i(1, 'if_true'),
-- ) if_false = i(2, 'if_false'),
} condition = i(3, 'condition'),
})),
})

View File

@@ -53,6 +53,8 @@ if wezterm.target_triple == 'x86_64-unknown-linux-gnu' then
config.xcursor_theme = xcursor_theme config.xcursor_theme = xcursor_theme
config.xcursor_size = xcursor_size config.xcursor_size = xcursor_size
-- end cursor theme -- end cursor theme
config.disable_default_key_bindings = true
end end
local local_config_filename = os.getenv('HOME') .. '/.config/wezterm/local.lua' local local_config_filename = os.getenv('HOME') .. '/.config/wezterm/local.lua'