Using a macro to add double quotations over multiple lines in vim
-
Select the Lines of Interest:
- Move the cursor to the start of the first line where you want to perform the operation.
- Enter Visual Line mode by pressing
Shift+V
. - Use the up or down arrow keys to extend the selection to cover all lines of interest.
-
Start Recording the Macro:
- Press
q
followed by a letter (likea
) to start recording the macro into registera
.
- Press
-
Append the Character to the Word:
- Move to the end of the Word by pressing
E
. This takes the cursor to the end of the current Word. - Enter insert mode at the current cursor position by pressing
a
. - Type the character you want to append.
- Press
Esc
to return to normal mode. - To ensure the cursor is positioned correctly for multiple runs, press
B
to go back to the beginning of the Word.
- Move to the end of the Word by pressing
-
Move to the Next Line and Stop Recording:
- Move to the next line with
j
. - Press
q
again to stop recording the macro.
- Move to the next line with
-
Apply the Macro to the Selected Lines:
- With the lines still selected in Visual Line mode, apply the macro by typing
:
which will bring up:'<,'>
. Then typenorm @a
to apply the macro to each line in the selection. The full command will be:'<,'>norm @a
. - To apply the macro to a range of lines, use
:[range]norm @a
, where[range]
is the line range (e.g.,5,10
for lines 5 to 10). - To apply the macro to every line in the file, you can use
:%norm @a
.
- With the lines still selected in Visual Line mode, apply the macro by typing
-
Save Your Changes:
- Once you have finished, save your changes with
:w
.
- Once you have finished, save your changes with