In vim, most commands take the form "[count] operator [count] motion". When you learn a new operator, you can use it with any motion that you know and vice versa; and you can add a count to either. To give a few examples:
- gqip to format (gq) a paragraph (ip).
- g?g? to ROT13 a line (doubling the operator makes it operate on the current line — in this case, g?? also works).
- y2w to copy (y) the next two words (2w) — this requires you to be at the start of the word, but you could use y2aw if you were in the middle of a word.
- dj to delete (d) two lines (j); see ":h linewise".
- dt. to delete (d) until a period (t.), not including the period.
- y% to copy (y) until the matching parentheses (%). If you aren't already on one, vim searches until a "(", which means that you can use this to copy a C-like function call.
Additionally, a subset of these operators and motions are available in plain vi, which is available on any POSIX system (Linux, macOS, *BSD, ...)
It should be possible to do this with a "regular" type of editor, where you have a keyboard shortcut to, for instance, select to the matching parentheses; there just aren't any editors (that I know of) with the same range of motions and operators as vim.
Not moving to the arrow keys or using ctrl-, alt- far outweighs the cost of switching between insert and normal mode.
I appreciate the tutorial, but I probably do already "know" vim, but it's not part of my muscle-memory. Context switching to something like writing an email or filling out a web form really makes it not worth getting too comfortable with all these esoteric shortcuts. Do you write all of your emails in vim and browse the web on the command line as well?
From reading the rest of the replies, it sounds like the real answer is "because it's everywhere", which isn't really satisfying. I don't work on lots of machines that aren't my own (embedded/mobile space, which don't have vi installed!), so I don't actually encounter it everyday despite living on the command line.
Sorry — I never know when to assume a large amount of knowledge or a small amount of knowledge. The worst for me is "ctrl-w" to delete a word backward in Insert mode, and to delete a tab in the web browser :) Vim is in my muscle memory and it's faster for me, so that's why I use it. It might be faster for you and it might not be faster for you, and if you don't need the portability for POSIX machines it's probably not worth the time.
CTRL+W messes me up sometimes. when i'm in split screen mode with two panes i'll often tap CTRL+W twice to switch panes. very confusing when you forget to exit insert mode.
> Do you write all of your emails in vim and browse the web on the command line as well?
Yes! I use mutt + vim. Composing emails in a textarea is a terrible experience by comparison. (Respect to emacs mail mode users, that’s a great option too.)
I also use w3m for browsing technical stuff, and use tmux for copy & paste into vim.
Playing around with this, [count]iw seems to have some really strange behavior — I need to do 3iw to select two words, 5iw to select three words, etc.? I'm not sure if I'm missing something. (I normally don't use many text objects; bdw is in my muscle memory instead of daw, for example.)
- gqip to format (gq) a paragraph (ip).
- g?g? to ROT13 a line (doubling the operator makes it operate on the current line — in this case, g?? also works).
- y2w to copy (y) the next two words (2w) — this requires you to be at the start of the word, but you could use y2aw if you were in the middle of a word.
- dj to delete (d) two lines (j); see ":h linewise".
- dt. to delete (d) until a period (t.), not including the period.
- y% to copy (y) until the matching parentheses (%). If you aren't already on one, vim searches until a "(", which means that you can use this to copy a C-like function call.
Additionally, a subset of these operators and motions are available in plain vi, which is available on any POSIX system (Linux, macOS, *BSD, ...)
It should be possible to do this with a "regular" type of editor, where you have a keyboard shortcut to, for instance, select to the matching parentheses; there just aren't any editors (that I know of) with the same range of motions and operators as vim.
Not moving to the arrow keys or using ctrl-, alt- far outweighs the cost of switching between insert and normal mode.