Skip to content

Instantly share code, notes, and snippets.

@roymanigley
Last active April 24, 2022 14:12
Show Gist options
  • Save roymanigley/91df8449975bef3ad14dc93b8a65e073 to your computer and use it in GitHub Desktop.
Save roymanigley/91df8449975bef3ad14dc93b8a65e073 to your computer and use it in GitHub Desktop.
How to record a macro on VIM and reuse it in a function

VIM recording

  1. start the recording
    qq
  2. do your stuff ...
  3. stop the recording
    q
  4. open the vimrc file :e /path/to/vim/c
    :reg q → prints the registers content
  5. paste the macro in a function by moving the cursor to the right position, change to NORMAL mode, enter "qp to paste the content from the register q
    function A()
      normal /\d <=== the macro
    endfunction
    
  6. run the macro when opening a file
    vim -u /path/to/vimrc +":call A()" /mapth/to/file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment