diff options
| -rw-r--r-- | README.md | 31 | ||||
| -rw-r--r-- | doc/nvim-treesitter.txt | 42 | ||||
| -rw-r--r-- | lua/nvim-treesitter/textobjects.lua | 1 |
3 files changed, 72 insertions, 2 deletions
@@ -133,6 +133,34 @@ require'nvim-treesitter.configs'.setup { } } }, + textobjects = { -- syntax-aware textobjects + enable = true, + disable = {}, + keymaps = { + ["iL"] = { -- you can define your own textobjects directly here + python = "(function_definition) @function", + cpp = "(function_definition) @function", + c = "(function_definition) @function", + java = "(method_declaration) @function" + }, + -- or you use the queries from supported languages with textobjects.scm + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["aC"] = "@class.outer", + ["iC"] = "@class.inner", + ["ac"] = "@conditional.outer", + ["ic"] = "@conditional.inner", + ["ae"] = "@block.outer", + ["ie"] = "@block.inner", + ["al"] = "@loop.outer", + ["il"] = "@loop.inner", + ["is"] = "@statement.inner", + ["as"] = "@statement.outer", + ["ad"] = "@comment.outer", + ["am"] = "@call.outer", + ["im"] = "@call.inner" + } + }, ensure_installed = 'all' -- one of 'all', 'language', or a list of languages } EOF @@ -171,6 +199,7 @@ The roadmap and all features of this plugin are open to change, and any suggesti - `refactor.navigation`: Syntax based definition listing and navigation. * List all definitions * Go to definition +- `textobjects`: Vim textobjects defined by treesitter queries ## Defining Modules @@ -217,7 +246,7 @@ More information is available in the help file (`:help nvim-treesitter-utils`). ## Supported Languages -For treesitter to work, we need to use query files such as those you can find in +For `nvim-treesitter` to work, we need to use query files such as those you can find in `queries/{lang}/{locals,highlights,textobjects}.scm` We are looking for maintainers to write query files for their languages. diff --git a/doc/nvim-treesitter.txt b/doc/nvim-treesitter.txt index 5b619f8c4..3b08e662b 100644 --- a/doc/nvim-treesitter.txt +++ b/doc/nvim-treesitter.txt @@ -47,6 +47,48 @@ By default, everything is disabled. To enable support for features, in your `ini node_decremental = "grm", -- decrement to the previous node } }, + refactor = { + highlight_defintions = { + enable = true + }, + smart_rename = { + enable = true, + smart_rename = "grr" -- mapping to rename reference under cursor + }, + navigation = { + enable = true, + goto_definition = "gnd", -- mapping to go to definition of symbol under cursor + list_definitions = "gnD" -- mapping to list all definitions in current file + } + }, + textobjects = { -- syntax-aware textobjects + enable = true, + disable = {}, + keymaps = { + ["iL"] = { -- you can define your own textobjects directly here + python = "(function_definition) @function", + cpp = "(function_definition) @function", + c = "(function_definition) @function", + java = "(method_declaration) @function" + }, + -- or you use the queries from supported languages with textobjects.scm + ["af"] = "@function.outer", + ["if"] = "@function.inner", + ["aC"] = "@class.outer", + ["iC"] = "@class.inner", + ["ac"] = "@conditional.outer", + ["ic"] = "@conditional.inner", + ["ae"] = "@block.outer", + ["ie"] = "@block.inner", + ["al"] = "@loop.outer", + ["il"] = "@loop.inner", + ["is"] = "@statement.inner", + ["as"] = "@statement.outer", + ["ad"] = "@comment.outer", + ["am"] = "@call.outer", + ["im"] = "@call.inner" + } + }, ensure_installed = 'all' -- one of 'all', 'language', or a list of languages } EOF diff --git a/lua/nvim-treesitter/textobjects.lua b/lua/nvim-treesitter/textobjects.lua index cf81b5963..4d8bb7cd1 100644 --- a/lua/nvim-treesitter/textobjects.lua +++ b/lua/nvim-treesitter/textobjects.lua @@ -27,7 +27,6 @@ function M.select_textobject(query_string) local root = parser:parse():root() local start_row, _, end_row, _ = root:range() - local nested = {} local query = ts.parse_query(lang, query_string) for m in queries.iter_prepared_matches(query, root, bufnr, start_row, end_row) do for _, n in pairs(m) do |
