nvim Comment.nvim 注释

参考博客:https://juejin.cn/post/7158607149029916680

同时他也提供了帮助文档,不知道怎么用的可以先看看那个文档,什么?你找不到,好吧nvim打开后:help comment-nvim

说明

当你通过setup的方式来配置Commnet的时候我们可以设置在vim的普通模式和可视化模式设置我么你自定义的快捷键。默认的或者说大多数人配置的是gcc,gbc [countgcc] [count]gbc gc[count][motion] gb[count][motion] , 其实无非就是gc gb加上我们的移位大法罢了。

普通模式 gcc : 行注释当前行 gbc : 使用块级别注释来注释掉当前行 ngcc : 使用行级别注释来注释掉当前行往后的几行数据 ngbc : 使用块级别的注释来注释代码行往后的几行数据

NORMAL mode

gcc - Toggles the current line using linewise comment

gbc - Toggles the current line using blockwise comment

[count]gcc - Toggles the number of line given as a prefix-count using linewise

[count]gbc - Toggles the number of line given as a prefix-count using blockwise

gc[count]{motion} - (Op-pending) Toggles the region using linewise comment

gb[count]{motion} - (Op-pending) Toggles the region using blockwise comment

VISUAL mode

gc - Toggles the region using linewise comment

gb - Toggles the region using blockwise comment

Extra mappings

These mappings are enabled by default. (config: mappings.extra)

NORMAL mode

gco - Insert comment to the next line and enters INSERT mode

gcO - Insert comment to the previous line and enters INSERT mode

gcA - Insert comment to end of the current line and enters INSERT mode

Examples

Linewise

gcw - Toggle from the current cursor position to the next word gc$ - Toggle from the current cursor position to the end of line gc} - Toggle until the next blank line gc5j - Toggle 5 lines after the current cursor position gc8k - Toggle 8 lines before the current cursor position gcip - Toggle inside of paragraph gca} - Toggle around curly brackets

Blockwise

gb2} - Toggle until the 2 next blank line gbaf - Toggle comment around a function (w/ LSP/treesitter support) gbac - Toggle comment around a class (w/ LSP/treesitter support)

文章目录