1

I would like to change the escape sequences used by some keys in my terminal. My goal is to define custom mappings in Vim (terminal version).

In the following I use shift-space as an example, but I would prefer if the proposed solution could be generic.

My current terminal (gnome-terminal) uses a simple space as escape sequence for shift-space, as can be seen by typing ctrl-v shift-space. A quick check with the true xterm shows the same behavior. I would like that the shift-space key combo generates another escape sequence (e.g., the one of shift-F30, which I would never use otherwise).

So, how would I go about doing that? And is it really a good idea? Let me know if there are better alternatives...

Note: I'm aware that this is only part of the problem: after the terminal sends a proper escape sequence for my keys, I still need to teach Vim what it means. But I think I know how to deal with that.

1

1 Answer 1

0

I started this answer trying to give you a solution just for the Vim part. After reading this stackoverflow page, it seems that Vim's curses implementation for terminal have no way of differentiating space and shift-space unless curses gain libtermkey support and your terminal support proper <CSI> sequences.

Normally and depending on the situation one would enter something like this in the ~/.vimrc file to get a mapping:

nmap <S-space> :SomeValidVimCommandHere<CR> 

or

inoremap <S-space> <S-F30> 

I did not test this out to see if curses has gotten the required support, so you could try to do the mapping and see if it will work. If this is sane or not I have no idea, but I would like to point out that some mappings will generate undefined behaviour. An example is the escape key. Some years ago I tried undefining the escape key so that it was no longer in use, this was because I wanted to force myself to stop using the escape key and instead use thejk combination to get the same result. That created for me a "random" behaviour which I could not get my head around. From what I understand, this is because the escape key is embedded deeply into Vims way of doing things. This might apply to the mapping you are suggesting to do, but I have no proof that this is the case.

I hope this shed some light on your problem.

4
  • This case does not depend on the library Vim uses. Even if Vim would read the raw input directly, it would still be limited to what the terminal sends, and the terminal sends the same thing for Space and Shift+Space. Commented Oct 27, 2013 at 11:00
  • @grawity: OK, so for shift+space, it is impossible to do this, but for the generic case the poster mentions, this would still be applicable as long as the key combination give a distinct value? Commented Oct 27, 2013 at 11:07
  • Yes, but in that case it is usually possible to bind the raw sequence in Vim as well – e.g. map <Esc>[C :foo Commented Oct 27, 2013 at 11:57
  • Actually, a better way to do the bindings in Vim is to use the :set notation. For example: set <S-Tab>=^[[Z (see :h :set-termcap). But as grawity said, my problem is that I don't know how to force the terminal to send a different sequence for <S-Space>. Commented Oct 30, 2013 at 13:24

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.