Banner of None

Advanced vim macros: Vim recursive macros


Category: vim

Date: July 2020
Views: 1.28K


Text editors are an important part of any operating system, learning how to use them and mastering them is must have skill for anyone who wants to use a computer, especially if you want to do some programming and code writing.

Vim comes at the top of all other text editors, even though it takes some time to learn how to use it, but its worth it, for when you do , editing texts becomes an art and a real fun activity . for programmers; what would take hours to write in other text editors can take minutes with vim and in this area where vim really excels . one of the features of vim is macros . vim macros can make editing semi automatic, you simply make some editing changes/commands to change a part of your text, and instruct vim to record them. after that you can use the same changes/commands to the rest of your text for as long as you want

So how to record a vim macro ?

In vim Normal mode we type "q" and then another letter, this letter represents the register in which our macro will be recorded, lets say we chose "a", now a message will show in the bottom of the window that says: "recording @a" which means that from now on every action we make, every insertion or deletion will be recorded in register "a" untill we hit "q" once again to finish recording our macro
from now on everytime we hit "@a" , the instructions recorded in our macro will be executed.
to make our macro a recursive macro, ie a macro that executes itself . we paste the content of register "a" by hitting : "ap (doublequote included) and then we append : "@a" at the end of the line, and then we copy the text once again to the register "a" , by hitting : "ayy (doublequote included).
the video bellow explains all this in details:



1.28K views

Next Article

0 Comments, latest

No comments.