Skip to content

Instantly share code, notes, and snippets.

@shreewatsa
Last active February 22, 2023 08:06
Show Gist options
  • Save shreewatsa/9a9298007babf07ba4f663a93ca6520d to your computer and use it in GitHub Desktop.
Save shreewatsa/9a9298007babf07ba4f663a93ca6520d to your computer and use it in GitHub Desktop.
Vim Cheatsheet

Macro :

q[a-z]  : record macro, do something, then press q again to stop recording. ie qa starts recording in register "a".  
@[a-z]  : to repeat the macro previously created.  
q[A-Z]  : Append at the end of the macro. eg qA will start appending to what was recorded in qa previously.  
:register or :reg       : Macro are stored in Vim’s registers.  
“ayy    : Yank current line to register a.  
“Ay$    : Append content from current cursor position to line end into register "a".  
“ap     : Paste contents of register a in normal mode.  
“+p     :  Paste contents of system clipboard. TODO: research “*p register.  

prefix your macro with 0 or ^ , so that it starts the same way in all the lines.
suffix your macro with +, n, * , to setup macro to run in other lines.
+ : moves the cursor to the beginning of the next line.
n : goto next search item.
* : forward search the word under the cursor.

Note: you can improve the macro by editing the macro contents and again copying to the register.

Marks and Jumps:

m[a-zA-Z]   : setup mark positions in normal mode.  
‘[a-zA-Z]   : Jump to the mark position. (' is a single tick)  

Extras (TODO):

:set nowrapscan        : don’t go past the EOF.  
:set lazyredraw 		   : if you don’t want to see macro running, and just want to see the end result.  
:cdo normal wfxll      : To run the contents in normal mode.   
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment