Command to toggle keyboard layout

It should be enough to just add this line to ~/.vimrc:

set keymap=foo

Where foo is the name of your keymap. For instance, I tested with set keymap=greek and I was typing in Greek when I opened vim (of course, then I couldn't exit the thing but that's vim for you).


If that doesn't work for some reason, here's an ugly, hacky approach you could try instead. Add this to your ~/.bashrc:

vim(){
  setxkbmap XX ## change this to whatever keymap you use for vim
  command vim  ## launch the actual vim executable
  setxkbmap YY ## change to whatever your default layout is
}

Now, open a new terminal and use vim. The keyboard layout will be automatically changed for the vim session and changed back when you exit vim.

This is not a very good solution, however, because the keyboard layout will be changed for all applications. It simply does it automatically and changes back when you exit, but you will still have the new layout for all other windows, as well as vim. The first approach is much better.