0

How do I disable the Ctrl key? I've tried options below, but they did not work.

noremap <C> <NOP>
noremap <C-> <NOP>
6
  • 1
    This answer might be related: It seems that it is not possible to map ctrl on its own... I'm curious but why do you need to disable this key?
    – statox
    Jul 29, 2015 at 7:43
  • I've quite big hands and after a day of work my pinky hurts. So I want to force myself to use more ergonomical alternatives.
    – OrangeTux
    Jul 29, 2015 at 8:00
  • 1
    I would have understand that with an emacs user but with vim I'm pretty surprised it has never been a problem for me... Anyway maybe you'll be interested in the function of the answer I linked in my previous comment which remaps all the combination of keys between <C-a> and <C-z> to <Space-a> to <Space-z>
    – statox
    Jul 29, 2015 at 8:06
  • 2
    Use your operating system's facilities for this? For example xmodmap on Linux. Jul 29, 2015 at 12:59
  • 4
    Personally, I find that having the control key immediately to the left of 'A' (where caps lock is on most modern keyboards) a lot more convenient than its usual location below the left shift key. I've discussed ways of remapping it on various systems here. Jul 30, 2015 at 18:24

1 Answer 1

2

You cannot disable control without breaking (what most would consider) needed functionality.

The basis for not being able to map from the control key itself (this question) or to the control key (other similar question) is that Vim is, at its core, a terminal application.

Terminal applications are different from GUI applications in that they send and receive a character stream, rather than receiving events and drawing pixels.

The history of terminals and characters and mappings is long (and still developing, for example 8bit meta vs utf-8 encoding). I appologize for the length of this answer in advance.

The short of it is that, assuming an ASCII baseline encoding and ignoring all extended encodings (latin1, utf-8, etc) there are 127 characters that a terminal program can send or receive. 96 of those are printable (alphabet, numbers, symbols, and space), and the other 32 are control characters (things like delete, bell, or end-of-transmission-block). It is up to the terminal or terminal emulator to map key presses to these characters.

None of these characters represent the control key itself, or the alt key itself, etc. Further, none of these represent the key being pressed vs released.

Because of this, it is difficult to make a regular key act like a modifier, difficult to make a modifier act as a regular key, and difficult to make one modifier act like another. Vim's mapping system is based on the characters it receives and notation like is just a nice way of specifying the code for the given character.

More details

The way this usually works are that the printing characters are sent like you'd expect. Numbers and symbols send the ASCII code for that number or symbol. Lower case letters go through as the lower case letter. Shift+letter goes through as the upper case letter.

What is considered to be happening under-the-hood is that holding shift modifies the next key. In the case of letters, the modification is to remove the 5th bit (0x20), so 'a' being 0x61 becomes 'A' at 0x41, and 'z' being 0x7A becomes 'Z' at 0x5A. (this is a convenient way of thinking about it at anyrate. I think the actual progression was different).

The control key is another modifier, which instead of clearing bit 5 while held down, clears bits 5 and 6 (0x60), so 'a' goes from 0x61 to just 0x1 which is ASCII start of header. 'm' with the control key gets converted from 0x6D to 0xD which is carraige return, which is also what the Enter key sends. This is why ctrl+m and enter are mapped the same time in Vim; they are the same character.

Since there is no upper or lowercase with control (the shift clearing bit is included with control), and keyboard keys are usually shown in upper-case, and old systems didn't have lower case anyway, the convention is showing uppercase. To designate that it is a representation of a control key, a ^ is placed before it. For example, a literal bel character in a file opened by Vim will be displayed as ^G. This allows a printable representation of an unprintable character. This doesn't cover all 31 control characters though. I don't know the reasoning behind the others, such as ^@ for null or ^^ for 0x1E (often typed as ctrl+6 regardless of where the ^ key is on your keyboard). Another interesting one on my system is that ctrl+4 is equal to ^\, and control+\ is the code to terminate (vs ctrl+c to interrupt) the running program.

Alt/meta is another issue. There aren't other characters in ASCII left to reference. Many GUI terminal emulators have configuration options on how to handle this. Popular methods are to send an escape char followed by the key pressed with alt (complete with shift processing). Another is to treat it as a modifier that sets bit 8. The former can cause Vim to leave insert mode (because of the escape), the latter can break encoding (that is, collides with latin1 or whatever characters, or starts an utf-8 sequence)

Specifically on disabling control key

Because you can map characters, one option is to map every character that results from modifying a typed character with a control key to a nop, as in

map <c-a> <nop>
map <c-b> <nop>
...

however, because several keys are equivalent, you would cause a removal of those functions as well. This includes aborting the current action (ctrl+c), the enter key (ctrl+m), backspace (ctrl+h or ctrl+?, another long story about those two that I won't get into now), tab (ctrl+i), and escape (ctrl+[).

You might be willing to do this, of course. All of the functionality except ctrl+c and escape key can be done with normal commands, if you only disable these in insert mode (e.g. escape + o instead of just enter while in insert mode, or escape, x, a instead of backspace in insert mode. Tab could probably be inserted by writing a function that generates it, or by yanking an existing one into a register for subsequent paste). The action of escape could be mapped to something else, like jj to get you our of insert mode. However, other keys that start with escape will also break if you map out the escape key itself. This includes the F1 through Fn keys, arrow keys, in some cases the number pad, sometime the delete key, page up/down, home/end, and depending on your setup, anything with the alt key pressed.

Of course blanket disabling would cause problems. How can you execute an ex command if you don't have enter/ctrl+m? Maybe jj escapes and jk executes? But then you have to hope you never need jk anywhere in your command. You wouldn't even be able do do something like j space backspace k to avoid the mapping, because you wouldn't have backspace either.

Additional thoughts

In OP's comments, it is mentioned that the reason for disabling control is to train to do things that don't use control. Some comments mention modyfing the key mappings at the OS level, which would remove being able to send control characters with the control key without disabling the terminal receiving tab and enter from the OS and sending those as control characters itself.

However, I must recommend that if your fingers are getting sore with your current setup, the best thing you can do is probably to change your setup. Everyday typing should not make you sore. A few options are to take more breaks from typing, adjusting your typing position, and/or obtaining a more ergonomic keyboard (not generically, but suited to your needs). At any rate, let the soreness itself be the guide to reducing or removing the habit that induces the sorenes; rather than jumping to disable the functionality of the system, try to be more concious of what you are doing to notice when you do something you don't wish to do. (hopefully that's neither too zen nor too useless)

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.