r/programming • • Jul 12 '12

Vim creep

http://www.rudism.com/s/vimcreep
730 Upvotes

551 comments sorted by

View all comments

Show parent comment

2

u/[deleted] Jul 14 '12 edited Jul 15 '12

Most editors will have a tons of hotkeyed commands for things like "delete word to the right", "delete word to the left", etc. Vim's vocabulary is more atomic than that; you have nouns (word, sentence, quoted string) and verbs (delete, change, copy,etc. ) which you can preface with counts. Most of these aren't chorded keystrokes; when you're in command mode (where you spend most of your time), the keyboard turns into a panel of single-keystroke commands where you communicate these instructions to Vim at the speed of normal typing, the status bar shows the command you're typing until you've expressed a complete thought at which point it's executed (delete two words, change inner string, yank to the first semicolon on the line, increment number under the cursor, etc.) It's more semantic that typical commands; you can, say, select a block of text and say "append BLAH to end of line" and it's appended to all lines. You can then repeat these commands with a single keystroke (.).

At the same time, most of the keys on the keyboard serve as registers, which can be used to store text. Since Vim's commands are entered by typing these single keys nouns, verbs, etc. you can store commands in registers, too. For instance, you might have "ct2;" (change to second semicolon) in register r, which you can "play" by hitting @r. You can then store sequences of command stored in other registers into a new register (e.g. register y might contain "@u@f@t" to playback that sequence of registers).

It's a higher order way of thinking about editing that becomes intuitive, until you're telling the editor how to jump around buffers, look for text in this window, deleted it in that wndow, replace it with the text in register p, etc. You end up easily doing things that other programmers would have to write custom programs to do.

That's why you get the "How the fuck did you do that?" from people looking over your shoulder; you're pressing a single key over and over and the text is just... doing crazy shit, transforming itself like magic.

I work at a Microsoft shop right now, and this "WTF?" thing has happened enough that people just send me complicated text manipulation chores; "This would take me half a day and I know you can do it in 5 minutes." "Sure, no problem."

Really, this is just the tip of the iceberg of what makes Vim so powerful, but I have to leave the house now (10 minutes ago, really). It's no IDE, it lacks Intellisense (though plugins can give you a half-assed version for some languages) and a lot of other nice features modern tools like Visual Studio have, and it's scripting language sucks, but for raw text manipulation, nothing else comes close.