Skip to content

Instantly share code, notes, and snippets.

@AndrewRadev
Last active January 1, 2016 22:09
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/8207806 to your computer and use it in GitHub Desktop.
Save AndrewRadev/8207806 to your computer and use it in GitHub Desktop.
Attempt to make simpler (and more limited) macros in Vim.
" Press `M` to start recording in a predefined register, press `M` again to
" stop. The dot mapping (`.`) now executes the macro.
let s:simple_macro_active = 0
nnoremap M :call <SID>SimpleMacro()<cr>
function! s:SimpleMacro()
if s:simple_macro_active == 0
call feedkeys('qm', 'n')
let s:simple_macro_active = 1
elseif s:simple_macro_active == 1
normal! q
" remove trailing M
let macro = @m[0:-2]
call repeat#set(macro, 1)
let s:simple_macro_active = 0
endif
endfunction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment