25

I am trying to figure out how to navigate windows little quicker, so I would like to map the following:

:nmap <silent> <C-F> :wincmd f<CR>

The problem is this remaps the ^f (lower-case f) mapping, which is page down. Is there any way to remap only ^F (upper-case F) and leave the ^f as it was?

1
  • 1
    You can if you use xterm or iterm and a recent Vim. See this answer for more info.
    – user938271
    Jul 26, 2020 at 20:29

1 Answer 1

33

Mapping <C-F> (Ctrl+letter) is always the same as mapping <C-f> (Ctrl+Shift+letter). You can't map one without the other.

The root of the problem is that Vim reads characters from the terminal, which sends ^F (ASCII code 0x06) for both Ctrl+f and Ctrl+Shift+f; Vim has no way of knowing whether you pressed the Shift key. This site provides some more information about terminals and control characters.

In theory, this could be done with gVim, since most (or all?) graphic environments send much more detailed key events. But unfortunately, gVim operates much like a terminal emulator, and can't distinguish between <C-f> and <C-F> either (this was perhaps a design decision for Vim-gVim compatibility).


Possible solutions:

  • You could configure your terminal emulator to send a different code to Vim when you press Ctrl+Shift+f. For example, for xterm you could do:

    XTerm*VT100.translations: #override \n\
        Ctrl ~Meta Shift <Key>f: string(0x1b) string("[24;6~")\n\
        Ctrl ~Meta Shift <Key>r: string(0x1b) string("[23;6~")
    

    This will send the code for <C-S-F12> and <C-S-F11> to Vim, which you can pick up with:

    nnoremap <C-S-F12> :echo 'ctrl+F pressed!'<CR>
    nnoremap <C-S-F11> :echo 'ctrl+R pressed!'<CR>
    
  • Note that you can map Alt+Shift+letter, since the terminal sends a different code for those: <Esc>f (0x1b0x66) or <Esc>F (0x1b0x46).

  • NeoVim has, as far as I can find, not fixed this problem except for a few cases such as Ctrl+Shift+Enter and Ctrl+Shift+Tab, but it's possible that this feature will be added in the future.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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