13

I have been using VIM for around 7 months now for all writing and all coding. Maybe 1-2 hours per day.

I can use it and work quite fast with it. Most of the time I know what I am doing.

But I still find myself looking at the keyboard sometimes to do basic things... like going down one line and left 5 times.

Are my expectations wrong or am I making slow progress?

12
  • 8
    Looking at your keyboard while using vim commands isn't a issue related to vim/nvim. If you are looking at your keyboard while typing, you'd rather improve your typing.
    – Diwas10
    Commented Oct 24, 2022 at 7:45
  • 6
    If your typing is quite good, then all it takes to master vim commands is practice. It's that simple.
    – Diwas10
    Commented Oct 24, 2022 at 8:03
  • 3
    When you look at the keyboard, what are you hoping to see?
    – MDeBusk
    Commented Oct 24, 2022 at 15:16
  • 1
    @Vinn What's your keyboard layout look like? On a standard QWERTY US keyboard layout, h would be immediately to to the left of your right index finger's home position, should be easy to reach. Your comment about it being far makes me think you might be using a different layout? vim's keybindings are designed to be convenient for a standard QWERTY US keyboard, if you don't have that, I'm not surprised you're having a hard time.
    – effect
    Commented Oct 24, 2022 at 17:59
  • 4
    Leaving a comment because just this bit struck me: "going left five times". Could you use e.g. b, B, F, T or search (/) instead?
    – Oliphaunt
    Commented Oct 24, 2022 at 20:26

4 Answers 4

24

I think for me the key was (and the optimization-happy engineer in me is aghast at this) not trying to vim-golf my motions. Because once you have to think about the motion it takes you out of the flow.

Find key combos that work for you. Then, when you're ready to focus on improving efficiency, pick one thing you want to improve on and try to consciously get better at it. In your case, instead of trying to jump vertically/horizontally optimally, maybe just go ahead and (sounds like you're on a macbook where this is easier) just arrow over for now (I know I know please don't lynch me). Get comfortable where it's automatic.

Then start optimizing. For me atm it's using yi({[ and ci({[ instead of t and f when trying to grab or change expressions.

Because once it is automatic, it will probably feel so friggin slow. I find pairing with other devs (especially non-vimmers) helps put me in the right mindset: I cringe because I can literally feel when their hands leave the keyboard to reach for the mouse and when the cursor is moving one character at a time it feels like I could re-write War and Peace before they get where they're going.

If using hjkl to move is what you're currently trying to improve on, just practice more.

5
  • 1
    I believe this is the ultimate truth. Focus on one thing at a time. I've picked up many things that are natural (like jumping paragraphs, visual line mode, ciw etc etc..) but I think if I target single problems (like the blasted h key) I can get better. Thanks
    – Vinn
    Commented Oct 24, 2022 at 17:30
  • 3
    for movement, searching (/, f, etc.) is often one of the fastest ways to get anywhere without counting, though if your search isn't accurate enough you may have to mash n/;/etc.
    – D. Ben Knoble
    Commented Oct 24, 2022 at 19:45
  • 1
    Since this is the accepted answer, I'll attach this article on "deliberate practice" to it.
    – MDeBusk
    Commented Oct 24, 2022 at 20:55
  • 1
    @MDeBusk thanks! Deliberate practice > random practice > no practice Commented Oct 24, 2022 at 21:23
  • 1
    As a relative Neovim n00b myself, this resonates. Trying to memorize too many things at once makes you slow at all of them. And, like a golf swing, you don't just go out there and do the whole thing, you drill on parts of it and then put it together. Commented Mar 24, 2023 at 0:18
16

What helped me was to vocalize the commands I'm issuing in my head while keying them into Vim, e.g.:

  • "change inside quotes" ⇒ ci"
  • "goto definition" ⇒ gd
  • "change surroundings parens to brackets" ⇒ cs([

The goal of that exercise is not only to memorize the commands but also to build a "vocabulary" for what you are doing. Over time this vocabulary will become internalized and you won't need it anymore. It shortens the distance between your intentions and your actions.

You don't have to do this all the time, but take some time every day to do it.

6
  • 1
    While this is a fine way to learn new commands, it's sub-optimal for getting faster, which is what the OP is wanting to do. Sub-vocalization slows you down because it restricts you to the speed of speech.
    – MDeBusk
    Commented Oct 24, 2022 at 20:56
  • 1
    @MDeBusk Re: speed of speech. Eventually text editing thoughts go straight to your hands vocalizing vim commands to the keyboard. It's like a bilinguist starting with thinking in their primary language, translating, and then speaking in their secondary language. Eventually with practice, their mouth will start outputting their secondary language without their brain involving their primary one at all. It's the same thing, only with your hands instead of mouth.
    – JoL
    Commented Oct 24, 2022 at 22:52
  • 1
    @JoL "Eventually", maybe. If you unlearn subvocalization. Most people don't, because they don't even realize they do it. Research has consistently shown, too, that translating from one's native language impedes acquisition of foreign languages; we're better off learning foreign vocabulary the way we learned our native vocabulary. And I'm pretty sure we're now off-topic.
    – MDeBusk
    Commented Oct 25, 2022 at 0:12
  • 2
    Could you expand a bit on how that cs([ command works? I can't find anything about it in the helpdocs, and I can't make it work in my version of Vim (or Neovim for that matter).
    – Arthur
    Commented Oct 25, 2022 at 13:38
  • 4
    cs is defined in Tim Pope's vim-surround plugin - github.com/tpope/vim-surround. It's very helpful for adding, changing or deleting "brackets" of all sorts around a text object or motion.
    – Phil R
    Commented Oct 25, 2022 at 18:47
4

Jared Smith's answer is generally correct, but here I'll provide a few more hints on how to implement this.

The very first thing you need to do, above all else, is to make sure you can touch-type (i.e., with your eyes closed) the entire keyboard, including numbers and punctuation. For example, you already know that going down one line and left five times is j5h; you should not be looking at the keyboard for any of this. Many moves require the use of punctuation (e.g., paragraph forward/back }/{ and search forward/back for word under cursor */#), which is why you need to be able to touch-type this just as easily as you can hjkl.

Learning this, if you don't already know it, will require slowing down before you can regain and exceed your previous speed. Like learning a scale on a musical instrument, you need to learn it correctly before you can do it correctly at speed.

Once you've got down these sorts of basic moves, move on to using counted basic moves that get you roughly closer to where you want to go when you need to do the move more than three or four times. 8wbb is fewer keystrokes than hitting w six times, and you'll be faster getting near where you need to go and then doing a small number of moves than you will trying to calculate a large count in advance.

At that point it's time to start adding new commands. Explore the Vim documentation (:help), looking both at keystrokes you don't know to learn what's out there and at entire sections to see what's in the various command groups that can be helpful. As Jared says, pick something that seems the most useful and slow yourself down to start using it. Wait until you come back up to speed again with these new commands before trying to bring in more.

Once you've explored a fair number of Vim commands, you'll want to start examining what you're still inefficient on in your particular application and start adding mappings and functions to help you handle those. For example, I do a lot of markdown editing with references at the bottom of the file or section in which they're used; I've added gr to search for the reference under the cursor (e.g., text like "[foo bar]") so I can easily move to other references and the reference definition. After using this for a while I added gR to read the reference the cursor is one, jump to the reference definition, and copy the URL of the reference to the "+ buffer which lets me paste it directly into a browser, curl command line, or whatever.

6
  • This brings up a very important point... while I can touch type with my eyes closed already. I use a keyboard in the office. But the "raw laptop" at home. They keyboard is significantly different in size and placement of the keys. This is slowed me down wildly as i never get a feel for where the keys are.
    – Vinn
    Commented Oct 26, 2022 at 12:58
  • 1
    This is super useful btw. Thanks cjs
    – Vinn
    Commented Oct 26, 2022 at 12:58
  • 3
    @Vinn That's a good point; using a lot of different keyboards can make life more difficult. I've gone to what some people might consider an extreme: I buy only ThinkPad laptops, and I own several USB and Bluetooth ThinkPad stand-alone keyboards for use on desktop computers. (And even other laptops; I bring one over when I'm pair programming with someone.) This gives me both a (mostly) standard layout and a TrackPoint everywhere, which is another thing that keeps my fingers near home row.
    – cjs
    Commented Oct 26, 2022 at 13:01
  • This is a fab peice of advice. The quick fix for me here would be to buy the shorter magic keyboard for mac (at the moment I use the long one with num pad at work). The only problem is... I wanna move 100% to windows duel boot linux haha! Gotta love this programming world. So many decisions!
    – Vinn
    Commented Oct 26, 2022 at 13:25
  • @Vinn I'm not too familiar with Apple stuff, but the Magic keyboard is just a standard Bluetooth keyboard, is it not? So you should be able to use it just fine on Windows or Linux as well (I use my BT keyboards on both), with the caveat that you'll still need a wired keyboard to enter your full-disk decryption password at the start of the boot process (and to do the install, etc.).
    – cjs
    Commented Oct 27, 2022 at 0:16
2

The other answers here are already great and you should follow their advice first. But I'd like to add:

Periodically look for new useful commands

Periodically review vim cheat sheets looking for new commands that could be helpful to add to your repertoire. By using a cheat sheet you're not having to sift through everything in vim help so you're more likely to find useful things. Don't keep using the same cheat sheet because you might find something interesting on a different cheat sheet and it is good to get fresh perspectives. Google will help you find hundreds of different cheat sheets out there.

I left "periodically" vague above on purpose. It might work best for you every month in the early days of using vim and then every quarter and then every year as you've been at it longer. Spacing it out means you've had time to let the prior new commands sink in and become muscle memory and you will have run into new challenges that might have command sequences to make easier. Consider putting a reminder on your calendar.

Put up a poster

This poster used to be commonly found in University terminal rooms:

old vi poster

Staring at something like this everyday will remind you of commands that you might otherwise forget. Consider posting something like this in sight of your computer if you have room.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.