Suppose I have the piece of text below with the cursor staying at the first A
currently,
AAAA
BBB
CC
D
How can I add spaces in
Another thing you could try is a macro. If you do not know already, you start a macro with q
and select the register to save the macro... so to save your macro in register a
you would type qa
in normal mode.
At the bottom there should be something that says recording. Now just do your movement as you would like.
So in this case you wanted 2 spaces in front of every line, so with your cursor already at the beginning of the first line, go into insert mode, and hit space twice. Now hit escape to go to normal mode, then down to the next line, then to the beginning of that line, and press q
. This ends and saves the macro
(so that it is all in one place, this is the full list of key combinations you would do, where <esc>
is when you press the escape key, and <space>
is where you hit the space bar: qai<space><space><esc>j0q
This saves the macro in register a
)
Now to play the macro back you do @
followed by the register you saved it in... so in this example @a
. Now the second line will also have 2 spaces in front of them.
Macros can also run multiple times, so if I did 3@a
the macro would run 3 times, and you would be done with this.
I like using macros for this like this because it is more intuitive to me, because I can do exactly what I want it to do, and just replay it multiple times.