3 ms·
It's more about "semantic editing" than memorizing arcane keybinds. With Vim, you describe what you want to do with actions and motions. Motions move the cursor
by Cakez0r 12y ago
It's more about "semantic editing" than memorizing arcane keybinds. With Vim, you describe what you want to do with actions and motions. Motions move the cursor from a starting point to an end point and then actions do something with everything between the start and the end.
For example, if you want to delete 3 words, there is an action to delete (d) and a motion to move forward one word (w): 3dw (read (3) times, (d)elete (w)ord)
If you want to delete everything up to a closing bracket, there's a motion to move to the next occurrence of a character (t): dt)
(read (d)elete (t)o ')')
It becomes much more productive when you're thinking in terms of composing actions and motions to achieve a goal rather than memorizing situational key combos. The hardest part is getting over the hump of memorising the actions and motions.
Relative line numbers aren't even too important, given that there is a motion to jump to a line number. If you have a function that you can see starts at line 6 and ends at line 14 and I want to move it to the top of the file. You want to go to line 6 (6G), delete (d), go to line 14 (14G - thus applying the delete action to the motion of moving from line 6 to line 14) then go to line 1 (1G) and paste (P).
- jsbgir 12y ago> For example, if you want to delete 3 words, there is an action to delete (d) and a motion to move forward one word (w): 3dw (read (3) times, (d)elete (w)ord) I prefer to use d3w since it feels more like English. It's also more compatible with other combinations like ci" ('change inside quotes', e.g. to change a string), ca" ('change around quotes', e.g. to replace a string with a constant), or yt{ ('yank to brace').