Although the holiday season is sort of officially over (with Dreikoenigstag, on the 6th), I thought to sneak in a post whose title fits to the holiday season, and whose contents could be a tiny gift to some touch typists working on the command line.
Of late, I have started creating keyboard shortcuts that keep my fingers close to the home keys. This is especially useful as I use different keyboards during the day, each of which have different layouts for some crucial keys. I also don’t like reaching for things like escape, or the number keys, which are needed for Perl programming (e.g. 4-$).
My .vimrc file contains the following custom mappings. ‘:imap’ tells vi to interpret the first set of keys (e.g. ‘;x’) as another (‘escape + dd + insert’). Just add the mappings into the .vimrc file in your home directory and you can try them out. One thing you should do, though, is create an vim alias that points to a plain .vimrc file. That way you can paste in text that contains the mappings that you’ve created.
The first set help with general editing tasks. One of the main advantages is that you can do lots of editing without having to exit edit mode. I find this to be much faster than hitting escape, and then the appropriate key(s).
1 2 3 4 5 6 7 8 9 |
" General editing: :imap ;x <Esc>dd<Ins> :imap ;c <Delete> :imap ;z <Esc>u<Ins> imap <c-Z> <Esc><c-r><Ins> :imap wq <Esc>:wq<Return> :imap ;w <Esc>:w<Return><Ins> :imap zk <Esc><Right><s-D><Ins><Right> :imap zn <c-n> |
The second set turn vi into a poor man’s Eclipse. I’m sure there are other tricks one could use to save even more time (and there are others I haven’t shown, as they are not obvious and might only be of use to me).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
" Programming: :imap ;; ;<Return><Tab> :imap ;d $ :imap zu _ :imap ;e <Space>=<Space> :imap ;a -> :imap zp ()<Left> :imap z[ []<Left> :imap ;b {<Return><Return>}<Left><Up><Tab> :imap ;b; {<Return><Return><Tab>}<Left><Up><Tab><Tab> :imap ;b;; {<Return><Return><Tab><Tab>}<Left><Up><Tab><Tab><Tab> :imap ;bb {}<Left> :imap ;q ""<Left> :imap wm <Esc>:make<Return> :imap zm my<Space>$ :imap ;g <Space><-<Space> |
You can also add the following to .inputrc and get keyboard shortcuts in any shell that uses the Readline library.
1 2 3 4 5 6 7 8 |
";g": " <- " ";e": "=" ";d": "$" "zu": "_" "zp": "()\C-b" "z[": "[]\C-b" ";b": "{ }\C-b\C-b" ";q": '""\C-b' |
For example, the first one will create the R assignment operator with little finger movement. Apparently, the terminals on which R was developed had a key for ‘<-‘, so it wasn’t as awkward to use then. I do agree, as per the Google style guide, that ‘<-‘ is superior to ‘=’ (even from a purely aesthetic viewpoint). Happy typing!