In VIM, at the moment when I need to comment out a section of Ruby code:
r<space>
if I want to uncomment the code or r#
if I want to comment it out. This workflow seems ok to me, are there any ways of improving this process? Are there any other tricks for commenting or uncommenting ruby code sections in vim?
Using the up and down arrow key, highlight the lines you wish to comment out. Once you have the lines selected, press the SHIFT + I keys to enter insert mode. Enter your command symbol, for example, # sign, and press the ESC key. Vim will comment out all the highlighted lines.
Single line comments in a Ruby script are defined with the '#' character. For example, to add a single line comment to a simple script: # This is a comment line - it explains that the next line of code displays a welcome message print "Welcome to Ruby!"
To comment out blocks in vim:use the ↑ / ↓ arrow keys to select lines you want (it won't highlight everything - it's OK!) Shift + i (capital I) insert the text you want, e.g. % press Esc Esc.
How to Comment a Single Line in Vim. To comment out a single line in Vim, enter Visual Mode by pressing Ctrl + V . Next, navigate to the line you wish to comment out and press the C key. Depending on your Vim configuration, this should comment out the selected line.
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With