Perhaps I wasn’t very clear in the title.
What I’m searching for is a way to map the f
key to execute some command, but only if I’m not in the middle of another series of a key strokes like cf<char>
or df<char>
.
Is there a way to know that?
Thanks a lot!
(I’ve searched this site and didn’t find similar question).
>Solution :
In cf<char>
and other operator+motion scenarios, Vim enters a special mode after the operator, "operator-pending mode", in which mappings created for other modes don’t apply.
Therefore, you could map f
in normal mode without impacting its behavior in operator-pending mode:
nnoremap f <Cmd>echo 'foo'<CR>
That said, f
is a useful command in its own right so it might not be a good idea to override it with something unrelated. Also, f
in normal mode and f
in operator-pending mode have the same semantics. By changing the meaning of one f
, you make the other f
less useful.