Technology and General Blog

Vim is an fantastic command-line textual content editor, in particular if you are cozy with its shortcuts, modes, and bindings. Nonetheless, when functioning with it, we can face situations in which we need to comment on code blocks while editing code and configuration data files.

This posting describes rapid and simple strategies to remark and uncomment out a number of lines of code in Vim editor. Finding out how to do this will eliminate the need to go down every single line and remark out just about every line.

How to Comment Several Strains – Vim

For this tutorial, we will use a very simple python script termed

Approach #1 – Line Quantities

The simplest system to comment out various strains is to use line quantities. First, open your file in Vim and press ESC to enter command manner.


:[start line],[end line]s/^/#

To reveal, permit us remark out from lines 10 to 15./

If you do not want to use line quantities in the command, use the spotlight strategy.

To do this, transfer to the line you want to begin commenting out and push Change + V. Executing this will emphasize the total line. Then, use the up and down arrow keys to highlight the other strains.

When you have the traces to comment out highlighted, press enter the Highlighted code ought to seem a thing like this:

Press ESC to enter command method and use the command as:

The moment completed, you must have all the lines you highlighted commented as:

Approach # 2 – Visual Manner

The other technique you can use to comment out a number of lines is to use Visual Mode.

To do this, press ESC and navigate to the traces you want to remark out.

Press CTRL + V to help Visible Mode.

Making use of the up and down arrow crucial, spotlight the strains you desire to remark out.

As soon as you have the strains picked, push the Change + I keys to enter insert mode.

Enter your command image, for case in point, # indication, and push the ESC important. Vim will comment out all the highlighted lines.

# 3 – Frequent Expression

A person of our favorite strategies of commenting traces of code in Vim is normal expressions. For case in point, employing regex is a potent approach that comments outlines that have a distinct term.

For illustration, to comment strains that consist of the phrase def, use the command:

Push enter to comment out the traces:

How to Uncomment Numerous Traces – Vim

The reverse is true at the time you remark on outlines, you need to uncomment them. To uncomment numerous lines, use the following system.

Enter the following to uncomment traces setting up with a # indication

Yet another process is to use Visible manner.

Navigate to the line you want to comment out and push CTRL + V to enter Visible method.

Use the up and down arrow keys to spotlight the strains you wish to uncomment. At the time selected, push x to remove the reviews.

As soon as you push x, it automatically uncomments the traces.

To Conclude

In short, working with Vim shortcuts really should improve your workflow and enable enhance your performance. Make sure you lookup our website for much more Vim tutorials to make improvements to your Vim expertise.

Thank you for looking at!

Leave a Reply

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