DEV Community

ᴙɘɘᴙgYmɘᴙɘj
ᴙɘɘᴙgYmɘᴙɘj

Posted on

One-Handed Vim

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>
Enter fullscreen mode Exit fullscreen mode

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>
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

and it will be swapped with

foo.reduce((acc, value) => {
  return {
  ...acc,
  }
}, {})
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (6)

Collapse
 
elliot profile image
Elliot

Careful, soon enough you will have right hand macros on one vim window and left hand macros on another window. You will be able to write two programs at once, but at the expense of the hemispheres of your brain becoming unnaturally independent and your personality becoming irreversibly altered.

Collapse
 
reergymerej profile image
ᴙɘɘᴙgYmɘᴙɘj

brain becoming unnaturally independent and your personality becoming irreversibly altered

You could claim that's a natural result of using Vim anyway.

Collapse
 
coreyja profile image
Corey Alexander

Sorry you broke your hand, that's gotta suck. Hopefully the recovery goes well!

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

I'll admit I use my mouse in VIM daily. You're right sometimes it's just more convient. It's a good tool to have even if you don't use it all the time

Yeah, it will suck, but I'll come out the other end even faster.

This is what I kept thinking as I read this! I can't imagine how fast you'll be once you are back to two hands!

Collapse
 
reergymerej profile image
ᴙɘɘᴙgYmɘᴙɘj

Thanks for the good vibes!

This reminds me of relearning to write in cursive. You have more time to think about what you're writing. As a result, you are more thoughtful and less likely to "ramble."

Collapse
 
chsanch profile image
Christian Sánchez

Here is a "cheat sheet" of Vim Motions:

gist.github.com/dahu/3986511

Hope you get better soon!

Collapse
 
jamessral profile image
James Sral

Great tips, and excellent mug