我如何使用modify NERDCommenter的行为对选中的*所有*行进行注释 在VIM中,当我用NeDeCnCutter注释多行视觉选择时,选择中的空行不予评论。在下面的示例中,我选择了所有5行,并为NerdCommonInteralignLeft键入\cl,但第3行为空,没有注释

我如何使用modify NERDCommenter的行为对选中的*所有*行进行注释 在VIM中,当我用NeDeCnCutter注释多行视觉选择时,选择中的空行不予评论。在下面的示例中,我选择了所有5行,并为NerdCommonInteralignLeft键入\cl,但第3行为空,没有注释,vim,Vim,之前: " Normalize Markdown : Remove Trailing # From Headers nnoremap <Leader>qq :%s/ \+#\+ *$//gc<CR> " Normalize Markdown : Remove Trailing Whitespace nnoremap <Leader>qw :%s/\s\+$//gc<CR> 之后: " " Normalize Markdown : Remove

之前:

" Normalize Markdown : Remove Trailing # From Headers
nnoremap <Leader>qq :%s/ \+#\+ *$//gc<CR>

" Normalize Markdown : Remove Trailing Whitespace
nnoremap <Leader>qw :%s/\s\+$//gc<CR>
之后:

" " Normalize Markdown : Remove Trailing # From Headers
" nnoremap <Leader>qq :%s/ \+#\+ *$//gc<CR>

" " Normalize Markdown : Remove Trailing Whitespace
" nnoremap <Leader>qw :%s/\s\+$//gc<CR>

这就是它在NERDCommenter插件中的实现方式。如果打开插件文件NERD_commenter.vim并查找名为s:CanCommentLine的函数,您将看到它有以下检查:

" make sure we don't comment lines that are just spaces or tabs or empty.
if theLine =~ "^[ \t]*$"
    return 0
endif
因此,在插件继续注释一行之前,它会检查它是否为空行。如果是这样,插件不会对其进行注释并跳到下一行


快速修复方法是从插件文件中删除这部分代码。

这似乎是对的,但对我来说不起作用。如果我知道原因,我会告诉你的。不管怎样,我还是投了赞成票。我在切换评论,而不是直接评论。在这种情况下,要修改的函数是s:CanToggleCommentLine。