autopairs + cleanup

This commit is contained in:
iofq 2025-08-07 02:16:42 -05:00
parent 4b7636090f
commit d01db43a23
15 changed files with 176 additions and 204 deletions

View file

@ -1,7 +1,6 @@
-- create undopath
local undopath = vim.fn.stdpath('data') .. 'undo'
vim.api.nvim_create_autocmd('VimEnter', {
command = 'silent !mkdir -p ' .. undopath,
command = 'silent !mkdir -p ' .. vim.fn.stdpath('data') .. 'undo',
group = vim.api.nvim_create_augroup('Init', {}),
})
@ -55,3 +54,57 @@ vim.api.nvim_create_autocmd({ 'FocusGained', 'TermClose', 'TermLeave' }, {
end
end,
})
-- Init treesitter
vim.api.nvim_create_autocmd('FileType', {
callback = function(event)
local bufnr = event.buf
local filetype = vim.api.nvim_get_option_value('filetype', { buf = bufnr })
if filetype == '' then
return
end
local parser_name = vim.treesitter.language.get_lang(filetype)
if not parser_name then
return
end
local parser_installed = pcall(vim.treesitter.get_parser, bufnr, parser_name)
if not parser_installed then
return
end
local function map(lhs, rhs, opts)
if lhs == '' then
return
end
opts = vim.tbl_deep_extend('force', { silent = true }, opts or {})
vim.keymap.set({ 'v', 'n' }, lhs, rhs, opts)
end
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
vim.treesitter.start()
map('[c', function()
require('treesitter-context').go_to_context(vim.v.count1)
end, { desc = 'jump to TS context' })
map(']f', function()
require('nvim-treesitter-textobjects.move').goto_next_start('@function.outer', 'textobjects')
end, { desc = 'next function def' })
map('[f', function()
require('nvim-treesitter-textobjects.move').goto_previous_start('@function.outer', 'textobjects')
end, { desc = 'prev function def' })
map(']a', function()
require('nvim-treesitter-textobjects.move').goto_next_start('@parameter.inner', 'textobjects')
end, { desc = 'next param def' })
map('[a', function()
require('nvim-treesitter-textobjects.move').goto_previous_start('@parameter.inner', 'textobjects')
end, { desc = 'prev param def' })
map('a]', function()
require('nvim-treesitter-textobjects.swap').swap_next('@parameter.inner')
end, { desc = 'swap next arg' })
map('a[', function()
require('nvim-treesitter-textobjects.swap').swap_previous('@parameter.inner')
end, { desc = 'swap prev arg' })
end,
})