From bb7a9912fb933898778302588dfac0c3f7cf877a Mon Sep 17 00:00:00 2001 From: jiangyinzuo Date: Sun, 21 Apr 2024 14:04:21 +0800 Subject: [PATCH] feat(nvim): treesitter-based textobject --- root/.config/nvim/lua/plugins/init.lua | 48 +++++++++++++++++++ root/.config/nvim/lua/plugins_setup.lua | 2 +- .../start/codenote/autoload/codenote.vim | 5 +- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/root/.config/nvim/lua/plugins/init.lua b/root/.config/nvim/lua/plugins/init.lua index f88f4d1..e109bb0 100644 --- a/root/.config/nvim/lua/plugins/init.lua +++ b/root/.config/nvim/lua/plugins/init.lua @@ -18,6 +18,54 @@ return { "RRethy/nvim-treesitter-endwise", }, }, + { + "nvim-treesitter/nvim-treesitter-textobjects", + config = function() + require'nvim-treesitter.configs'.setup { + textobjects = { + select = { + enable = true, + + -- Automatically jump forward to textobj, similar to targets.vim + lookahead = true, + keymaps = { + ib = "@block.inner", + ab = "@block.outer", + ic = "@class.inner", + ac = "@class.outer", + ["if"] = "@function.inner", + af = "@function.outer", + }, + }, + move = { + enable = true, + set_jumps = true, -- whether to set jumps in the jumplist + goto_next_start = { + ["]b"] = "@block.outer", + ["]m"] = "@function.outer", + ["]]"] = { query = "@class.outer", desc = "Next class start" }, + }, + goto_next_end = { + ["]B"] = "@block.outer", + ["]M"] = "@function.outer", + ["]["] = "@class.outer", + }, + goto_previous_start = { + ["[b"] = "@block.outer", + ["[m"] = "@function.outer", + ["[["] = "@class.outer", + }, + goto_previous_end = { + ["[B"] = "@block.outer", + ["[M"] = "@function.outer", + ["[]"] = "@class.outer", + }, + }, + }, + } + end, + dependencies = "nvim-treesitter/nvim-treesitter", + }, { "nvim-telescope/telescope.nvim", lazy = true, diff --git a/root/.config/nvim/lua/plugins_setup.lua b/root/.config/nvim/lua/plugins_setup.lua index 65b5480..181aba1 100644 --- a/root/.config/nvim/lua/plugins_setup.lua +++ b/root/.config/nvim/lua/plugins_setup.lua @@ -3,7 +3,7 @@ function M.nvim_treesitter() require("nvim-treesitter.configs").setup({ -- 安装 language parser -- :TSInstallInfo 命令查看支持的语言 - ensure_installed = { "cpp", "lua", "vim", "vimdoc", "python", "rust", "html" }, + ensure_installed = { "cpp", "lua", "vim", "vimdoc", "python", "rust", "html", "query", "markdown", "markdown_inline" }, -- Install parsers synchronously (only applied to `ensure_installed`) sync_install = false, -- 启用代码高亮模块 diff --git a/root/.vim/pack/my_plugins/start/codenote/autoload/codenote.vim b/root/.vim/pack/my_plugins/start/codenote/autoload/codenote.vim index fb1ebe8..630c57e 100644 --- a/root/.vim/pack/my_plugins/start/codenote/autoload/codenote.vim +++ b/root/.vim/pack/my_plugins/start/codenote/autoload/codenote.vim @@ -34,7 +34,8 @@ function codenote#GetCodeLinkDict() return endif - " 支持/path/to/filename.ext:line_number 和 + " 高亮标记支持 + " /path/to/filename.ext:line_number 和 " +line_number path/to/filename.ext两种格式 " --max-columns=0 防止rg显示 [ ... xxx more matches ] let g:code_links = system("rg -INo --max-columns=0 '(^[\\w\\d\\-./]+:[0-9]+$)|(^\\+[0-9]+ .*$)' " . g:noterepo_dir) @@ -196,7 +197,7 @@ endfunction " 2) +123 /path/to/file " 3) src/execution/operator/aggregate/physical_hash_aggregate.cpp|478 col 7-32| " -" 3) 源自coc.nvim在quickfix list中的显示格式 +" 3) 源自coc.nvim/nvim lsp在quickfix list中的显示格式 let s:codelink_regex = '[A-Za-z0-9\-./]\+\([:|][0-9]\+\)\|\(^\+[0-9]\+\s\)' if g:codenote_filepath_style == 'colon'