Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I know if I in the middle of key series in vim?

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!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

(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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading