4 ms·
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'
by mononcqc 14y ago
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.