7 ms·
I’ve always wondered, how does anyone rapidly compose vi movements like your example? Or d7w, or c9j… I can’t count seven words or nine lines as fast as I can
by ip26 4y ago
I’ve always wondered, how does anyone rapidly compose vi movements like your example? Or d7w, or c9j… I can’t count seven words or nine lines as fast as I can just tap vwwwwwwwd or shift-vjjjjjjjjjc, because in the latter case I only have to pick out whether the cursor has reached the target, allowing me to blast out four w, then three, then two, with increasing precision as I converge.
Counting characters is even worse. It takes me a good second and a half to confirm that “characters” is ten characters.
- jasonm23 4y ago> I can’t count seven words or nine lines as fast as I can just tap vwwwwwwwd 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.
- vidyesh 4y agoI use hop[1] to jump horizontally. Hop can also be used with any other commands like v, d, c, y etc. And generally if I know where I want to go, I would just search with / instead of doing jjjjjjjjj [1] https://github.com/phaazon/hop.nvim https://github.com/phaazon/hop.nvim
- dkersten 4y agoThere was a point of time when I was a pretty efficient vi user, not anymore though. However when I was, I found that in time, with practice, I got very good at estimating how many characters, words and lines things were. So it’s just practice, after a while you can judge how far you need to go without having to count or think about it.
- WhyNotHugo 4y agoPractice really. I occasionally still get something like 31cl wrong, but just undo and do it right (e.g.: 33cl). Note that, by being off by just 2 or 3 characters, I can quickly ~~recount~~ add. 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).
- least 4y agoThis is what relative line numbers are useful for. Not so useful for a delete word action, though. If I'm deleting a set of words though that's when something like leap, sneak, etc. can be useful, since it's a bit more descriptive than the t, T, f, and F motions, which will only go to the next instance of that character. You could do something like d/term<CR> to delete to a search term, though.
- galoisscobi 4y agoI use relative line numbers to go to the line I'm interested in, then use f to jump to a char, and comma to jump to the next matching char, or if I want to go inside a paren (say inside {}), I'll do vi{<Esc>. I also generously use f or F to go back and forth, or just '/' to search a few chars for where I want to jump. Primeagen has a good video about horizontal motions: https://www.youtube.com/watch?v=qZO9A5F6BZs https://www.youtube.com/watch?v=qZO9A5F6BZs.
- deleted 4y ago[deleted]
- collegeburner 4y agoidk i just got the point where i can eyeball distance and adjust a little if needed.
- bee_rider 4y agoI've mapped a convenient key to :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.
- oktwtf 4y agoMaybe you could apply several `colorcolumn` markers, possibly every 10 characters to aid in parsing the verticality? `: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.
- bee_rider 4y agoThat could work, and is nice because it is possible to do just the statusline or thereabouts. But rnu for columns would be even nicer
- CoolCold 4y agoI've seen couple of persons good witn counting chars. Out of other hundreds who prefer some sort of visual mode
- bern4444 4y agoI’m with you on the words or character part. As others have said for line numbers using relative numbers makes it easy. 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.
- mftb 4y agoAs others have said I use relative line numbers to prevent counting vertically. Within a line, I use "f" constantly. Using your last example, say I needed to get to the word "characters" and change it, I would, "fc" and "cw". In the case where there just happened to be multiple "c" on that line, I would "fh" and "ciw". I don't like counting either.
- atomicnumber3 4y agoYeah same, t T f and F are by far the most common things I do for both navigating and deleting/copying. But I also mostly only use vim as my "backup editor". For those scenarios where you only have a magnetized needle, a steady hand, and SSH.
- lovehashbrowns 4y agoYou get easier at doing the math in your head as you practice more. There’s also lots of methods you can use to skip counting altogether. Like using search. d/“ will delete everything between the cursor and the first “ vim finds, for example. Double quotes are easy, though. :) you can do fun stuff like d/x then dW in this case: 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.
- Izkata 4y agoOthers have mentioned relativenumber, but for horizontal I just use search. For example: 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.
- minusf 4y ago> d/text<enter> 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 /.
- deleted 4y ago[deleted]
- cassepipe 4y agoI have to personally thank you for that one. Thank you.
- oktwtf 4y agoThese discussions are always a gold mine of tips.! 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.)
- amelius 4y agoAnd you can also type d2ft to delete everything up to and including the second t, for example. (I personally think of "f" as "find", not "first")
- 4y ago
- zamalek 4y agoYou use Kakoune instead. It selects before an action, allowing you to preview whatever you're doing. So you can 10W as an estimate and then, say, 2BD.
- alwillis 4y agoNeovim has a plug-in for that: https://github.com/smjonas/live-command.nvim https://github.com/smjonas/live-command.nvim
- cassepipe 4y agoOr Helix if you like shiny new things and you can't resist the "written in rust" hype. (I'm joking, it has other benefits over Kakoune, which is already great and more polished right now)
- oktwtf 4y agoHelix is very nice! I do like snagging the hx bin and getting to work, no need to mess with LSP config till it's working right!
- bjeanes 4y agoHelix too, it seems, though I haven't used either for more than 10 minutes each.
- deleted 4y ago[deleted]
- schoen 4y agoYou could start with something you're sure is too low and then use . to repeat the command. Like d3w and then press . repeatedly until you get close enough that it's one word (dw) or you can see exactly how many it is. 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).
- drbojingle 4y agoThats more for macros than anything else imo.
- gnubison 4y ago> Or d7w, or c9j… I can’t count seven words or nine lines as fast as I can just tap vwwwwwwwd or shift-vjjjjjjjjjc, because in the latter case I only have to pick out whether the cursor has reached the target, allowing me to blast out four w, then three, then two, with increasing precision as I converge. 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.
- spiffytech 4y agoI don't count, I (under)estimate. "Eh, that looks like about 5 words", then I mash keys the rest of the way.
- koprulusector 4y agoIt’s less common for me to use numbers with motions on a single line. 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.