Hacker News new | ask | show | jobs
by lhnz 5404 days ago
This is why I only use the most basic features of vim. There are simply too many commands to learn and many of these tutorial and cheatsheets present you with too much information. I don't think the time investment makes sense, and I don't understand why there has to be so much noise: how many of those commands save a significant amount of time; how often are they used?

The questions I would like to ask advanced vim users, are:

(1) Imagine that you had your memory of vim wiped, and you lost the ability to remember more than 10 commands. If you decided to learn vim again which 10 commands would you keep in memory?

(2) How many commands does somebody need to know before they can used vim productively? Is it less or greater than 10?

9 comments

I am an avid Vim user, and I also find such cheat sheets overwhelming. My pattern has been slow, incremental learning.

Starting from scratch is very intimidating. But when you have 10 commands in muscle memory, learning #11 seems pretty easy. When you know 50, #51 seems easy.

At first, using Vim was terrible. In a couple of weeks, I was back to "normal" productivity. In the 3 or so years since, I've continued to learn a new "trick" every few weeks or so, making notes in a Google Doc.

There is a long tail of commands, and no, you don't need all of them. But yesterday I created a macro that called a second macro, performing many complicated edits in my file in a few seconds that would have taken 10 minutes otherwise.

Was that worth it? Heck yes. It saved time, but even better, it felt awesome. The computer did my bidding.

Isn't that what programming is all about?

> making notes in a Google Doc.

Care to make that doc public? :)

The first Vim commands people learn generally fall into this set: i, i_<Esc>, gg, h, j, k, l, yy, dd, p, :w, :q. But any computer literate person should be able to operate on this level in a basic "Notepad" application. The be highly productive in Vim, I think you'll need to learn closer to 50 commands.

Now, if you think learning 50 commands is hard, think about your ability to touch type: that's at least 50 keys. Think about your programming language vocabulary. Think about your English language vocabulary. (Frankly, if I lost the ability to remember more than 10 Vim commands, re-learning Vim would be the least of my worries.)

> any computer literate person should be able to operate on this level in a basic "Notepad" application

Yes, although I will say that <n>dd, p and P when properly wielded are a nice boost in power over optimal Notepad editing, even with mastery of the system-specific modifier key selection techniques.

The thing is.. there's a really step learning curve in learning the fundamentals of vim, but once you know them, it takes a second to learn a new command.

For instance, dt' will delete characters until it matches a'. But also, dtf' will delete characters until it matches a' but also delete that '. T and F goes backward.. you can put a number in front of the command to delete until it matches the nth ', etc. It looks like a lot of command.. but it's all the same basic ideas.

So to answer your question, yes you can use vim effectively with less than 10 commands.. but once you know those 10, it's a matter of seconds to learn 100+ which would make you extremely more effective.

And as my "top" commands.. I'd say definitely:

  ciw *deleting the current word*
  cit *deleting between the current html tag*
  ci) *deleting between the ()*

  With surround plugin:
  ds' *deleting the surrounding '*
  cs'" *changing the surrounding ' for "s*
  / *incremental search*
  o/O inserting new lines.
->For instance, dt' will delete characters until it matches a'. But also, dtf' will delete characters until it matches a' but also delete that '.

dtf' should be df' in the above

ops, yes, thank you.
Worth noting: cib == ci), and ciB == ci}.

Also, "a" instead of "i" includes the enclosing markers. Not really that useful for braces and parens, but for strings da" is great. da[ is pretty great for Obj-C, too.

(a bit cheating since it's more than 10, but just 10 is not enough for even basic use)

1) Cursor movement commands (hjkl)

2) Move by word (w and b) and page (^f and ^b)

3) Search for word under cursor (forward * and backward #)

4) File commands (:w, :new)

5) Split buffer (:split) and buffer movement (^w and hjkl)

6) Tab commands (:tabnext, :tabnext etc, bound to ",tn", ",n", ",p" etc)

7) File explorer (:Explore(), bound to ,f)

8) Move to start and end of file (gg and G)

9) Switch modes (v, V for linewise, i, esc)

10) Basic register operations (dd, y, p, P)

(To write these down I had to actually open vim and do the things I described - and for some, the conscious thought I put into it prevented me from actually doing it - says something about how ingrained they become)

I prefer to think of the commands being organized conceptually, not by location. Something like this: http://fprintf.net/vimCheatSheet.html

So, if you are just starting out, learn the basic command(s) for doing each thing. Then, as you do it over and over, you'll begin to wonder how to do it easier. That's where the more advanced commands come in.

I do have printed cheat sheets that I occasionally will look at and say "oh, cool, that looks really convenient." But I'm not aiming for total mastery- just efficient use.

Absolutely. My question is always "How do I ____, again?" The most hellpful cheatsheets are the ones that showcase alias commands, alternative commands, and related commands.

Thanks for the link.

Also recommended: Mug of Vi (http://nostarch.com/mug.htm)

:)

If you are calling every single button press a command then i(insert), m(mark), %(brace match), w(save), q(quit), /(search), s/(search and replace), y(copy), p(paste), d(cut).

That covers 90% of what I do in vim. Add in R (overwrite mode), o (start a new line), !(run a command at the command line then return to the file you were editing), crtl-ws (split windows), Ctrl-ww (switch windows),Ctrl-p (auto complete), various movement keys(I really only use h,j,k,l, $,^,Ctrl-f, Ctrl-b) and you have 100% of what I know about Vi. Definitely not a power user but it gets the job done faster than any other editor I have tried.

I find just the first 10 are faster than using notepad or its replacements. Throw in a few Vim addons like a source control plugin and tags, and it becomes fairly nice.

@lhnz

I don't consider myself even a novice at vim. I know how to move the cursor in any manner that I need, I know how to globally search and replace, I use quick little commands like 'cw' all the time but don't know anything really advanced. My handwritten cheat sheet has about 15 or so commands on it and those alone have made me extremely productive in vim.

Someone posted recently about a nice, step by step, tutorial: http://news.ycombinator.com/item?id=2936670
Yup, really like that one.
Go through vimtutor (just type "vimtutor" in your shell), and you'll know the basics.

vimtutor is probably the very best introduction to vim that there is.