Socob
Socob

Reputation: 1284

Remapping a key to Escape in Vim (German keyboard)

Okay, so I've been trying out Vim (the standard console version; my OS is Linux Mint 13) and I'd like to get rid of having to use the Escape key to change modes. Preferably, I'd like to swap the Capslock and Escape keys, but as far as I've heard, that's not possible within Vim itself. Most "solutions" I've found involve changing the key on a global level (using xmodmap or whatever), but I don't really want that. If there's an easy way to swap Capslock and Escape only in Vim, please let me know.

Another common thing I've heard of is using "Ctrl-[" as an equivalent to Escape. However, because I'm using a German keyboard with a different layout, that's not an option. So, I thought I'd use noremap <C-ü> <Esc> in Vim (the "ü" key on a German keyboard is in the same place as the "[" key on US keyboards), but that didn't work, either. I'm assuming that's because "ü" isn't an ASCII character. Is there any way to get either of these options working?

UPDATE: Well, this is strange. After experimenting some more, it seems that "Ctrl-ü" does work after all. I'm not sure what happened – maybe I messed up some encoding-related settings while trying different things? If there is no good solution for remapping capslock, I guess I will stick with "Ctrl-ü".

Upvotes: 2

Views: 3216

Answers (3)

Spectator6
Spectator6

Reputation: 403

Here is another alternative that may be useful to you! It involves changing the keyboard file related to VIM. I found this suggestion on this youtube video

$ cd /usr/share/X11/xkb/symbols/
sudo vim pc

to edit the capslock key to escape, change the capslock line to read as follows:

key <CAPS> { [ Escape ] }; 

:wq # to write and close the file

Log out and log back into the machine and it should be updated!

Upvotes: 0

Socob
Socob

Reputation: 1284

So, yeah, eventually I decided to go with <C-ü> because it doesn't conflict with anything else and because it's the same as <C-[> on US keyboards.

However, because I'm getting tired of using the German keyboard layout for programming (for example, to get "{" you need to type "Alt Gr-7"), I'm switching my keyboard to US-International, which essentially has a similar effect as far as Vim is concerned. It also helps if you want to want to get into the habit of touch-typing; you actually can't look at the keyboard because the keys aren't labeled "correctly" ;-)

Upvotes: 1

romainl
romainl

Reputation: 196566

A lot of people use jk:

inoremap jk <Esc>

You can also simply do <C-c>.

Upvotes: 0

Related Questions