Vim: & ldquo; f & rdquo; breaks my mapping when he can not find a character

advertisements

I have a (fairly crude) mapping I want to use for Jade files.

nmap <leader>jc ^f)Wc$

should turn these examples

a.classname(href='url', title='title') Click here
p This is a paragraph

into

a.classname(href='url', title='title') _
p _

where _ is the cursor in insert mode.

However, when f can't find ) it ceases to run the remaining actions in the sequence. Is there a way I can force it to continue with the sequence of commands regardless?


romainl has already tried to convince you that your approach has some flaws.

Anyway, if you want your macro to continue after a command failure, you have to split the sequence of normal mode commands into Ex commands (with :normal), as these do not abort:

nmap <leader>jc :execute 'normal ^f)'<CR>Wc$