I dislike to have to reach up to the Escape key all the time. For a while I used the program xcape under Linux to map Caps lock to be both Control and Escape. However, I am currently working more and more on a Mac so I can’t have the same keybinding without much increased effort.

I thought that the key combination of Control-Space would be quite nice.

I tried to rebind with:

map <NUL> <ESC>
nmap <NUL> i

But that does not work correctly, often inserting the same text again.

  • 4
    An alternative to Esc key that is more 'reachable' is Ctrl-[
    – tivn
    Apr 25 '15 at 15:58
  • Why would <Nul> be a ctrl-space?
    – Ben
    Apr 25 '15 at 23:38
  • Control-Space is a potentially difficult thing, since it's a signal which differnt TERMs send differently. It can be <C-Space> or <NUL>, if it's sent at all. Apr 26 '15 at 19:50

I found this map works for Ctrl-Space :

:nnoremap <C-@> i
:inoremap <C-@> <Esc>
  • 1
    Yes, I found that's what I have had to use for vim in terminals. The way to discover such things is to see what Vim produces when you type i<Ctrl-V><Ctrl-Space> or :<Ctrl-V><Ctrl-Space>. Dec 12 '15 at 4:53
  • Beware if you use Ubuntu 14.04, iBus may be intercepting the keystroke. Check the preferences of the little keyboard icon in the dock that lets you select language / keyboard input method, and change the mapping to something else (I went for <Ctrl-Alt-Space>). Dec 12 '15 at 4:56
nnoremap <C-Space> i
inoremap <C-Space> <Esc>
  • Does not do anything in normal mode exept beeping and in insert mode somehow triggers completion. :/ Apr 25 '15 at 14:37
  • 1
    Do you have existing mappings for c-space? These should work, I think, unless your vim is not recognizing the keystroke.
    – Ben
    Apr 25 '15 at 23:40
  • Should work for most modern terminals, however you can also map <C-@>like @tivn suggests, that works as well, the reason being both send the same key codes to vim. Apr 26 '15 at 23:05

Probably because the touch bar escape key is a bit difficult to hit reliably, Mac now has an option to turn capslock into the escape key. System Preferences -> Keyboard -> Modifier Keys.

  • 1
    I believe that option existed before the touch bar, but I could be wrong. At any rate, welcome to Vi and Vim!
    – D. Ben Knoble
    May 14 '20 at 13:50

As @pdr written, macOS has the ability to change the behavior of some modifier keys.

You can go to System Preferences -> Keyboard and check on the lower right corner of the window. There is the button Modifier keys....

If you click the Modifier keys... button, then a drop-down panel appears when you can change the behavior of the keys:

  • Capslock
  • Control
  • Option
  • Command
  • Function

Personally, I have mapped Capslock to Escape.

This works also in the touch-bar models of Apple.

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.