How to Comment and Uncomment multiple line vi terminal editor

vi is a powerful text editor for Linux if you know most of its command-line hacks. One common thing you might want to do is is commenting or uncommenting multiple lines using the terminal vi editor. In this tutorial, I will explain the steps required for that.

Commenting Multiple Lines in VI

Follow the steps given below for commenting multiple using the terminal.

  1. First, press ESC
  2. Go to the line from which you want to start commenting. Then, press ctrl + v, this will enable the visual block mode.
  3. use the down arrow to select multiple lines that you want to comment.
  4. Now, press SHIFT + I to enable insert mode.
  5. Press # and it will add a comment to the first line. Then press ECS and wait for a second, # will be added to all the lines.

Related: Linux Troubleshooting Commands

Uncommenting Multiple Lines in VI

  1. Press CTRL + V to enable visual block mode.
  2. Move down and select the lines till you want to uncomment.
  3. press x and it will uncomment all the selected lines at once.

Hope this tip helps. Check this article for more VI editor tips

2 Likes

Thanks a lot, very helpful…