Many russian VIM lover as well as user, who uses not only en_US keyboard layout knows about troubles with switching keyboard layouts over and over again to switch between text input and commands in normal mode.

If you’re familiar with <C-^> and set keymap=russian-jcukenwin you may find it not so usable. Unfortunatelly, I found no :help neither about how to bind CapsLock key directly, nor how to change keybinding from Ctrl + ^. So here are my workarounds to switch MacOS keyboard layouts globally by Caps everywhere, but in Vim.

System settings

Unbind it in system settings, (note current keyboard switching keystrokes is Cmd-Space:

Unbind it in system settings

Next you need PCKeyboardHack and rebind your Caps:

Make it work as PC_APPLICATION

Then you need beta version of KeyRemap4MacBook. Last stable version 9.3.0 haven’t worked with window’s titles properly.

Configure KeyRemap4MacBook

Into the file private.xml paste this:

<?xml version="1.0"?>
    <name>CapsLock to Crtl-^ in Vim</name>
    <appendix>forces it to change keymap</appendix>
      <autogen>__KeyToKey__ KeyCode::PC_APPLICATION, KeyCode::KEY_6, ModifierFlag::CONTROL_L | ModifierFlag::SHIFT_L</autogen>
      <autogen>__KeyToKey__ KeyCode::PC_APPLICATION, KeyCode::SPACE, ModifierFlag::COMMAND_L</autogen>

And load these settings:

Settings load KeyRemap4MacBook

Vim settings

Finally, configure Vim like this:

set keymap=russian-jcukenwin
set iminsert=0
set imsearch=0
set imdisable
highlight lCursor guifg=NONE guibg=Cyan
nmap <C-^> <Nop>


If everything went ok, you should be able to switch keyboard layouts system-wide with CapsLock, but in console vim or macvim this should take no effect in normal mode, but once you switched into insert mode and press it you should be able to type привет!, once you left it, you still have US layout in normal mode.

hello vim

Cool, yeah?