Welcome to Vifm Q&A, where you can ask questions about using Vifm. Registration is optional, anonymous posts are moderated. E-mail and GitHub logins are enabled.
0 votes
ago in vifm by

I have the below mapping, but when the current file is a symlink, it doesn't work:
nnoremap sl :if filetype('.') == 'link' | exec "norm! cl" | else | alink | endif

even i run the below command in the cmdline, it's also not working:
:exec "norm! cl"

only i use the raw normal command "cl", it works.

could you please help take a look on it, thanks a lot!

1 Answer

0 votes
ago by
 
Best answer

Take a look at the documentation of :normal:

[...] Unfinished last command is aborted as if <esc> or <c-c> was
typed.  A ":" should be completed as well. [...]

:normal can change modes but it always ends in a normal mode, even if it isn't reached by the key sequence.

A somewhat ugly but functional workaround is to use nmap, add a mapping, and execute it at the end:

nmap <silent> sl :if filetype('.') == 'link' | exec 'nnoremap _sl cl' | else | exec 'nnoremap _sl :alink<lt>cr>' | endif<cr>_sl
...