小智 10
在Perl代码中,我更喜欢使用tComment的样式而不是NERDCommener.
原版的:
my $foo;
if ($foo) {
$foo = 1;
$bar = 1;
}
return $bar;
Run Code Online (Sandbox Code Playgroud)
tComment:
my $foo;
# if ($foo) {
# $foo = 1;
# $bar = 1;
# }
return $bar;
Run Code Online (Sandbox Code Playgroud)
NERDCommenter:
my $foo;
#if ($foo) {
#$foo = 1;
#$bar = 1;
#}
return $bar;
Run Code Online (Sandbox Code Playgroud)
另外,我喜欢tCommenet的默认映射,感觉Vim更原生.基本是:
gc{motion} :: Toggle comments
gcc :: Toggle comment for the current line
gC{motion} :: Comment region
gCc :: Comment the current line
Run Code Online (Sandbox Code Playgroud)
我在vimrc中添加了一些映射,现在我非常高兴:
" tComment extra mappings:
" yank visual before toggle comment
vmap gy ygvgc
" yank and past visual before toggle comment
vmap gyy ygvgc'>gp'.
" yank line before toggle comment
nmap gy yygcc
" yank and paste line before toggle comment and remember position
" it works both in normal and insert mode
" Use :t-1 instead of yyP to preserve registers
nmap gyy mz:t-1<cr>gCc`zmz
imap gyy <esc>:t-1<cr>gCcgi
Run Code Online (Sandbox Code Playgroud)
还有一个映射表示一致性:gcc切换注释行但是gc切换注释视觉,所以让它更加一致:
vmap gcc gc
Run Code Online (Sandbox Code Playgroud)
两者都尝试一下,看看哪一个最适合您