tComment对比 NERD评论者

ma1*_*w28 14 vim macvim

我正在从TextMate切换到MacVim.我应该使用哪个以及为什么?tCommentNERD评论者

小智 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)


Rob*_*kop 1

两者都尝试一下,看看哪一个最适合您

  • -1 因为有时需要一段时间才能意识到有一些小原因某些东西不适合你,然后你就掌握了它的命令并且必须重新学习。经验之声可能很有价值。 (55认同)