Tag: VI

Using VI to insert spaces at the begining of every line

In the Vi text editor, you can insert two spaces at the beginning of each line using a command called “substitution.” Here’s how you can do it:

when in vi with your text displayed :

Press the Esc key to ensure you’re in command mode.

Enter the following command to perform the substitution:

:%s/^/  /

Press the Enter key to execute the substitution command.

Explanation of the command:

%s indicates that the substitution should be done throughout the entire file.
^ represents the beginning of each line.
/ is the space you want to insert at the beginning of each line. Make sure to type two spaces.


Now, each line in the file should start with two spaces. You can verify this by scrolling through the file or using other search and navigation commands in Vi.