Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Absolutely not true. The best description for VIM is "programming your text". In VIM you have a set of commands that you use to manipulate text. Generally commands looks like nOm where n is number of times to repeat the whole thing, O is operator to apply, m is motion command/selection. So for example 3dw applies 3 times the d (delete) operator to motion command w move one word forward, i.e. delete next 3 words. The nice thing is if you learn lots of motion commands you instantly learn lots of ways to manipulate text objects based on those motions. Want to change inner if block in your code? Just type ci{ (change inner { which deletes everything inside the {} block the cursor is in and places you in insert mode. Etc.

In other editor you have keyboard shortcuts and there are only so many you can have. In VIM there are over 1500 commands (not shortcuts). People who say "vi key bindings" or "vi shortcuts" don't get vim.



My favorite form of this is when using regular expressions.

You have 'v' for visual mode, where you move the cursor around and can select stuff.

You have 'd' to delete things.

If I press 'v' then move around, then press 'd', I'll delete the selection.

If I press 'vf,' it means 'select until you are on a comma'. If I press 'df,' it means 'delete until you are on a comma'.

The problem with these two modes is that they're restricted to one line.

Now if I do 'v/,$', it means 'select until the first match of the regular expression ',$' (comma on end of line). If that comma is 5 lines below, it'll find it.

What's fun is that with this sublanguage, I can say 'dv/,$' and it will delete where the selection of the next comma at the end of a line, or more generally, <Command>v/<Regex> will do the command until a given regex. If I replace 'd' with 'c', it deletes and puts me in insert mode ('c' is change), and so on.

Even nicer? what if I'm writing Erlang (I usually am), and I want to delete, say 3 functions. I could delete one by getting to the beginning of the function and delete until '\.\n' as a regex (functions are terminated by a full stop). So the command becomes 'dv/\.\n' for a single function.

Rather than calling the same command 3 times, I can do it once, then press '.' twice to repeat the previous ones.

Or I can use the fact that vim has this sublanguage and instead call '3dv/\.\n', which will delete until the next end of a function (full stop + line break) 3 times.

Its command set is fully composable and at some point you find your sweet spot in there.


That is an awesome tip! One question: is there any reason why you do 'dv/,$' rather than just 'd/,$'?


They both work absolutely fine. I tend to use d/<regex>, but the dv/<regex> example highlights the sublanguage and composition a bit more :)


Genuine question: Couldn't this be accomplished by any scriptable editor?


Yes, it's true that it can be done in any sufficiently good scriptable editor. But once you have written all those scripts to do all those magic, your editor will look more like vim.

You have just built your own Vim.


Oh. Well that makes a lot of sense. I feel like I understand Vim a ton better now.


I will grant that "vi shortcuts" is strange, but "vi key bindings"? The operators/motions (or verb/noun) perspective is vital, but those operators and motions are not intrinsic properties of the keys they happen to be mapped to - indeed, you can remap them. The initial mapping is a totally valid question, particularly for lesser-used commands, and one that can quite reasonably be referred to by the phrase "vi key bindings".




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: