News for hackers. Stuff that matters.
Re:Leap: Neovim’s Answer to the Mouse by ip26 on Saturday October 08, 2022 @03:52PM (#33135427)
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.

Re:Leap: Neovim’s Answer to the Mouse by CoolCold on Saturday October 08, 2022 @04:41PM (#33135827)
I've seen couple of persons good witn counting chars. Out of other hundreds who prefer some sort of visual mode
Re:Leap: Neovim’s Answer to the Mouse by galoisscobi on Saturday October 08, 2022 @03:59PM (#33135490)
I 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.

Re:Leap: Neovim’s Answer to the Mouse by bee_rider on Saturday October 08, 2022 @04:18PM (#33135640)
I'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.

Re:Leap: Neovim’s Answer to the Mouse by oktwtf on Saturday October 08, 2022 @06:54PM (#33136834)
Maybe 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.

Re:Leap: Neovim’s Answer to the Mouse by bee_rider on Saturday October 08, 2022 @07:27PM (#33137013)
That could work, and is nice because it is possible to do just the statusline or thereabouts. But rnu for columns would be even nicer
Re:Leap: Neovim’s Answer to the Mouse by least on Saturday October 08, 2022 @03:58PM (#33135477)
This 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.
Re:Leap: Neovim’s Answer to the Mouse by collegeburner on Saturday October 08, 2022 @04:06PM (#33135562)
idk i just got the point where i can eyeball distance and adjust a little if needed.
Re:Leap: Neovim’s Answer to the Mouse by bern4444 on Saturday October 08, 2022 @04:43PM (#33135838)
I’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.

Re:Leap: Neovim’s Answer to the Mouse by mftb on Saturday October 08, 2022 @05:04PM (#33135989)
As 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.
Re:Leap: Neovim’s Answer to the Mouse by atomicnumber3 on Saturday October 08, 2022 @05:52PM (#33136366)
Yeah 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.
Re:Leap: Neovim’s Answer to the Mouse by lovehashbrowns on Saturday October 08, 2022 @05:06PM (#33136011)
You 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.

Re:Leap: Neovim’s Answer to the Mouse by Izkata on Saturday October 08, 2022 @05:29PM (#33136190)
Others 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.
Re:Leap: Neovim’s Answer to the Mouse by minusf on Saturday October 08, 2022 @06:12PM (#33136532)
> 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 /.

Re:Leap: Neovim’s Answer to the Mouse by cassepipe on Saturday October 08, 2022 @06:22PM (#33136593)
I have to personally thank you for that one. Thank you.
Re:Leap: Neovim’s Answer to the Mouse by oktwtf on Saturday October 08, 2022 @06:47PM (#33136777)
These 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.)

Re:Leap: Neovim’s Answer to the Mouse by amelius on Saturday October 08, 2022 @08:03PM (#33137183)
And 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")

Re:Leap: Neovim’s Answer to the Mouse by oktwtf on Saturday October 08, 2022 @09:24PM (#33137525)
I never even thought to numerically increment the action!

What beautiful chords at this here fireside chat.

Re:Leap: Neovim’s Answer to the Mouse by zefhous on Sunday October 09, 2022 @12:01AM (#33138177)
There’s also the `;`, which repeats the last movement! So if you did `dft` and didn’t see the extra “t” in the way in the first place, you can then just do `d;`. It’s like `.` but for movement!

I think that’s right anyway, no vim terminal at hand to check myself.

Re:Leap: Neovim’s Answer to the Mouse by cuddlecake on Sunday October 09, 2022 @04:20AM (#33139075)
Wouldn't just `.` do the same as `d;` in that case?
Re:Leap: Neovim’s Answer to the Mouse by amelius on Sunday October 09, 2022 @11:38AM (#33142235)
Not always, the ";" sets the repetition-count of the operation to 1.

You can type "d2;" however.

Re:Leap: Neovim’s Answer to the Mouse by cuddlecake on Sunday October 09, 2022 @03:02PM (#33144192)
Good to know, thank you
Re:Leap: Neovim’s Answer to the Mouse by oktwtf on Sunday October 09, 2022 @03:18PM (#33144322)
Oh great, I’ll finally have to remove my remap of ‘; = :’ never did I investigate to know what I was opting out of.
Re:Leap: Neovim’s Answer to the Mouse by paledot on Tuesday October 11, 2022 @09:41PM (#33171706)
Not worth it. That remap has saved me more keystrokes than I can reasonably count. But adding the opposite remap for good measure isn't the worst idea.
Re:Leap: Neovim’s Answer to the Mouse by nyx on Saturday October 08, 2022 @10:00PM (#33137700)
I think of the t motion as "to", and the f motion as "frough" (rhymes with through: "delete frough the second t").
Re:Leap: Neovim’s Answer to the Mouse by bch on Saturday October 08, 2022 @10:37PM (#33137835)
Beautiful - the ways I’ve never considered composing…
Re:Leap: Neovim’s Answer to the Mouse by wyager on Saturday October 08, 2022 @07:23PM (#33136990)
How does dtt differ from dft?
Re:Leap: Neovim’s Answer to the Mouse by aGHz on Saturday October 08, 2022 @07:27PM (#33137015)
dtt will stop just before the first t character, dft will delete the t as well.
Re:Leap: Neovim’s Answer to the Mouse by kevincox on Saturday October 08, 2022 @11:20PM (#33137998)
In the case of dtt you can also often repeat it with . if you have a "false positive" before the intended character rather than counting occurances. Not for c but for d if you don't need the yanked text and regular movement.
Re:Leap: Neovim’s Answer to the Mouse by u801e on Saturday October 08, 2022 @07:29PM (#33137019)
Another approach is to use normal mode to delete a block of text you want. For instance, if you want to delete up to the line before the line that contains "This is a line of text", you could run

    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.
Re:Leap: Neovim’s Answer to the Mouse by koprulusector on Saturday October 08, 2022 @11:06PM (#33137942)
Never knew about the - or _ as flags for the search regex. This is awesome!
Re:Leap: Neovim’s Answer to the Mouse by u801e on Sunday October 09, 2022 @12:32AM (#33138287)
It's not actually a flag to the s command. It's a way to modify the address. So, for instance, if you want to delete from the third line to the third to last line in the file, you could run:

    :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.
Re:Leap: Neovim’s Answer to the Mouse by shepherdjerred on Saturday October 08, 2022 @10:40PM (#33137849)
> d/text<enter>

You've changed my life

Re:Leap: Neovim’s Answer to the Mouse by zamalek on Saturday October 08, 2022 @05:30PM (#33136203)
You 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.
Re:Leap: Neovim’s Answer to the Mouse by cassepipe on Saturday October 08, 2022 @06:25PM (#33136622)
Or 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)
Re:Leap: Neovim’s Answer to the Mouse by oktwtf on Saturday October 08, 2022 @06:56PM (#33136847)
Helix 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!
Re:Leap: Neovim’s Answer to the Mouse by bjeanes on Saturday October 08, 2022 @07:31PM (#33137036)
Helix too, it seems, though I haven't used either for more than 10 minutes each.
Re:Leap: Neovim’s Answer to the Mouse by alwillis on Sunday October 09, 2022 @02:44AM (#33138752)
Neovim has a plug-in for that: https://github.com/smjonas/live-command.nvim
Re:Leap: Neovim’s Answer to the Mouse by srik on Saturday October 08, 2022 @06:36PM (#33136690)
I NEVER use count, because my mental flow is drastically hindered by pausing for any form of counting in midst of editing; I stay off relative numbers even. In their place, I enable a vast number of text objects instead, quite a few implemented through the `kana/textobj-user plugin`. Good text object serve as a better embodiment of intent and thus map better mentally than any method using brute counting. It does come at the loss of some precision and speed, but it's a small sacrifice for QOL.

[1] https://github.com/kana/vim-textobj-user

[2] https://github.com/kana/vim-textobj-user/wiki

Re:Leap: Neovim’s Answer to the Mouse by schoen on Saturday October 08, 2022 @06:52PM (#33136817)
You 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).

Re:Leap: Neovim’s Answer to the Mouse by drbojingle on Saturday October 08, 2022 @07:47PM (#33137109)
Thats more for macros than anything else imo.
Re:Leap: Neovim’s Answer to the Mouse by gnubison on Saturday October 08, 2022 @08:32PM (#33137331)
> 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.

Re:Leap: Neovim’s Answer to the Mouse by spiffytech on Saturday October 08, 2022 @08:44PM (#33137383)
I don't count, I (under)estimate. "Eh, that looks like about 5 words", then I mash keys the rest of the way.
Re:Leap: Neovim’s Answer to the Mouse by koprulusector on Saturday October 08, 2022 @11:04PM (#33137931)
It’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.

Re:Leap: Neovim’s Answer to the Mouse by jasonm23 on Sunday October 09, 2022 @02:32AM (#33138717)
> 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.

Re:Leap: Neovim’s Answer to the Mouse by vidyesh on Sunday October 09, 2022 @02:55AM (#33138791)
I 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

Re:Leap: Neovim’s Answer to the Mouse by dkersten on Sunday October 09, 2022 @03:16AM (#33138859)
There 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.
Re:Leap: Neovim’s Answer to the Mouse by WhyNotHugo on Sunday October 09, 2022 @04:13AM (#33139051)
Practice 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).