There is no function like mode()
or special v:macro_running
variable, and many would argue that those would just encourage bad practices.
What you can do is use the behavior of feedkeys()
, whose passed keys are usually executed right after the command / mapping, but only at the very end of the macro execution. If you put your long-running commands in there, they will directly slow down normal commands as usual, but only (cummulatively) slow down after the macro execution (and you can usually abort that with <C-C>
).
Example
let @q = ',a,b'
Instead of:
nnoremap ,a aHello<Esc>2gs nnoremap ,b aWorld<Esc>2gs
use
nnoremap ,a aHello<Esc>:call feedkeys('2gs', 'n')<CR> nnoremap ,b aWorld<Esc>:call feedkeys('2gs', 'n')<CR>
This will immediately insert the whole HelloWorld
text inside a macro.