在Vim中,当我使用NERDCommenter注释多行可视选择时,选择中的空行不会被注释。在下面的示例中,我选择了所有5行并键入"\cl“(表示NERDCommenterAlignLeft),但是第三行没有注释,它是空白的。
之前:
" 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>发布于 2012-06-15 22:11:36
这就是它在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因此,在插件继续注释一行之前,它会检查该行是否为空行。如果是这样,插件不会对其进行注释,并跳到下一行。
快速修复方法是简单地从您的插件文件中删除这部分代码。
https://stackoverflow.com/questions/11036685
复制相似问题