Adam Allidina
Adam Allidina

Reputation: 23

Vim: Run command for `n` lines

Let's start with an example.

I have a text document that I'm editing. It is of the form:

**** A
**** B
**** C
 ...
**** Z

I want to carry out the operation 3x which (on L0 C0) yields: * A

Is there a quick way to tell VIM: Run this command 3x within line range (m, n)

Upvotes: 2

Views: 551

Answers (2)

unione
unione

Reputation: 371

i would record a macro, then run it twice. lets suppose your doc looks like this

*** A
*** B
*** C
*** D

and you want it like this

ooo A
ooo B
ooo C
*** D

go to the first line gg0 and hit qq to begin recording a macro. then work as usual cwooo<esc> then go down one line j0 and hit q to stop recording. now just run the macro twice with 2@q

Upvotes: 0

Ziyadsk
Ziyadsk

Reputation: 479

Use Visual block to easily choose the lines you want to edit :

Ctrl+v and then I to enter insert mode at the start of the line , and when you finish editing hit ESC and then All the selected lines will be affected .

Upvotes: 1

Related Questions