neovim一些插件的快捷键备忘录

1 前言

本来SpaceVim用的好好的,在无意中一次更新Nvim和插件后,一切都改变了:各种乱七八糟的插件报错,怎么也解决不了,看来别人配好的东西还是有点局限性,真要稳定使用还得自己DIY,于是毅然删除了SpaceVim,从头开始配置我的Neovim(结合之前自己的vim配置)。这里记录一下几个常用插件的常用功能,作为备忘录使用,刚开始用的不熟时可以方便自己迅速找到参考处。

nvim查看某快捷键详细信息: :verbose map xxx<cr>

(各插件不分先后顺序)

2 nvim-tree

侧边栏,呼出的命令分NvimTreeToggleNvimTreeFindFile两个,用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

  1. 增量选择,可视模式下<CR><BS>进行选择;
  incremental_selection = { -- 启用增量选择
    enable = true,
    keymaps = {
      init_selection = '<CR>',
      node_incremental = '<CR>',
      node_decremental = '<BS>',
      scope_incremental = '<TAB>',
    }
  },
  1. 智能选择,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',
    },
  },
  1. 文本对象的选择、跳转、交换等,新文本对象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?)、headingemojineoclip,此外还有个`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/ma 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 打开诊断窗口(前面讲过了)
Author: zcp
Reprint policy: All articles in this blog are used except for special statements CC BY 4.0 reprint polocy. If reproduced, please indicate source zcp !
评论
 Previous
latex-cheatsheet
1 前言最近需要和一堆公式打交道,用mathpix的公式识别还是太贵了(API也连涨几次价),还是自己记住这些语法手打公式比较快。下文全部从别的地方收集而来,仅供自己备用。 2 cheatsheet(分类)2.1&ems
Next 
2022年总结——躺平的一年
1 小目标回顾 通过5月28日的软考(高级系统架构设计师) 因疫情取消了,下半年懒没有考。话说上半年只有系分下半年才有架构考,这个当初都没调研清楚= = 7月的JLPT N1拿到满分(扣5分之内能够接受)
  TOC