The goal is to remap CapsLock to Esc in Vim, installed on Ubuntu (console only, no Desktop Environment).

This Ubuntu system is installed on Virtual Private Server. I'm logging to this server using Putty, from my home laptop with Windows 10.

And everybody are talking about mapping this CapsLock key to Esc in Vim, but I was unable to find actual line, that needs 2 be written in $HOME/.vimrc file.

This is what I've tried myself, but none of this works, except for the first line adding row numbers:

set number

inoremap <Caps> <Esc>
inoremap <Caps_Lock> <Esc>
inoremap <CapsLock> <Esc>

The goal is to remap CapsLock to Esc only in Vim, not the whole Ubuntu server.

I've checked and CapsLock works fine in Vim, and makes UpperCase when locked.

I've searched so many places like: https://vim.fandom.com/wiki/Mapping_keys_in_Vim_-Tutorial(Part_1) all 3 parts of this guide and here as well.

Like everything is written there: mapping "ii", "jj", "jk", "jw" different Ctrl and Shift combinations. Everything except CapsLock to Esc remap.

??? Why ???

Why is it so hard to remap CapsLock to Esc in Vim? It's almost my question, but unfortunately on Windows OS.

From the comments below my question I gather that mapping CapsLock to Esc is impossible in Vim alone.

I've also read this thread: How to use CapsLock instead of Escape in Vim?

And the answer that's accepted states: "For remapping in the console, if your distro uses systemd, you can use a custom keyboard layout in /etc/vconsole.conf as described on the Arch Wiki."

I guess Ubuntu uses systemd, so I'm ready to accept the answer that's going to map CapsLock to Esc key in whole Ubuntu installed on my VPS, providing my home, Windows machine key mappings, remain unchanged.

I've run this:

michal@localhost:~$ localectl status
   System Locale: LANG=en_US.UTF-8
       VC Keymap: n/a
      X11 Layout: us
       X11 Model: pc105

What should I do next?

I think I don't have this file /etc/vconsole.conf on my Ubuntu VPS. Should I create it myself, or should it be there by default?

  • 1
    Vim isn't even aware of Caps Lock. Certainly not on some client that's connected to a server in which Vim is running. It just gets uppercase characters from whatever the input source is. Note how none of the answers in the post you linked to have anything to do with Vim.
    – muru
    Commented Oct 10, 2021 at 12:55
  • @muru Can you please write little more details on why it's so difficult to remap CapsLock to Esc key? What do you mean when you say "Vim isn't even aware of Caps Lock."? Commented Oct 10, 2021 at 14:20
  • 1
    I mean that Caps Lock handling is done outside of Vim. So it neither knows nor has to care what CapsLock is. Obviously it's going to be impossible to change the handling of something in Vim when Vim has nothing to do with how that is handled in the first place.
    – muru
    Commented Oct 10, 2021 at 14:33
  • I've edited the question and I'm willing to accept the answer, that's going to map CapsLock to Esc key in whole Ubuntu installed on my VPS, Commented Oct 10, 2021 at 15:03

1 Answer 1


An easy alternative would be to add this in your vimrc file

imap ii <Esc>

Here I am using ii( 2 'i's ) instead of Escape to return to Normal mode.

You may rarely encounter a word with two consecutive ii in English Language so you won't accidentally get to normal mode.

You can also replace ii with any other Key if you want but as far as I know and I have tried, it doesn't work with keys like Caps Lock, Shift, Ctrl and Alt since they require any other key in order to give something meaningful.

  • OP explicitly mentions this ('Like everything is written there: mapping "ii", "jj", "jk", "jw"')
    – muru
    Commented Jan 6, 2023 at 11:49
  • They have also asked for why is it hard to remap Caps Lock, which is why I have posted it. Also similar questions will now be marked as [duplicate] so newbies should have a clear answer right here, without having them to go through that detailed stuff Commented Jan 7, 2023 at 2:51
  • But you don't answer that question either.
    – muru
    Commented Jan 7, 2023 at 8:52
  • I have said in my answer that since Caps Lock is a supporting key, it doesn't mean anything on its own and the OS usually sends a signal to the text editing software only when you hit another key that makes it meaningful, same is the case for Shift, Ctrl, and Alt. For example in the Caps Lock's case, the OS subtracts (64/32)'h20 to every preceding English letter inserted which makes it a capital letter. Therefore, it is hard to capture the keystroke of the Caps Lock key since OS, compilers, or text editors aren't designed to hear the keystroke itself. Commented Jan 7, 2023 at 15:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .