Skip to main content

Macro in VIM

·193 words·1 min
Posts vim macro cli
Table of Contents
Macro is like a magic.

All the while, I’m a fan of Vim editor. In fact, this whole blog is edited with Vim editor (manually).

Macros in VIM
#

Today I learn my first macro in Vim editor.

Here are the steps to create a macro, to repeat on editing the line, and apply it.

Creating Macro
#

To record a macro (from command mode):

  1. Press q to start a macro.

  2. Press h to register for macro.

  3. Goto insert mode and edit a line as usual.

    • (Goto position of the first line)
    • press i to switch to insert mode
    • press " for open quote
    • press ESC to switch back to command mode
    • press a to append to the end of line position and switch to insert mode
    • press " and , for closing quote with comma
    • press ESC to switch back to command mode
    • pressENTER to goto next line (at first position)
  4. Press q to stop the macro.

Apply The Macro
#

To simply apply the recorded macro to a line, press @h.

To apply the macro to multiple lines, press 5@h.

Demo (YT Shorts)
#

Thank you typecraft for the excellent tip!

Related

Multicloud Cmdline Cheat Sheet
·126 words·1 min
Posts YT cli cloud sans
Multicloud Command Line Cheat Sheet Resource Demo.
Simple Git Aliases
·171 words·1 min
Posts dotFiles cli git
With aliases, you can start avoid typing the same commands over and over again.
Colors with ANSI Escape Code
·364 words·2 mins
Posts ansi cli color console shell
Notes about ANSI escape code for colors.