News for hackers. Stuff that matters.
Re:I don't need your query language by danielheath on Saturday June 17, 2023 @07:20AM (#36369205)
This is also my primary issue with vi.

d3w (`d`elete `3 w`ords) cannot be highlighted / indicated in any way ahead of time. If the motion specifier came first, it could be.

Re:I don't need your query language by Olreich on Saturday June 17, 2023 @07:34AM (#36369304)
`3w` is a command all its own. There’s an implicit move command baked in. Moving gets pretty clunky if you don’t have first order movement (adding a specifier or something to clear selection). You can mimic this by mapping a single button to <C-v> and disabling all movement commands in normal mode. It’s rough, but may be learnable.

I think something that might work better is adding a “commit” signal to operations. So you type `d3w` and the editor highlights the next three words with a strike through or red or whatnot. Then you can hit enter to commit the delete or escape to cancel it (cursor resets to start position, highlight goes away).

Re:I don't need your query language by wryanzimmerman on Saturday June 17, 2023 @08:04AM (#36369499)
If you use visual mode, you can do `v3w` to highlight three words, and then you can manipulate that selection before you do something with it, like `d` for delete.

You can also use that with ex commands, like if you do `vap:s/foo/bar/g` you will replace `foo` with `bar` only within the block of code you visually highlighted with `ap` (which I remember as “a paragraph).

So if you want “delete three words”, do `d3w`. If you want “highlight three words” do `v3w` and then issue another command like `d` to do something with what you highlighted.

Re:I don't need your query language by PhilipRoman on Saturday June 17, 2023 @08:07AM (#36369520)
I think these two concepts could be reconciled by having selection be combined with moving. So 3w could select three words but also move the cursor to the end of selection, ready to process another normal mode command. The highlighting would need to be scaled back a little (perhaps a dark gray background), as you don't want your entire screen to light up when moving but I think it's doable.
Re:I don't need your query language by SaidinWoT on Saturday June 17, 2023 @09:17AM (#36369935)
That's exactly the model used by the Kakoune editor[0]. It definitely feels more intuitive to me, but I personally didn't stick with it due to vim's ubiquity.

[0] https://kakoune.org

Re:I don't need your query language by Kamq on Saturday June 17, 2023 @11:44AM (#36371202)
> So 3w could select three words but also move the cursor to the end of selection

I mean, if you hit v first, that's exactly what it does.

Re:I don't need your query language by PhilipRoman on Saturday June 17, 2023 @03:14PM (#36373510)
Yes, but in terms of editing speed and comfort, one keystroke is the difference between life and death. As long as the motion can be described in a single command, visual mode is overkill.
Re:I don't need your query language by Kamq on Sunday June 18, 2023 @03:55AM (#36378189)
Wouldn't what you're proposing complicate the rest of normal mode though?

Or is this just reversing the order so it's {motion}{verb} instead of {verb}{motion}?

Re:I don't need your query language by xyzzy_plugh on Saturday June 17, 2023 @07:25AM (#36369243)
v3wd?
Re:I don't need your query language by wryanzimmerman on Saturday June 17, 2023 @07:58AM (#36369461)
If you want to highlight something, use `v` for "visual" mode
Re:I don't need your query language by Fissionary on Saturday June 17, 2023 @09:28AM (#36370000)
You might like kakoune (https://github.com/mawww/kakoune), which does exactly that: first you select the range (which can even be disjoint, e.g. all words matching a regex), then you operate on it. By default, the selected range is the character under cursor, and multiple cursors work out of the box.

It's also generally lean and follows the Unix philosophy, e.g. by using shell script, pipes, and built-in Unix utilities to do complex operations, rather than inventing a new language (vimscript) for it.

(Not affiliated with the creator, but kakoune has been my daily driver for years now.)

Re:I don't need your query language by kwkelly on Saturday June 17, 2023 @10:56AM (#36370726)
Helix[1] is another editor which heavily borrows from kakoune’s “selection then action” paradigm. The editor is very good, but still in heavy development, so it lacks plugins and has the occasional rough edge. [1] https://helix-editor.com
Re:I don't need your query language by mmh0000 on Saturday June 17, 2023 @12:15PM (#36371541)
I know you specifically mentioned 'vi', but I'm going to blindly assume you meant 'vim'. In which case, as others already pointed out, you can use visual model to get exactly that behavior.

A good mindset to have in regards to Vim is, "Vim can do anything, even make you coffee". The trick with Vim is actually figuring out /how/ to do it.

I highly recommend you start with the VimCasts[1] video series. They're short, 5 minute, videos. With each covering a specific functionality of Vim. They straight to the point, and the author provides samples code for all videos.

[1] http://vimcasts.org/episodes/page/8/