Skip to content

Instantly share code, notes, and snippets.

@AndrewRadev
Last active January 24, 2024 17:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AndrewRadev/e03115590daf14d86c53f495b4e63a3d to your computer and use it in GitHub Desktop.
Save AndrewRadev/e03115590daf14d86c53f495b4e63a3d to your computer and use it in GitHub Desktop.
Create a macro with a single keybinding in a default register, apply by dot-repeating
" Place file in autoload/quickmacro.vim
"
" Create mapping in vimrc to start and stop the macro with e.g. M:
"
" nnoremap M :call quickmacro#Record()<cr>
"
" Apply macro by @m, or if you have repeat.vim, just press .
let s:recording = v:false
function! quickmacro#Record() abort
if s:recording
normal! q
let s:recording = v:false
silent! call repeat#set(":call quickmacro#Run()\<cr>")
else
let s:recording = v:true
normal! qm
endif
endfunction
function! quickmacro#Run() abort
normal! @m
silent! call repeat#set(":call quickmacro#Run()\<cr>")
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment