Compare commits
1 Commits
78b8bf177c
...
treesitter
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
a086657031 |
@@ -30,7 +30,7 @@ vim.api.nvim_create_autocmd('SwapExists', {
|
|||||||
desc = 'Always choose to delete the swap file, files are saved automatically',
|
desc = 'Always choose to delete the swap file, files are saved automatically',
|
||||||
group = vim.api.nvim_create_augroup('NoSwaps', { clear = true }),
|
group = vim.api.nvim_create_augroup('NoSwaps', { clear = true }),
|
||||||
callback = function(args)
|
callback = function(args)
|
||||||
vim.cmd("let v:swapchoice = 'd'")
|
vim.cmd "let v:swapchoice = 'd'"
|
||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -116,4 +116,33 @@ vim.api.nvim_create_autocmd('BufWritePost', {
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd('FileType', {
|
||||||
|
pattern = {
|
||||||
|
'bash',
|
||||||
|
'c',
|
||||||
|
'diff',
|
||||||
|
'html',
|
||||||
|
'lua',
|
||||||
|
'luadoc',
|
||||||
|
'markdown',
|
||||||
|
'markdown_inline',
|
||||||
|
'query',
|
||||||
|
'vim',
|
||||||
|
'vimdoc',
|
||||||
|
'php',
|
||||||
|
'javascript',
|
||||||
|
'typescript',
|
||||||
|
'json',
|
||||||
|
},
|
||||||
|
callback = function()
|
||||||
|
-- syntax highlighting, provided by Neovim
|
||||||
|
vim.treesitter.start()
|
||||||
|
-- folds, provided by Neovim
|
||||||
|
vim.wo.foldexpr = 'v:lua.vim.treesitter.foldexpr()'
|
||||||
|
vim.wo.foldmethod = 'expr'
|
||||||
|
-- indentation, provided by nvim-treesitter
|
||||||
|
vim.bo.indentexpr = "v:lua.require'nvim-treesitter'.indentexpr()"
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
require('helpers').edit_cf('a', '/lua/autocmd.lua')
|
require('helpers').edit_cf('a', '/lua/autocmd.lua')
|
||||||
|
|||||||
@@ -30,13 +30,13 @@ vim.keymap.set('n', '<Leader>c', function()
|
|||||||
vim.treesitter.inspect_tree()
|
vim.treesitter.inspect_tree()
|
||||||
end, { desc = 'Treesitter' })
|
end, { desc = 'Treesitter' })
|
||||||
|
|
||||||
vim.keymap.set('n', '<C-S-D>', function()
|
-- vim.keymap.set('n', '<C-S-D>', function()
|
||||||
local node = vim.treesitter.get_node {}
|
-- local node = vim.treesitter.get_node {}
|
||||||
local range = { vim.treesitter.get_node_range(node) }
|
-- local range = { vim.treesitter.get_node_range(node) }
|
||||||
vim.api.nvim_win_set_cursor(0, { range[3] + 1, range[4] - 1 })
|
-- vim.api.nvim_win_set_cursor(0, { range[3] + 1, range[4] - 1 })
|
||||||
vim.fn.setpos("'x", { 0, range[1] + 1, range[2] + 1, 0 })
|
-- vim.fn.setpos("'x", { 0, range[1] + 1, range[2] + 1, 0 })
|
||||||
vim.cmd.normal 'v`x'
|
-- vim.cmd.normal 'v`x'
|
||||||
end, { desc = 'Select surrounding treesitter node' })
|
-- end, { desc = 'Select surrounding treesitter node' })
|
||||||
|
|
||||||
vim.keymap.set('v', '<C-S-D>', function()
|
vim.keymap.set('v', '<C-S-D>', function()
|
||||||
local start = vim.api.nvim_win_get_cursor(0)
|
local start = vim.api.nvim_win_get_cursor(0)
|
||||||
@@ -258,7 +258,6 @@ vim.keymap.set('n', '<Leader>]', '<CMD>cnext<CR>', { desc = 'Next item in quickf
|
|||||||
vim.keymap.set('n', '<Leader>[', '<CMD>cprevious<CR>', { desc = 'Previous item in quickfix list' })
|
vim.keymap.set('n', '<Leader>[', '<CMD>cprevious<CR>', { desc = 'Previous item in quickfix list' })
|
||||||
vim.keymap.set('n', 'gd', '<CMD>Telescope lsp_definitions<CR>', { desc = 'Go to definition' })
|
vim.keymap.set('n', 'gd', '<CMD>Telescope lsp_definitions<CR>', { desc = 'Go to definition' })
|
||||||
|
|
||||||
|
|
||||||
local function open_test()
|
local function open_test()
|
||||||
require('neotest').summary.open()
|
require('neotest').summary.open()
|
||||||
require('neotest').output_panel.open()
|
require('neotest').output_panel.open()
|
||||||
|
|||||||
@@ -1,86 +1,153 @@
|
|||||||
|
-- Highlight, edit, and navigate code
|
||||||
return {
|
return {
|
||||||
'nvim-treesitter/nvim-treesitter-textobjects',
|
-- 'nvim-treesitter/nvim-treesitter-textobjects',
|
||||||
dependencies = {
|
-- lazy = true,
|
||||||
'nvim-treesitter/nvim-treesitter',
|
-- branch = 'main',
|
||||||
},
|
-- dependencies = {
|
||||||
lazy = false,
|
-- 'nvim-treesitter/nvim-treesitter',
|
||||||
enabled = true,
|
-- },
|
||||||
config = function()
|
-- config = function()
|
||||||
require('nvim-treesitter.configs').setup {
|
-- -- configuration
|
||||||
incremental_selection = {
|
-- require('nvim-treesitter-textobjects').setup {
|
||||||
enable = true,
|
-- select = {
|
||||||
keymaps = {
|
-- lookahead = true,
|
||||||
-- mappings for incremental selection (visual mappings)
|
-- selection_modes = {
|
||||||
init_selection = 'gnn', -- maps in normal mode to init the node/scope selection
|
-- ['@parameter.outer'] = 'v', -- charwise
|
||||||
node_incremental = 'grn', -- increment to the upper named parent
|
-- ['@function.outer'] = 'V', -- linewise
|
||||||
scope_incremental = 'grc', -- increment to the upper scope (as defined in locals.scm)
|
-- ['@class.outer'] = 'V', -- blockwise
|
||||||
node_decremental = 'grm', -- decrement to the previous node
|
-- },
|
||||||
},
|
-- include_surrounding_whitespace = false,
|
||||||
},
|
-- },
|
||||||
|
-- move = {
|
||||||
|
-- set_jumps = true,
|
||||||
|
-- },
|
||||||
|
-- }
|
||||||
|
|
||||||
textobjects = {
|
-- for keys, query in
|
||||||
-- syntax-aware textobjects
|
-- {
|
||||||
enable = true,
|
-- -- or you use the queries from supported languages with textobjects.scm
|
||||||
keymaps = {
|
-- ['af'] = '@function.outer',
|
||||||
['iL'] = {
|
-- ['if'] = '@function.inner',
|
||||||
-- you can define your own textobjects directly here
|
-- ['aC'] = '@class.outer',
|
||||||
go = '(function_definition) @function',
|
-- ['iC'] = '@class.inner',
|
||||||
},
|
-- ['ay'] = '@conditional.outer',
|
||||||
-- or you use the queries from supported languages with textobjects.scm
|
-- ['iy'] = '@conditional.inner',
|
||||||
['af'] = '@function.outer',
|
-- ['aj'] = '@loop.outer',
|
||||||
['if'] = '@function.inner',
|
-- ['ij'] = '@loop.inner',
|
||||||
['aC'] = '@class.outer',
|
-- ['is'] = '@statement.inner',
|
||||||
['iC'] = '@class.inner',
|
-- ['as'] = '@statement.outer',
|
||||||
['ay'] = '@conditional.outer',
|
-- ['ac'] = '@comment.outer',
|
||||||
['iy'] = '@conditional.inner',
|
-- ['ic'] = '@comment.inner',
|
||||||
['aj'] = '@loop.outer',
|
-- ['ap'] = '@comment.parameter',
|
||||||
['ij'] = '@loop.inner',
|
-- ['ip'] = '@comment.parameter',
|
||||||
['is'] = '@statement.inner',
|
-- ['an'] = '@local.scope',
|
||||||
['as'] = '@statement.outer',
|
-- }
|
||||||
['ac'] = '@comment.outer',
|
-- do
|
||||||
['ic'] = '@comment.inner',
|
-- vim.keymap.set({ 'n', 'x', 'o' }, keys, function()
|
||||||
['ap'] = '@comment.parameter',
|
-- require('nvim-treesitter-textobjects.select').select_textobject(query, 'textobjects')
|
||||||
['ip'] = '@comment.parameter',
|
-- end)
|
||||||
},
|
-- end
|
||||||
move = {
|
|
||||||
enable = true,
|
-- for keys, query in
|
||||||
set_jumps = true, -- whether to set jumps in the jumplist
|
-- {
|
||||||
goto_next_start = {
|
-- -- or you use the queries from supported languages with textobjects.scm
|
||||||
[']m'] = '@function.outer',
|
-- [']'] = '@function.outer',
|
||||||
[']]'] = '@class.outer',
|
-- ['o'] = { '@loop.inner', '@loop.outer' },
|
||||||
},
|
-- ['n'] = '@local.scope',
|
||||||
goto_next_end = {
|
-- ['y'] = '@conditional.outer',
|
||||||
[']M'] = '@function.outer',
|
-- ['e'] = '@statement.outer',
|
||||||
[']['] = '@class.outer',
|
-- ['/'] = '@comment.outer',
|
||||||
},
|
-- }
|
||||||
goto_previous_start = {
|
-- do
|
||||||
['[m'] = '@function.outer',
|
-- vim.keymap.set({ 'n', 'x', 'o' }, ']' .. keys, function()
|
||||||
['[['] = '@class.outer',
|
-- require('nvim-treesitter-textobjects.move').goto_next_start(query, 'textobjects')
|
||||||
},
|
-- end)
|
||||||
goto_previous_end = {
|
-- vim.keymap.set({ 'n', 'x', 'o' }, '[' .. keys, function()
|
||||||
['[M'] = '@function.outer',
|
-- require('nvim-treesitter-textobjects.move').goto_previous_start(query, 'textobjects')
|
||||||
['[]'] = '@class.outer',
|
-- end)
|
||||||
},
|
-- end
|
||||||
},
|
-- -- require('nvim-treesitter.configs').setup {
|
||||||
select = {
|
-- -- incremental_selection = {
|
||||||
enable = true,
|
-- -- enable = true,
|
||||||
keymaps = {
|
-- -- keymaps = {
|
||||||
-- You can use the capture groups defined in textobjects.scm
|
-- -- -- mappings for incremental selection (visual mappings)
|
||||||
['af'] = '@function.outer',
|
-- -- init_selection = '<C-S-D>', -- maps in normal mode to init the node/scope selection
|
||||||
['if'] = '@function.inner',
|
-- -- node_incremental = '<C-S-D>', -- increment to the upper named parent
|
||||||
['ac'] = '@class.outer',
|
-- -- scope_incremental = '<C-S-U>', -- increment to the upper scope (as defined in locals.scm)
|
||||||
['ic'] = '@class.inner',
|
-- -- node_decremental = '<C-S-S>', -- decrement to the previous node
|
||||||
-- Or you can define your own textobjects like this
|
-- -- },
|
||||||
['iF'] = {
|
-- -- },
|
||||||
python = '(function_definition) @function',
|
|
||||||
cpp = '(function_definition) @function',
|
-- -- textobjects = {
|
||||||
c = '(function_definition) @function',
|
-- -- -- syntax-aware textobjects
|
||||||
java = '(method_declaration) @function',
|
-- -- enable = true,
|
||||||
go = '(method_declaration) @function',
|
-- -- keymaps = {
|
||||||
},
|
-- -- ['iL'] = {
|
||||||
},
|
-- -- -- you can define your own textobjects directly here
|
||||||
},
|
-- -- go = '(function_definition) @function',
|
||||||
},
|
-- -- },
|
||||||
}
|
-- -- -- or you use the queries from supported languages with textobjects.scm
|
||||||
end,
|
-- -- ['af'] = '@function.outer',
|
||||||
|
-- -- ['if'] = '@function.inner',
|
||||||
|
-- -- ['aC'] = '@class.outer',
|
||||||
|
-- -- ['iC'] = '@class.inner',
|
||||||
|
-- -- ['ay'] = '@conditional.outer',
|
||||||
|
-- -- ['iy'] = '@conditional.inner',
|
||||||
|
-- -- ['aj'] = '@loop.outer',
|
||||||
|
-- -- ['ij'] = '@loop.inner',
|
||||||
|
-- -- ['is'] = '@statement.inner',
|
||||||
|
-- -- ['as'] = '@statement.outer',
|
||||||
|
-- -- ['ac'] = '@comment.outer',
|
||||||
|
-- -- ['ic'] = '@comment.inner',
|
||||||
|
-- -- ['ap'] = '@comment.parameter',
|
||||||
|
-- -- ['ip'] = '@comment.parameter',
|
||||||
|
-- -- },
|
||||||
|
-- -- move = {
|
||||||
|
-- -- enable = true,
|
||||||
|
-- -- set_jumps = true, -- whether to set jumps in the jumplist
|
||||||
|
-- -- goto_next_start = {
|
||||||
|
-- -- [']m'] = '@function.outer',
|
||||||
|
-- -- [']]'] = '@class.outer',
|
||||||
|
-- -- },
|
||||||
|
-- -- goto_next_end = {
|
||||||
|
-- -- [']M'] = '@function.outer',
|
||||||
|
-- -- [']['] = '@class.outer',
|
||||||
|
-- -- },
|
||||||
|
-- -- goto_previous_start = {
|
||||||
|
-- -- ['[m'] = '@function.outer',
|
||||||
|
-- -- ['[['] = '@class.outer',
|
||||||
|
-- -- },
|
||||||
|
-- -- goto_previous_end = {
|
||||||
|
-- -- ['[M'] = '@function.outer',
|
||||||
|
-- -- ['[]'] = '@class.outer',
|
||||||
|
-- -- },
|
||||||
|
-- -- },
|
||||||
|
-- -- select = {
|
||||||
|
-- -- enable = true,
|
||||||
|
-- -- keymaps = {
|
||||||
|
-- -- -- You can use the capture groups defined in textobjects.scm
|
||||||
|
-- -- ['af'] = '@function.outer',
|
||||||
|
-- -- ['if'] = '@function.inner',
|
||||||
|
-- -- ['ac'] = '@class.outer',
|
||||||
|
-- -- ['ic'] = '@class.inner',
|
||||||
|
-- -- -- Or you can define your own textobjects like this
|
||||||
|
-- -- ['iF'] = {
|
||||||
|
-- -- python = '(function_definition) @function',
|
||||||
|
-- -- cpp = '(function_definition) @function',
|
||||||
|
-- -- c = '(function_definition) @function',
|
||||||
|
-- -- java = '(method_declaration) @function',
|
||||||
|
-- -- go = '(method_declaration) @function',
|
||||||
|
-- -- },
|
||||||
|
-- -- },
|
||||||
|
-- -- },
|
||||||
|
-- -- },
|
||||||
|
-- -- }
|
||||||
|
-- end,
|
||||||
|
-- opts = {},
|
||||||
|
-- -- There are additional nvim-treesitter modules that you can use to interact
|
||||||
|
-- -- with nvim-treesitter. You should go explore a few and see what interests you:
|
||||||
|
-- --
|
||||||
|
-- -- - Incremental selection: Included, see `:help nvim-treesitter-incremental-selection-mod`
|
||||||
|
-- -- - Show your current context: https://github.com/nvim-treesitter/nvim-treesitter-context
|
||||||
|
-- -- - Treesitter + textobjects: https://github.com/nvim-treesitter/nvim-treesitter-textobjects
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,10 +2,11 @@
|
|||||||
return {
|
return {
|
||||||
'nvim-treesitter/nvim-treesitter',
|
'nvim-treesitter/nvim-treesitter',
|
||||||
build = ':TSUpdate',
|
build = ':TSUpdate',
|
||||||
main = 'nvim-treesitter.configs', -- Sets main module to use for opts
|
branch = 'main',
|
||||||
-- [[ Configure Treesitter ]] See `:help nvim-treesitter`
|
-- [[ Configure Treesitter ]] See `:help nvim-treesitter`
|
||||||
opts = {
|
config = function()
|
||||||
ensure_installed = {
|
require('nvim-treesitter').setup {}
|
||||||
|
require('nvim-treesitter').install {
|
||||||
'bash',
|
'bash',
|
||||||
'c',
|
'c',
|
||||||
'diff',
|
'diff',
|
||||||
@@ -17,18 +18,13 @@ return {
|
|||||||
'query',
|
'query',
|
||||||
'vim',
|
'vim',
|
||||||
'vimdoc',
|
'vimdoc',
|
||||||
},
|
'php',
|
||||||
-- Autoinstall languages that are not installed
|
'javascript',
|
||||||
auto_install = true,
|
'typescript',
|
||||||
highlight = {
|
'json',
|
||||||
enable = true,
|
}
|
||||||
-- Some languages depend on vim's regex highlighting system (such as Ruby) for indent rules.
|
end,
|
||||||
-- If you are experiencing weird indenting issues, add the language to
|
opts = {},
|
||||||
-- the list of additional_vim_regex_highlighting and disabled languages for indent.
|
|
||||||
additional_vim_regex_highlighting = { 'ruby' },
|
|
||||||
},
|
|
||||||
indent = { enable = true, disable = { 'ruby' } },
|
|
||||||
},
|
|
||||||
-- There are additional nvim-treesitter modules that you can use to interact
|
-- There are additional nvim-treesitter modules that you can use to interact
|
||||||
-- with nvim-treesitter. You should go explore a few and see what interests you:
|
-- with nvim-treesitter. You should go explore a few and see what interests you:
|
||||||
--
|
--
|
||||||
|
|||||||
Reference in New Issue
Block a user