1 前言
本来SpaceVim用的好好的,在无意中一次更新Nvim和插件后,一切都改变了:各种乱七八糟的插件报错,怎么也解决不了,看来别人配好的东西还是有点局限性,真要稳定使用还得自己DIY,于是毅然删除了SpaceVim,从头开始配置我的Neovim(结合之前自己的vim配置)。这里记录一下几个常用插件的常用功能,作为备忘录使用,刚开始用的不熟时可以方便自己迅速找到参考处。
nvim查看某快捷键详细信息: :verbose map xxx<cr>
(各插件不分先后顺序)
2 nvim-tree
侧边栏,呼出的命令分NvimTreeToggle
与NvimTreeFindFile
两个,用which-key
插件统一管理快捷键,开关的快捷键我设为了<Space>ft
或<leader>n
,定位到文件的快捷键我设为了<Space>fo或<space>n
。前面的快捷键与原SpaceVim保持一致,后面的是我根据习惯设置的。其他快捷键配置见nvim-tree
配置文件:
local keymap_list = {
{ key = { "<CR>", "o", "l", "<2-LeftMouse>" }, action = "edit" },
{ key = "h", action = "close_node" },
{ key = "p", action = "preview" },
{ key = "<C-r>", action = "refresh" },
{ key = "yn", action = "copy_name" },
{ key = "yp", action = "copy_path" },
{ key = "yy", action = "copy_absolute_path" },
{ key = "a", action = "create" },
{ key = "d", action = "remove" },
{ key = "r", action = "rename" },
{ key = "I", action = "toggle_git_ignored" },
{ key = "R", action = "collapse_all" },
{ key = "?", action = "toggle_help" },
}
3 buffer-line
自己设置的快捷键如下:(依赖close-buffers插件)
快捷键 | 功能 |
---|---|
<leader>j | next buffer |
<leader>k | previous buffer |
<leader>[number] | to buffer [number] |
<space>bc | close invisible buffers |
<space>bd | close current buffer |
<space>bt | close other buffers |
4 nvim-treesitter
- 增量选择,可视模式下
<CR>
与<BS>
进行选择;
incremental_selection = { -- 启用增量选择
enable = true,
keymaps = {
init_selection = '<CR>',
node_incremental = '<CR>',
node_decremental = '<BS>',
scope_incremental = '<TAB>',
}
},
- 智能选择,
v.
、v;
、vi;
分别对应smart、outer、inner三种模式;
textsubjects = { -- 智能选择
enable = true,
prev_selection = ',', -- (Optional) keymap to select the previous selection
keymaps = {
['.'] = 'textsubjects-smart',
[';'] = 'textsubjects-container-outer',
['i;'] = 'textsubjects-container-inner',
},
},
- 文本对象的选择、跳转、交换等,新文本对象f(function)、c(class);移动快捷键h为start、l为end、j为next、k为previous、小写为function、大写为class;
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
["ic"] = { query = "@class.inner", desc = "Select inner part of a class region" },
},
-- You can choose the select mode (default is charwise 'v')
selection_modes = {
['@parameter.outer'] = 'v', -- charwise
['@function.outer'] = 'V', -- linewise
['@class.outer'] = '<c-v>', -- blockwise
},
-- If you set this to `true` (default is `false`) then any textobject is
-- extended to include preceding xor succeeding whitespace. Succeeding
-- whitespace has priority in order to act similarly to eg the built-in
-- `ap`.
include_surrounding_whitespace = true,
},
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
["xl"] = "@function.outer",
["xL"] = "@class.outer",
},
goto_previous_start = {
["xh"] = "@function.outer",
["xH"] = "@class.outer",
},
goto_next_end = {
["xj"] = "@function.outer",
["xJ"] = "@class.outer",
},
goto_previous_end = {
["xk"] = "@function.outer",
["xK"] = "@class.outer",
},
},
},
5 telescope
模糊搜索神器,有很多扩展,我装了fzf
(模糊匹配)、bookmarks
(书签,基于vim-bookmarks?)、heading
、emoji
、neoclip
,此外还有个`telescope-coc,下面是我设置的快捷键位:
快捷键 | 功能 |
---|---|
<leader>f | find files(当前buffer所在文件层级开始) |
<leader>F | 搜寻当前git项目中的文件(应用gitignore) |
<leader>b | search buffers |
<leader>o | search symbols in current file |
<leader>s | search symbols in project |
<leader>g | live grep, 内容搜索 |
<leader>G | live grep cursor word, 内容搜索所选单词 |
<leader>m/ |
search bookmarks |
<leader>d | search coc diagnostic |
<leader>h | jump between headings(md、beancount…) |
模糊匹配平时感觉用的挺多,这里先说下书签相关快捷键:
快捷键 | 功能 |
---|---|
mm | 当前行做标记 |
mi | 当前行做标记,并写上相应的注释 |
mn | 跳到下一个标记 |
mp | 跳到上一个标记 |
ma | show all bookmarks |
mc | 删除当前buffer的标记 |
mx | 删除所有buffer的标记 |
6 nvim-surround
Add/delete/change surrounding pairs
快捷键 | 示例 | 功能 |
---|---|---|
ys | ysiw( | 在当前文本对象周围增加surround |
ds | ds[ | 删除一个[] |
cs | cs’” | 将一对’改为一对” |
7 vista
显示symbols和tags导航栏,快捷键cn
8 vim-floaterm
快捷键 | 功能 |
---|---|
<C-t> | 显示/关闭悬浮窗 |
<C-n> | 新建悬浮窗 |
<C-p> | 上一个悬浮窗 |
9 vim-commentary
:Commentary
注释代码,设定快捷键为<space>lc
,默认快捷键如下:
快捷键 | 功能 |
---|---|
gcc | comment out a line |
gcaw | comment out a textobject |
gc | comment out selected(visual mode) |
10 undotree
显示编辑历史记录,:UndotreeToggle
,设定快捷键<space>cu
,打开后按?
可查看更具体的帮助。
11 nvim-spectre
文件名替换,同时对多个文件进行替换。
快捷键 | 功能 |
---|---|
<space>sp | 在当前项目中搜索 |
<space>sP | 搜索当前光标 |
12 code_runner
只用该插件的:RunCode
命令,忽略其他功能,快捷键我设为<Space>rc
13 vim-table-mode
<space>tm
进入/退出表格编辑模式
14 coc-nvim
快捷键 | 功能 |
---|---|
gd | 跳转到定义处 |
gr | 跳转到references-used |
K | 可以查询函数,变量,宏等,注释将会显示在悬浮窗口上 |
gy | 跳转到type-definition处 |
gi | 跳转到implementation |
[g, ]g | 跳转到coc各个诊断处 |
<leader>ln | 重命名变量(别用算了,直接用nvim-spectre重命名) |
<leader>d | 打开诊断窗口(前面讲过了) |