fir3net
PPS-Firenetbanner-780.5x190-30-03-17

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

Introduction

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.

Steps

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.

By what is :'<,'> norm I  actually doing?

:'<,'> : 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

References

https://vi.stackexchange.com/questions/4489/how-to-add-space-on-multiple-lines-when-pressing-spacebar-without-extra-configu 

Tags: Linux

About the Author

RDonato

R Donato

Rick Donato is the Founder and Chief Editor of Fir3net.com. He currently works as a Principal Network Security Engineer and has a keen interest in automation and the cloud.

You can find Rick on Twitter @f3lix001