4 ms·
You need to start by learning all of the various operators and movement commands for Normal mode. Memorize as many as you can and try to think about where you w
by bobbyi 16y ago
You need to start by learning all of the various operators and movement commands for Normal mode. Memorize as many as you can and try to think about where you would use them.
As you edit, force yourself to notice the situations where an operator/ movement command exists that is slightly more efficient than your usual way of doing things. For example, recognize opportunities to use the c and s operators instead of a delete operation followed by an insert and to use f and t to jump to a specific character rather than holding l.
At first this will be much less efficient than just doing things in the obvious way. Keep pushing and memorizing more movement commands and operators until you know what every key does without thinking about it. Use visual mode when necessary to verify what text a command will operate on.
Then get good at combining the operators with movements and repeating them by using the . operator and by prefixing them with numbers. Also, start remapping things aggressively to make vim work the way you think it should. If there is a key whose default action you don't find that useful (e.g., Enter, Backspace, Space, Tab and the arrow keys), have it do something that justifies its place on the keyboard.
Only at that point, start really drilling into the ex commands and (ugh) vimscript.
You should also figure out how to use/ add auto-completion, version control integration, project management, diff mode, build support, ctags, etc., but that is mostly orthogonal to learning how to use vim as an editor.
- csmeder 16y agoMemorize as many as you can and try to think about where you would use them. As you edit, force yourself to notice the situations where an operator/ movement command exists that is slightly more efficient than your usual way of doing things.... At first this will be much less efficient than just doing things in the obvious way. Keep pushing and memorizing more movement commands and operators until you know what every key does without thinking about it. Great Advice
- bobbyi 16y agoWhat's not obvious at first about vim is that its power (somewhat like unix) comes from orthogonality. Since you can combine any operator with any movement command, the number of commands that you know is the product of the number of operators and the number of movements.
- edanm 16y agoThis really hits home for me. After learning Emacs, which derives its awesomeness from the amazingly large set of stuff it knows how to do, I found vim to be good for other reasons. Vim is good because with very, very few commands, you can do things much quicker. The "f" or "t" commands, combined with the fact that you can use "c", are just amazing. Same with the "i" (inner) command. Those few commands alone can make editing any line faster and funner.
- samstokes 16y agoSame with the "i" (inner) command. (Technically it's a motion, not a command. "i" as a command just enters insert mode.) To elaborate, since this is one of my favourite vim features, say you have the following code: do_something_with(some + long * complicated * expression) ^ Say your cursor is where the caret indicates. Typing 'ci)' ("change inside parens") in normal mode will: * delete all the text between the two matching parens * place you in insert mode with the cursor between the two (now adjacent) parens * put the deleted text in the yank buffer so that 'p' will paste it. The use case here is obviously so you can assign a name to that long complicated expression. 'ci)' is much easier than selecting it with the mouse, and keeps your hands on the keyboard where they belong ;) With nested parentheses, it does what you expect (affects the text contained by the innermost matching pair to contain your cursor - try it and see). Other equally useful variants: * i" - "inside double quotes" - everything between double quotes * i' - "inside single quotes" * iw - "inside word" - the word the cursor is on * is - "inside sentence" - great for editing prose * ip - "inside paragraph" There are also similar motions beginning with "a": * a) - like i) but includes the parens (e.g. 'da)' deletes everything inside parens and the parens themselves) * a" - similarly * aw - like iw but includes trailing whitespace. (Update - I thought this deserved its own air, so I turned it into a blog post: http://blog.samstokes.co.uk/post/767636740/vim-wizardry-1 http://blog.samstokes.co.uk/post/767636740/vim-wizardry-1 Bonus tip if you read to the end!)
- deleted 16y ago[deleted]
- deleted 16y ago