6

I usually use gvim and it understands the mapping similar to

inoremap <C-Space> <C-n>
inoremap <C-S-Space> <C-p>

Now I'm testing nvim and I can use the Ctrl+Space.

But Ctrl+Shift+Space is not handled correctly and it triggers the same action as Ctrl+Space does.

Now my question is: is this a behaviour of nvim or is the cause of the problem something else (like my terminal)?

6

You are right, this issue arises on terminal Vim. The easiest would be to stick to Gvim.

Update: For rxvt-unicode, edit your .Xresources file and use the CSI found by Raphael in the article "Fix Keyboard Input on Terminals":

  • URxvt.keysym.S-space: \033[32;2u to map <S-Space>

  • URxvt.keysym.C-S-space: \033[32;6u to map <C-S-Space>


This Vip Tip addresses the S-Space mapping problem:

Vim runs on many different hardware and software platforms. Therefore some key sequences may not be available. For example, you may be able to map Shift-Space in a GUI Vim, but not in a terminal Vim (and even if you could, if you were running via PuTTY, for example, Vim might not receive the key code).

There seems to be a workaround for Urxvt:

For Shift-Space in terminal Vim, I used URxvt.keysym.S-space: \033 in .Xresources. (for the rxvt-unicode terminal emulator).

And a way to test if your Vim recognises the key combination:

To test your system, enter insert mode then press Ctrl-K followed by the key of interest (for example, press Ctrl-K then Shift-Space). :help i_CTRL-K


This SO question may help you, even though the answer reasserts that:

You cannot. CMS's solution will work for gVim, but not in vim because terminals cannot distinguish between and because curses sees them the same. It might be possible in the future if vim gains libtermkey support and your terminal supports the proper sequences (xterm does if properly configured; nothing else does yet).

If your are using iTerm, there might be a solution in the second answer.


See also Mapping Shift-space: how to tell if its possible?

When Vim is run in a terminal (i.e., in console mode), it's at the mercy of the terminal's keyboard logic. Some keys or key combos will not be passed at all. Others will be "translated" according to the current locale. For some keys, Shift and/or Ctrl and/or Alt may get lost, jointly or severally.

| improve this answer | |
  • 1
    Thanks, the Urxvt.keysym was the needed clue. Only the CSI was not helpful. For neovim URxvt.keysym.S-space: \033[32;2u maps <S-Space> and URxvt.keysym.C-S-space: \033[32;6u for <C-S-Space>. The info about the CSI I got from leonerd.org.uk/hacks/fixterms . Maybe you can edit it into the answer. – Raphael Ahrens Aug 28 '17 at 8:27

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.