In VIM, at the moment when I need to comment out a section of Ruby code:
I do almost the same thing as you.
commenting:
CTRL-V
then I#
(insert #
in the begining)uncommenting:
CTRL-V
then X
(delete the first symbol on the line)Please note uppercase I
and X
.
Try T-comment with Ruby block.
I have T-comment mapped to //.
" Easy commenting
nnoremap // :TComment<CR>
vnoremap // :TComment<CR>
This allows, from anywhere in a Ruby block, to comment it out with:
var (visual around Ruby)
// (toggle comments)
Note that Ruby blocks has a couple of plugin dependencies that need installing, see my Vimfiles for an example.
Some people seem to like Nerd Commenter
I will recommend you an alternative way to comment using by Macro
The first, just put this in to your .vimrc
let @c="I#\ej"
let @u="^xj"
For the example
To comment 12 lines:
12@c
on command mode to comment 12 linesTo uncomment 12 lines:
12@u
on command mode to uncomment 12 linesThe conclusion
Commenting:
[quantifier]@c
Uncommenting:
[quantifier]@u
note: These commands will start commenting/uncommenting from your current line.
Additional:
To improve you nevigation number.vim
can help you a lot about quantifier number.
https://github.com/myusuf3/numbers.vim
You can also do this:
Ctrl + q
to enter Visual Block modeI
, comment out by pressing #
ESC
And to uncomment:
#
of commentCtrl + q
to enter Visual Block moded
to remove the comment charactersHave you tried out EnhCommentify.vim or tComment.vim?