feat(vim): add nvim-treesitter-textobjects

I have been wanting to play with this plugin for a long time now. I have
a minimal config that will give me most of what I need. Moving
parameters and arguments is a big one. Also selecting parameters, this
will also include the type definition so its much more powerful than
selecting words.

Jumping to functions has also been included, right now I am not sure how
much that will be used. My muscle memory is very used to <C-d> and <C-u>
for paging.
This commit is contained in:
Ade Attwood 2024-06-14 18:03:07 +01:00
parent 2f2e59a8c3
commit 6cbd7eb9ae
2 changed files with 37 additions and 3 deletions

View file

@ -39,6 +39,7 @@ local start_plugins = {
["nvim-lint"] = { url = "https://github.com/mfussenegger/nvim-lint.git" },
["nvim-lspconfig"] = { url = "https://github.com/neovim/nvim-lspconfig.git" },
["nvim-treesitter"] = { url = "https://github.com/nvim-treesitter/nvim-treesitter.git" },
["nvim-treesitter-textobjects"] = { url = "https://github.com/nvim-treesitter/nvim-treesitter-textobjects.git" },
["vim-surround"] = { url = "https://github.com/tpope/vim-surround.git" },
["vim-tmux-navigator"] = { url = "https://github.com/christoomey/vim-tmux-navigator.git" },
["cmp-cmdline"] = { url = "https://github.com/hrsh7th/cmp-cmdline.git", revision = "main" },

View file

@ -1,16 +1,49 @@
require("nvim-treesitter.configs").setup {
auto_install = true,
playground = { enable = true },
indent = { enable = false },
indent = { enable = true },
rainbow = { enable = true },
highlight = {
-- `false` will disable the whole extension
enable = true,
additional_vim_regex_highlighting = true,
additional_vim_regex_highlighting = false,
},
textobjects = {
select = {
enable = true,
keymaps = {
["af"] = "@function.outer",
["if"] = "@function.inner",
["aa"] = "@parameter.outer", -- this is also arguments
["ia"] = "@parameter.inner", -- this is also arguments
["ab"] = "@block.outer",
["ib"] = "@block.inner",
["ac"] = "@comment.outer",
["ic"] = "@comment.inner",
},
},
move = {
enable = true,
set_jumps = true,
goto_next_start = {
["]f"] = "@function.outer",
},
goto_previous_start = {
["[f"] = "@function.outer",
},
},
swap = {
enable = true,
swap_next = {
["L"] = "@parameter.inner",
},
swap_previous = {
["H"] = "@parameter.inner",
},
},
},
}
vim.opt.foldmethod = "expr"
vim.opt.foldexpr = "nvim_treesitter#foldexpr()"
vim.opt.foldenable = false