Vim takes a lot of dexterity and practice. Speed comes with time and a lot of muscle memory. It’s a big investment, but worth it.

And then you break your hand.

mono

That’s OK. You can still work at a decent pace. Here are some tips.

Macro Everything

Basic

First, add a macro to edit and to source your vimrc. You will need to edit it a lot.

" edit this file
:nnoremap <leader>ev :vsplit $MYVIMRC<cr>

" re-source this file
:nnoremap <leader>sv :source $MYVIMRC<cr>

Going forward, you can open, change, save, and source your runtime config in no time.

Add mappings for write and quit.

:nmap <leader>ww :w<cr>
:nmap <leader>qq :wq<cr>

Common Structures

As you’re writing code, you will recognize structures you use a lot. Add insert mappings for them. For example, in insert mode, if I want to reduce an array, I can type …

foo.rrr

and it will be swapped with

foo.reduce((acc, value) => {
  return {
  ...acc,
  }
}, {})

Take the time to write these. You’ll have to goof around to find what you like, hence the quick source thing we did at the beginning. Here are some I’m using for JavaScript.

" insert if block
" if () {
"
" }
:imap iii if () {<cr>}<esc>kwa

" insert braces
" {
"
" }
:imap {{{ {<cr>}<esc>O 

" insert brackets
" [
"
" ]
:imap [[[ [<cr>]<esc>O

" insert arrow fn
" () => {
"
" }
:imap ((( () => {{{return 

" map loop
:imap .mmm .map((item) => {<cr>return item<cr>})<esc>kA

" reduce loop
:imap .rrr .reduce((acc, value) => {<cr>return {<cr>...acc,<cr>}<cr>}, {})<esc>kkA

" console
:imap ccc console.log()<esc>i

Efficient Moving

Take a moment to think about what you’re navigating to. Lazy kkkkkjjjjkj crap doesn’t work well in one-hand mode. Look at relative line numbers. Move to them properly.

  • Go up 17 lines with 17k.
  • Go to the next r with fr.
  • Go to the first blank line above you with {.
  • Go down 3 folds with 3zj.

Brush up on your movements a bit and take the time to do them correctly.

Use <C-o> and <C-i> a lot. As you hit the wrong keys, you’ll bounce around a lot. These take you back or forward.

Don’t be a purist. Sometimes the mouse is faster, especially when you’re confused

Avoid Typing

Especially if you’re typing really long entity names, use ctrlp.vim or something to auto complete for you. This avoids typos and can be much faster. This includes when opening files.

Slow is Smooth, Smooth is Fast

That’s an Infantry motto that applies well here. I’m going to take these next many long weeks to practice deliberate movement and optimizations. Yeah, it will suck, but I’ll come out the other end even faster.