I'm switching from TextMate to MacVim. Which should I use and why? tComment or The NERD Commenter
Asked
Active
Viewed 9,726 times
16
-
2I personally prefer EnhancedCommentify, http://www.vim.org/scripts/script.php?script_id=23 – Peter Rincker Jan 17 '11 at 20:44
-
I've been using it for something like 10years or more, and ... well. It does its work, and it does it fine. In the end, I've never tried the two challengers. – Luc Hermitte Jan 17 '11 at 22:30
-
Just as Luc, I have used it for many years and am very happy with the results. I suggest you try all 3 out and tell us which you like best. – Peter Rincker Jan 18 '11 at 02:40
-
you should use nerdcommenter. it's the standard. don't waste your time with other plugins. you're commenting out code, you don't need any bells and whistles that no one else knows how to use. – Andy Ray Nov 24 '12 at 00:55
-
1There's also a [commentary.vim](https://github.com/tpope/vim-commentary). – Santosh Kumar Aug 29 '13 at 16:35
-
Which did you end up using @ma11hew28? – Alexej Magura May 08 '19 at 17:40
-
@AlexejMagura, sorry, but I don't remember if I tried any of them. Currently, I just use Vim from Terminal on macOS, not MacVim. And, if I'm in Normal mode and want to comment out the line my cursor is on (the first line) and the 3 lines below it, for example, I type 0, Ctrl-V, 3, J, and Shift-I. That puts me into Insert mode at the start of the first line. There, I insert the comment character and a space, and then, I press Esc to go back to Normal mode, and Vim inserts the same characters at the start of each of the 3 lines below. I know that's a lot to type, but that's how I do it for now. – ma11hew28 May 08 '19 at 23:00
-
@ma11hew28 The plugins in question can be used in both MacVim and regular Vim (running on a terminal emulator). Did you think you couldn't use plugins outside of the GUI? – Alexej Magura May 10 '19 at 20:50
-
1@AlexejMagura no, I didn't think that. I guess I just also wanted to give an update: that I now use Vim from Terminal, instead of MacVim. Sorry for the confusion, and thank you for clarifying. :-) – ma11hew28 May 14 '19 at 05:17
3 Answers
10
I like style of tComment more than NERDCommenter, at least in Perl code.
Original:
my $foo;
if ($foo) {
$foo = 1;
$bar = 1;
}
return $bar;
tComment:
my $foo;
# if ($foo) {
# $foo = 1;
# $bar = 1;
# }
return $bar;
NERDCommenter:
my $foo;
#if ($foo) {
#$foo = 1;
#$bar = 1;
#}
return $bar;
I also like default mappings of tComment that feel more native for Vim. The basic are:
gc{motion} :: Toggle comments
gcc :: Toggle comment for the current line
gC{motion} :: Comment region
gCc :: Comment the current line
I have added a few more mappings in vimrc and now I'm fully happy:
" 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
And one more mapping for consistency: gcc toggle comment line but gc toggle comment visual, so let's make it more consistent:
vmap gcc gc
-
What you say about the commenting in NERD is not completely true. Yes `\cc` will comment as you say. But if you `\cl` you'll comment the whole block in a "line", just as your tComment example shows. Also `\cs` will block comment. Also yanking the text before commenting [`\cy`] comes straight out of the box with NERD. No need to modify your `.vimrc` – cartbeforehorse Jun 21 '15 at 22:12
-
tComment is more powerful in being able to comment parts of a line. For example: `gct;` will comment everything from the position of the cursor to just before the first instance of semi-colon, on the current line. You can't do this in NERD. However, NERD seems more powerful in line manipulation. No need for visual mode with NERD. `4\cy']p` comments current line and 3 following lines, then pastes them immediately after. – cartbeforehorse Jun 21 '15 at 22:51
3
I like tcomment a lot more (I tried both). Check out http://vimsomnia.blogspot.com/2010/11/tcomment-vim-plugin.html

Rafael Vega
- 4,575
- 4
- 32
- 50
1
try both and see what suits you best

Robokop
- 906
- 1
- 5
- 12
-
1
-
55-1 because sometimes it takes a while to realize there's some small reason something doesn't suit you, and then you've got its commands under your fingers and have to relearn. Voices of experience can be valuable. – Cascabel Jan 18 '11 at 05:46