How to comment out multiple lines at once in vim

My name is Ito and I am an infrastructure engineer.
When editing files on Linux, I often use "Vim".

When working with configuration files,
there may be times when you want to comment out multiple lines at once to comment out unnecessary settings.

This time I would like to introduce you to how to do this

Use rectangular selection mode

For operations on multiple lines, use the "Rectangle Selection Mode."

Open the file in vim and enter the following command:

ctrl + v

Enter "Visual Rectangle Mode"
and with your cursor select the line you want to comment out.

I (shift + i)

This is "insert mode."

Enter the character to comment out (such as "#")

Esc

Exit insert mode

I've put it all together in GIF
uGl98JLL61

Looks like
a comment has been inserted at the beginning!

Let's try our best to become proficient in Vim

If you found this article useful, please click [Like]!
0
Loading...
0 votes, average: 0.00 / 10
3,825
X Facebook Hatena Bookmark pocket

The person who wrote this article

About the author