DEV Community

Cover image for Accelerated Vim-Provement
Ryan Palo
Ryan Palo

Posted on • Edited on • Originally published at assertnotmagic.com

Accelerated Vim-Provement

I'm currently working on practicing and learning to use Vim as an editor. After a few sorry attempts to learn it quickly by sitting down and doing a few tutorials, I've learned that the road to Vim mastery for me will consist of a slow, steady grind of practice, learning and conquering one thing at a time, letting the Vim philosophy soak in as I go.

Slow and steady

Learning to take the pressure off of myself to learn quickly and move on the the next thing has been difficult, but I'm glad for it. It's turned the hiccups, small frustrations, and the disappointment of having to Google the same thing for the umpty-seventh time into a weirdly relaxing and enjoyable journey. Instead of "I'm so dumb, I can't believe I can never remember how to delete a word", it has become, "Oh Vim, you little rascal, you got me again. We'll see who has the last laugh."

Oh, Vim...

I did come up with one thing that helped me speed things up a little bit, which I thought I could share.

Take the Training Wheels Off

One of the first things you learn when learning Vim is how to move around using h, j, k, l keys instead of the arrow keys. In theory, it's more efficient and keeps your hands in an ideal typing position. I don't think that using the arrow keys makes you a bad person, but there is one additional benefit to using these keys instead of the arrow keys:

You have exactly as much practice using h, j, k, and l to move around as you have with any of the other motion/command keys in Vim.

The arrow keys are sort of a crutch, because, if you want, you can ignore all of the commands and keys that make Vim extra useful and stick to just using the arrow keys and staying in Insert mode all the time. If this is how you're using Vim, you're essentially just using an obnoxious version of Nano.

All the features of Nano, with the added joy of continuously forgetting you're in Normal mode and trying to start typing, only to have your cursor do crazy things all over the screen.

If that's the way you like it, I have no problem with that. You do you. If you're trying to break that habit and convert your brain to the Vim way of doing things (via Vimception, maybe?), then I've found it is super helpful to actually throw away the crutch entirely and turn off your arrow keys.

Add these lines to your .vimrc file.

nnoremap <Up> <Nop>
nnoremap <Down> <Nop>
nnoremap <Left> <Nop>
nnoremap <Rigth> <Nop>
Enter fullscreen mode Exit fullscreen mode

Mapping a key to <Nop> (or no-op, or no-operation) causes it to do nothing.

But Why?

This is actually pretty common advice, but most articles will tell you only that it's to help get you more comfortable with h, j, k, l. This seemed dumb to me because... why would I want to learn a new set of keys that just do the same thing if I'm already efficient with arrow keys? I would say the benefit is not that I got more comfortable with h, j, k, l, but that I quickly got tired of pushing these keys. Without the arrow keys to fall back on, but with a desire to be more efficient, I've had a much larger incentive to learn keys like w, e, $, 0, G, gg and others!

You don't take the training wheels off of a bike so that you can say you're not using training wheels -- while continuing to ride slowly. You take the training wheels off of a bike so that you can quickly learn that it's actually much easier when you go faster.

Hard Mode Enabled

This works well, but there's still the temptation to just drop into Insert mode and use the arrow keys there, which defeats the entire purpose. To circumvent this, You can also disable the arrows in Insert mode as well by adding the following to your .vimrc:

inoremap <Up> <Nop>
inoremap <Down> <Nop>
inoremap <Left> <Nop>
inoremap <Right> <Nop>
Enter fullscreen mode Exit fullscreen mode

This will make your life frustrating at times. "But I just want to move over two characters! I don't want to have to drop out of Insert mode, move over and go back in!"

Tough. Cookies.

You're a tough cookie.

Stick with it! It'll pay off. I've only been doing that for like a week and I'm seeing huge improvements.

Bonus

For extra encouragement, replace all of the <Nop>'s above with this:

:echo 'STAHP.'<CR>
Enter fullscreen mode Exit fullscreen mode

Wrap Up

If you've got any Vim pro-tips, let me know. Vim is a fairly popular tutorial topic and everybody's got lots of opinions about it, but I'm always on the lookout for cool resources, books, guides, games, ways to practice, etc. I know there's a lot of people with a lot of knowledge to share, so share away!


Originally posted on assert_not magic?

Top comments (20)

Collapse
 
papey profile image
Jean Michel Functional Programming • Edited

This is also the setup I used. No arrow keys. After 6 years without it I used hjkl for my configs (zsh, xmonad, web browers, weechat etc...).

If you want to reduce finger travel here is another tip :

inoremap jj <esc>

Remap jj to is the second best thing i did in my vim life.

Collapse
 
maestromac profile image
Mac Siri

Can you tell me how you are using hjkl in terminal and on other applications?

Collapse
 
rpalo profile image
Ryan Palo

I found this post that has some good resources. Also, they link to their fork of oh-my-zsh that makes allowances for vi-mode while still letting you do history searching and stuff. Looks pretty legit, I'll have to check it out when I get home.

Thread Thread
 
maestromac profile image
Mac Siri

Thanks for that! I'll check that out.

Collapse
 
papey profile image
Jean Michel Functional Programming • Edited

I used personal keybinds, inspired by vim in my xmonad config and weechat config. For web browsers i recommend Vimium (For Firefox and Chrome/Chromium). For zsh there is a vim plugin available. A lot terminal apps works well out of the box with hjkl, so I always give it a try.

Collapse
 
eljayadobe profile image
Eljay-Adobe

I map CAPSLOCK to ESC. Not in Vim, but in the OS.

CAPSLOCK is a worthless key in a prime real estate location.

Collapse
 
maxdevjs profile image
maxdevjs

I do not remap CAPSLOCK only because I like to have this module active in polybar

long live to the capslock

Collapse
 
rossijonas profile image
Jonas B. R. • Edited

Well here is more tips on learning Vim, I hope it helps anyone:

First of all hit you terminal and type :vimtutor ...this is the first step! Take 30mins to 1 hr to practice relaxed, no rush! 👨‍💻

There's a nice book called Mastering Vim Quickly by Jovica Ilic, that is a pretty good one, and If you can't invest right now, you can subscribe to get chapters for free and newsletter tips.

vimcasts.org is a free good resource with videos and articles.

I started to write quick tips and tutorials for Vim beginners too, to help them deal with specific configs and get excited with tricks you can use.

You can check it on medium.com/vim-drops!

Duckduckgo.com has a cheatsheet embedded on the search bar... you can type vim cheatsheet and you get:
cheatsheet

Cheers!✌️👨‍💻⌨️👩‍💻✌️

Collapse
 
maestromac profile image
Mac Siri

This is a nice tip! What stopped me from doing this in the past is that I still rely on arrow keys when I'm in command-line mode (when you press : or /). My personal tip is to learn about leader keys and really make use of it 😃.

Collapse
 
rpalo profile image
Ryan Palo

Cool! What are some of your most frequently used leader commands?

Collapse
 
maestromac profile image
Mac Siri

My most used are saving, quiting, and save&quit in below. Reducing keystrokes are always a plus!

let mapleader = ","
noremap <leader>w :w<cr>
noremap <leader>q :q<cr>
noremap <leader><Tab> :wq<cr>
noremap <leader>f :tab split<CR>:Ack ""<Left>
noremap <leader>F :tab split<CR>:Ack <C-r><C-w><CR>
noremap <leader>3 :NERDTreeToggle<CR>
Thread Thread
 
rpalo profile image
Ryan Palo

Awesome. I'll definitely have to do more leader-ing. Thanks!

Collapse
 
awkravchuk profile image
Andrew Kravchuk

Neat! Here's the snippet I've just made for Spacemacs (which is mostly like Vim, but, erm, is in fact Emacs) to do the same thing: gist.github.com/lockie/6d74aa5ca2c...
I'm thrilled to start using it though, even writing this snippet in Spacemacs with half of rules activated made my brain tingle :D

Collapse
 
stsewd profile image
Santos Gallegos

I think this method is the best for stop using the arrow keys 😅

vim

Seriously, taked me a while to stop using them, I did it in this way:

  • Always keep my fingers on the home row
  • Navigate a lot of text using h, j, k, l (:tutorial is a good place).
  • Whenever I wanted to read some text/code I opened it on vim.
  • Keep doing that till feels natural, but be careful, you will try to use hjkl on everything!
Collapse
 
eljayadobe profile image
Eljay-Adobe

I've been using Vim for about 20 years. Before that I used Emacs for 2 years.

After a particularly interesting "my editor is better than your editor" flamewar with a coworker, we made a deal: I'd use Vim for 6 months, and he'd use Emacs for 6 months.

At the end of the 6 months, he switched back to Vim, and I never went back to Emacs. (I'm not saying Vim is better than Emacs. I'm saying that Vim is better for me.)

So for anyone thinking of using Vim my response is simply, "It's too late for me! Save yourself!" That's a "ha-ha only serious... well, only slightly serious."

Vim let's me become one with the keyboard. The editor gets out of the way. My fingers know it tacitly. I never have to reach for the mouse.

Bill Joy, the creator of vi, said that vi was made in the day of 300 baud modems and every character of very limited bandwidth was precious. These days, we have gigabit internet connections. The reason that vi is the way it is is no longer is a factor.

Yet I still use Vim, every day. I also use Visual Studio and Xcode... but when I want to do serious coding* I hop over to Vim.

* which is in C++... another "It's too late for me! Save yourself!"

Collapse
 
papey profile image
Jean Michel Functional Programming

Visual Studio Code vim plugin is awesome ! Even if I like VSCode, I can't get away from my neovim config and all the plugins I have.

Collapse
 
niorad profile image
Antonio Radovcic

The biggest eye-opener for me was embracing the difference between Tabs and Buffers.

joshldavis.com/2014/04/05/vim-tab-...

Coming from UI-Based editors like Sublime, learning the difference was an important step in understanding Vim (and also Emacs, similar principles).

Also, a more general tip for people considering Vim: Learn it anyways. The skillset you build by learning modular editing can be applied in any major editor/IDE via plugins.

Collapse
 
rpalo profile image
Ryan Palo

Cool, thanks for the tips! I’ll give that post a look.

Collapse
 
voyeg3r profile image
Sérgio Araújo

Talking about movements recently I discovered g_ to jump to the last non-blank char in the line and _ to jump to the first non-blank.

I also became amazed, long time ago with gf gi and gv

Collapse
 
andy profile image
Andy Zhao (he/him)

Obligatory @maestromac mention