textobjects.lua (2359B)
1 return { 2 "nvim-treesitter/nvim-treesitter-textobjects", 3 dependencies = { "nvim-treesitter" }, 4 config = function() 5 require("nvim-treesitter.configs").setup({ 6 textobjects = { 7 move = { 8 enable = true, 9 set_jumps = true, 10 goto_next_start = { 11 ["[f"] = "@function.outer", 12 ["]["] = "@class.outer", 13 }, 14 goto_previous_start = { 15 ["]f"] = "@function.outer", 16 ["[["] = "@class.outer", 17 }, 18 goto_previous_end = { 19 ["[F"] = "@function.outer", 20 ["[]"] = "@class.outer", 21 }, 22 }, 23 select = { 24 enable = true, 25 26 -- Automatically jump forward to textobj, similar to targets.vim 27 lookahead = true, 28 29 keymaps = { 30 -- You can use the capture groups defined in textobjects.scm 31 ["af"] = "@function.outer", 32 ["if"] = "@function.inner", 33 -- You can optionally set descriptions to the mappings (used in the desc parameter of 34 -- nvim_buf_set_keymap) which plugins like which-key display 35 ["ic"] = { query = "@class.inner", desc = "Select inner part of a class region" }, 36 ["ac"] = { query = "@class.outer", desc = "Select outer part of a class region" }, 37 -- You can also use captures from other query groups like `locals.scm` 38 ["as"] = { query = "@local.scope", query_group = "locals", desc = "Select language scope" }, 39 }, 40 -- You can choose the select mode (default is charwise 'v') 41 -- 42 -- Can also be a function which gets passed a table with the keys 43 -- * query_string: eg '@function.inner' 44 -- * method: eg 'v' or 'o' 45 -- and should return the mode ('v', 'V', or '<c-v>') or a table 46 -- mapping query_strings to modes. 47 selection_modes = { 48 ["@parameter.outer"] = "v", -- charwise 49 ["@function.outer"] = "V", -- linewise 50 ["@class.outer"] = "<c-v>", -- blockwise 51 }, 52 -- If you set this to `true` (default is `false`) then any textobject is 53 -- extended to include preceding or succeeding whitespace. Succeeding 54 -- whitespace has priority in order to act similarly to eg the built-in 55 -- `ap`. 56 -- 57 -- Can also be a function which gets passed a table with the keys 58 -- * query_string: eg '@function.inner' 59 -- * selection_mode: eg 'v' 60 -- and should return true or false 61 include_surrounding_whitespace = true, 62 }, 63 }, 64 }) 65 end, 66 }