Counting characters is even worse. It takes me a good second and a half to confirm that “characters” is ten characters.
Counting characters is even worse. It takes me a good second and a half to confirm that “characters” is ten characters.
This is a line of text.
If the cursor is on "is" and you want to delete everything before "text", this is what I do: d/text<enter>
Any movement works for these actions, even searching to "select" everything between the cursor and the target. Often I'll use visual mode to get a quick confirmation before deleting it: v/text<enter>h
(check selection is what I want)
d
The visual mode one isn't exactly the same because one additional character, the first "t" in "text", is in the visual selection area, hence the "h" to go back one.if you have a unique letter, as in this case ("t"), a quicker way is "dtt" (delete till "t") or "ctt" (change till "t"). in case of non unique character it takes a count but that scales badly for me, and i use /.
Also I like to use "f" for find followed by the character you wish to move cursor to the character you desire to end up on the present line. (ex. "fl" jumps to the first "l" of the line.)
(I personally think of "f" as "find", not "first")
What beautiful chords at this here fireside chat.
I think that’s right anyway, no vim terminal at hand to check myself.
You can type "d2;" however.
q:
.,/This is a line of text/- d
. is the current line. /This is a line of text/ is the line that contains it and the - after the regex refers to the line immediately above. You could use _ to refer to the line immediately after, or -x or +x where x refers to the number of lines above or below the line that the regex matched. :1+2,$-2 d
1 is the address of the first line in the file and $ is the address of the last line in the file. Add 2 to the first to get the third line and subtract 2 from the last to get the third to last line. The d command deletes the lines in the address range.You can also address lines with a regex, like I did in the example in my previous comment. You can even use regex addressing for ranges. If you wanted to delete a python method definition in between other method definitions, you could do something like:
:/def method_to_delete/,/def/- d
which would start the range with the line that contains def method_to_delete and delete lines up to the line before the next line that contains the def keyword that starts the next method definition.You've changed my life
Primeagen has a good video about horizontal motions: https://www.youtube.com/watch?v=qZO9A5F6BZs.
No one actually counts :) For vertical motions, I use {/} and search; horizontal motions can use w/W/b/B/e/E, t/f/T/F as well. If you’re counting, you’re doing it wrong: big numbers can’t be recognized quickly, small numbers it’s faster to press ‘.’ than to hit the digit.
Similarly for lines. 4dd, ., ., ., and so on.
Of course, this only makes sense for deletion, not for changing or for movement (because the . to repeat a command is commonly not what you intended for changes and doesn't apply at all to pure movement actions).
This is just an example. Anyway,
To delete from the cursor at T to just before the A in Anyway without counting words.
Contrived example because there’s an even easier method. There are fun ways to do things and it’s satisfying when you figure out a neat method.
I end up doing stuff like dt( to delete up until the opening parenthesis or ci’ to to delete inside quotes.
Otherwise as you said I’ll spam the keys till I’m at the point where I want.
:exec &rnu? "set nu nornu" : "set nonu rnu"
I wish there were vertical line numbers, though. Usually I just eyeball letter jumps (so rather than 7l I'll end up doing 10lhhh).
In practice, I can't say I've ever felt like moving the cursor around takes up an appreciable amount of time. If it does, then it is probably the case that I'm trying to do something manually that would be better macro-ized.
`:set cc=10,20,30,40,50,60,70,80,90`
Might have to change your highlights/colours so it's a bit more subtly, likely theme dependent.
Usually, I'll get it right if it's under 30 characters, and will be off by one or two if it's between 30 and 50.
For normal code though, counting words is way quicker (e.g.: 7cw).
When it comes to rows, `relanumbers` helps a lot, there's no going back.
For larger chunks of text, things like `cif` (change inside function) and `co{` (change outside brackets) help a lot. Again, practice and keeping them in mind.
Also, every time threads like this appear on HN, I learn new stuff. Like, somebody mentioned using `c/X` (change, search, X). Gonna try that next time I need to replace all text leading to X (which is pretty common).
A lot of times I find a landmark on the line I’m working, for example, I see there’s a word with a “C”. Then, say I want to delete everything to that “C” I’ll do dtC. Or I want to delete everything in quotes on the line, I’ll do di”. Or I’ll pick a character, say “ “ (as in a blank space), and do 3f<space>, and if I need to jump more from there I’ll just just comma a couple times if I need.
I will, however, use 30j or 3J to operate across lines, since I have both absolute and relative line numbers turned on. But solely for movement I’m more likely to use HML to initially jump somewhere more than 5 lines, then do something like 4k or 2j to jump the rest of the way.
And generally if I know where I want to go, I would just search with / instead of doing jjjjjjjjj
But you can with a little practice then it becomes normal.
For lines it's easiest, and relative line numbers makes it even easier.
But you can take off the training wheels if you just aim to be proficient after a solid day of practice.