When I'm on an empty line and press cfa, nothing happens, whereas on a line with an a, it will go into insert mode.

E.g. I have this:

onoremap <silent> a :normal! Favfz

Whether I am on an empty line or a line where the pattern is actually present, I will always go into Insert mode

How can I emulate that behavior in my own mappings?

I don't want a solution for the above, I would be happy with

onoremap <silent> a <don't enter onoremap>
  • Why would you insert those operations in the first place, on an empty line? It's normal that "change to where you find an a" fails (when there is no a), so the change operation is cancelled. On an empty line, you simply hit i (or S) ..
    – VanLaser
    Jun 11 '16 at 18:38
  • I believe I have illustrated my intention. With the above remap <kbd>c</kbd><kbd>a</kbd> will enter insert mode no matter if there is a "asdfz", "abc", or nothing at all. I only want it to enter insert mode, if there is "asdfz".
    – hgiesel
    Jun 11 '16 at 18:43
  • 2
    I see. For your question - there are more powerful ways of defining text-objects/motions/operators, but they involve calling "real" vimscript functions. There are even plugins that build on that: github.com/kana/vim-textobj-user (the idea is that, using functions, you can achieve what you want - you can check for example if you have an a on your line, or your line is empty etc. and enter - or not - insert mode from your function (mapped to your keys).
    – VanLaser
    Jun 11 '16 at 21:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.