Using Vim with Colemak

Posted by Xudong Zheng on December 28, 2017

Colemak is one of the most popular alternatives to the standard QWERTY keyboard layout due to its (arguably) superior ergonomics. Using it with Vim, a highly customizable modal text editor, allows me to maximize productivity when either programming or writing.

Vim users who are considering the switch from QWERTY to Colemak are confronted with the dilemma as to whether it is worthwhile to remap Vim's default binding to maintain the key positioning under Colemak. Both options have various benefits and challenges. For those that choose to add Vim mappings for Colemak, there are different ways of doing so each with its own tradeoffs.

No Changes

Keeping the default Vim bindings can be very beneficial for users who frequently work on remote machines with only the standard Vim configuration, allowing them to use Vim with the same muscle memory. This is perhaps the simplest solution although a major drawback is that the right index finger is responsible for all 4 hjkl keys. While I do not rely on hjkl to navigate within Vim, I use them often enough that using Vim's default bindings ends up being inconvenient.

Using "noremap"

My preferred solution is using noremap to map Colemak keys to the corresponding QWERTY keys. This works well for me because I am able to deploy my personal .vimrc to remote servers that I administer. You can take a look at my complete .vimrc file to see what exactly I've done (along with my other customizations).

noremap d g
noremap e k
noremap f e
noremap g t
noremap i l
noremap j y
noremap k n
noremap l u
noremap n j
noremap o p
noremap p r
noremap r s
noremap s d
noremap t f
noremap u i
noremap y o
noremap D G
noremap E K
noremap F E
noremap G T
noremap I L
noremap J Y
noremap K N
noremap L U
noremap N J
noremap O P
noremap P R
noremap R S
noremap S D
noremap T F
noremap U I
noremap Y O

As a simple example, you would use n instead of j to go to the next line since n in Colemak uses the j QWERTY key.

These mappings only affect verbs and modifiers; they do not affect text objects. Deleting inner sentence is sus under Colemak compared to dis under QWERTY. In this example the verb d and modifier i are positionally the same between QWERTY and Colemak whereas the text object s uses a different physical key but maintains its logical meaning.

Using "langmap"

An alternative solution is using langmap. For this to work, your Vim must have been installed with the langmap version. This may not be the case for some minimalist Vim installs. Note that my version below maps o to p and leaves the semicolon alone rather o to ; and ; to p.

set langmap=dg,ek,fe,gt,il,jy,kn,lu,nj,pr,rs,sd,tf,ui,yo,op,DG,EK,FE,GT,IL,JY,KN,LU,NJ,PR,RS,SD,TF,UI,YO,OP

When using this approach, everything is mapped verbatim from QWERTY to Colemak. Deleting inner sentence is sur for example.

Comparing "noremap" vs "langmap"

I strongly prefer the noremap approach as your other Vim mappings needs minimal changes to accommodate Colemak.

This is easy to demonstrate with a simple example. Suppose you had <leader>f for changing the case of everything until the end of the word.

nnoremap <leader>f ve~

Using noremap, you can keep this and still press <leader>f to trigger the mapping albeit the position of the f key has changed.

With langmap, you need the following instead if you want trigger the mapping with <leader>f. Essentially you need to convert the left hand side to QWERTY whereas the right hand side is the non-sensible converted QWERTY sequence.

nnoremap <leader>e vf~

In my opinion, the noremap mapping approach makes much more sense: the left hand side is what you are typing and the right hand side follows standard Vim behavior.

Using "langnoremap"

set langnoremap can be used alongside langmap to make langmap behave more like noremap described above. I've ran into some edge cases where behavior is inconsistent though some of these could be attributed to some bug in Vim rather than the expected behavior.