I wanted to change the behavior of some keys in the :h i_CTRL-X submode. For example, I wanted to use the following:

inoremap <expr> <C-f> pumvisible() ? "\<C-x>\<C-f>" : "<C-f>"

The keybinding above is supposed to let me use only <C-f> after I've enabled the popupmenu with <C-x><C-f>. For example, say, I have the following directory and file in my popup-menu:


By default, I have to enable filename-completion with <C-x><C-f> and move to bin/ directory with <C-n> and if I want to move into the directory, I need to get out of that submode, which I used to do with <C-x> so that with one key I just got out of that previous submode and started getting into that submode again.

One more keypress is not a big deal, but I thought I should be able to make it one keypress. I wanted to use <C-f> to get out of that submode and also get into it again. It's fairly simple, until I learnt that it doesn't work with normal inoremap cause it's a separate submode and <C-f> works as <C-n> in that submode as the suggestion in the echo area suggests:

-- File name completion (^F^N^P) match 1 of 2

So, I don't know what to do now. I have also tried imap directly by the way, so that's not it. Any idea how to get a workaround?


Some doc after :h complete_CTRL-Y:

Note: The keys that are valid in CTRL-X mode are not mapped.  This allows for
":map ^F ^X^F" to work (where ^F is CTRL-F and ^X is CTRL-X).  The key that
ends CTRL-X mode (any key that is not a valid CTRL-X mode command) is mapped.
Also, when doing completion with 'complete' mappings apply as usual.

You can not map <c-f> in CTRL-X submode because <c-f> is valid in CTRL-X submode, but you can map f, because f ends CTRL-X mode

inoremap <expr> f pumvisible() ? "\<c-y>\<c-x>\<c-f>" : "f"
  • I need to map <C-f>. That's the whole point. Otherwise, if I used f, I wouldn't even need "\<C-y>" part you added. This answer doesn't provide a solution to the question, only attest that the problem is reproducible and also mentioned in the docs (which I read btw, that's why I knew I needed a workaround) – klaus Apr 23 at 7:01
  • You can't map <c-f>, that's a sure thing. what kind of workaround would you like to find? – dedowsdi Apr 23 at 7:30
  • I need to map <C-f>. That is the workaround I need. The reason for <C-f> not working is that I'm in a submode, right? Then there must be a way to map key to that mode. Or maybe, I can change the keys that are valid in CTRL-X mode so that <C-f> can be mapped. I want this to happen for all the ins-completion keys in CTRL-X submode. That's why I can't just use another key like <C-g> for <C-f>. – klaus Apr 23 at 7:37

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.