How do I add a Space to Selected Lines within VIM?


Most likey there will be a time (for one reason or another) where you need to insert a number of spaces to a set of lines within a text file.
Within this short article we will show you how via the use of VIM.


1. Within VIM select blockwise visual mode, by pressing CTRL-V.
2. Use the cursor keys to select the lines you want to add the spaces to.
3. Then enter :'<,’> norm I  .
4. This will then insert a single space to the beginning of your select lines.

Lets break down the command :'<,’> norm I 

:'<,’> : For the line I selected
norm : Execute the following sequence of keystrokes as if I was in normal mode
I: Insert at the beginning of the line the following characters
[space]: The character(s) you would like to insert


Rick Donato

Want to become a Linux expert?

Here is our hand-picked selection of the best courses you can find online:
Linux Mastery course
Linux Administration Bootcamp
and our recommended certification practice exams:
AlphaPrep Practice Tests - Free Trial