1
0
mirror of https://github.com/jdhao/nvim-config.git synced 2025-06-08 14:14:33 +02:00

use treesitter-textobjects instead (#380)

Note that we should keep the branch of nvim-treesitter and nvim-treesitter-textobjects the same. `main` is targeted at nightly neovim and `master` is for stable neovim. See also https://github.com/nvim-treesitter/nvim-treesitter/issues/4767
This commit is contained in:
jdhao 2025-02-16 20:15:41 +01:00 committed by GitHub
parent 93166c65a5
commit ab059bbb6d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 52 additions and 4 deletions

View File

@ -0,0 +1,44 @@
require("nvim-treesitter.configs").setup {
textobjects = {
select = {
enable = true,
-- Automatically jump forward to textobj, similar to targets.vim
lookahead = true,
keymaps = {
-- You can use the capture groups defined in textobjects.scm
["af"] = "@function.outer",
["if"] = "@function.inner",
["ac"] = "@class.outer",
-- You can optionally set descriptions to the mappings (used in the desc parameter of
-- nvim_buf_set_keymap) which plugins like which-key display
["ic"] = { query = "@class.inner", desc = "Select inner part of a class region" },
},
-- You can choose the select mode (default is charwise 'v')
--
-- Can also be a function which gets passed a table with the keys
-- * query_string: eg '@function.inner'
-- * method: eg 'v' or 'o'
-- and should return the mode ('v', 'V', or '<c-v>') or a table
-- mapping query_strings to modes.
selection_modes = {
["@function.inner"] = "V", -- linewise
["@function.outer"] = "V", -- linewise
["@class.outer"] = "V", -- linewise
["@class.inner"] = "V", -- linewise
["@parameter.outer"] = "v", -- charwise
},
-- If you set this to `true` (default is `false`) then any textobject is
-- extended to include preceding or succeeding whitespace. Succeeding
-- whitespace has priority in order to act similarly to eg the built-in
-- `ap`.
--
-- Can also be a function which gets passed a table with the keys
-- * query_string: eg '@function.inner'
-- * selection_mode: eg 'v'
-- and should return true or false
include_surrounding_whitespace = false,
},
},
}

View File

@ -61,10 +61,14 @@ local plugin_specs = {
require("config.treesitter")
end,
},
-- Python-related text object
{ "jeetsukumaran/vim-pythonsense", ft = { "python" } },
{
"nvim-treesitter/nvim-treesitter-textobjects",
event = "VeryLazy",
branch = "master",
config = function()
require("config.treesitter-textobjects")
end,
},
{ "machakann/vim-swap", event = "VeryLazy" },
-- IDE for Lisp