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