Comment multiple lines in vim

To comment multiple lines in vim, first select the line in visual mode.

To change mode to visual mode, type

v

Now use j/k keys to select lines of text you need to comment.

To comment

To comment, use :norm command.

:norm i#

This will insert # to start of every line.

When you type :norm, in visual mode, you will see

:'<,'>norm i#

Uncomment

To uncomment, select the lines in visual mode. Then run

:norm x

this will delete first chars from every selected lines.

Method 2

You can use CTRL + V, this will select first char only.

To comment

1) Get into VISUAL_BLOCK mode by pressing CTRL + V
2) use j/k keys to select lines to comment.
3) Press SHIFT + I, now type #
4) Press ESC

To uncomment

1) Get into VISUAL_BLOCK mode by pressing CTRL + V
2) use j/k keys to select lines to comment.
3) Press x

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *