Reputation: 11916
Given:
https://stackoverflow.com/questions/ask
From normal mode at the first character, typing in qaqqaf/xb@aq@a
clears all of the forward slashes.
But running normal qaqqaf/xb@aq@a
stops after b -- it seems to bail at the recursive call. The same happens if you try to use map the command.
Is there something wrong with my syntax? Or is it impossible to record a recursive macro with normal
?
Note: I know it's possible to write a recursive macro with let
. I'm wondering if this is the only way to write a recursive macro without recording it manually:
let @a = "f/xb@a"
normal @a
(I ask because of this answer: Remove everything except regex match in Vim )
Upvotes: 2
Views: 620
Reputation: 45107
If you want to create a map to a recursive macro I suggest you start by doing something like so:
nmap <f2> :let @a = "f/xb@a"|normal @a
Of course this clobbers the @a register and if you find you self doing many of these kinds of mappings maybe a function would better suit your needs.
Here is a safer alternative to making recursive macro mappings:
function! RecMacroExe(cmds)
let a = @a
let @a = a:cmds . "@a"
try
normal @a
finally
let @a = a
endtry
endfunction
nmap <f2> :call RecMacroExe("f/xb")<cr>
Edit: Changed function according to @Luc Hermitte comment
Upvotes: 3