martanne / vis

A vi-like editor based on Plan 9's structural regular expressions
Other
4.26k stars 259 forks source link

C-n: Select new word, not working on [=+-&] #864

Closed ddkn closed 4 years ago

ddkn commented 4 years ago

Hello,

So I got inspired to use more of the features in Vis, after watching this, for some heavy LaTeX edits. I have a set of equations that I wanted to select certain "=" signs, and append an "&", such that, I would get "&=".

However, it ends up selecting the surrounding space, and the first character on the right, and I cannot use C-n or C-x to select or skip. This works in other cases with letters or a word, but not [+-=&].

Am I missing something? Or is this a known problem? I attached some images to help clairify,

Selecting the "=" on the top right, image

Using C-n, image

It is a feature I really like, but a little frustrating it isn't consistent. I tried using the cursors to unselect the space or C-_ then followed by C-n but no luck. Hopefully someone has some insight to this.

Cheers,

ninewise commented 4 years ago

I've come to understand that C-n only works on words (so \w characters). This specific case I'd solve using

If you only want some of these = signs, you'd have to find a better selection criteria, or C-k and C-j to focus some of the selects after step 2 and remove them with C-p.

ddkn commented 4 years ago

Yes doing a visual selection, then using C-[jk] to move and unselect searches, solves my problem! The problem is I want to interactively select thing because there is a lot going on in my equations. I find doing this nice and visual reassuring in what I am doing. It isn't as convenient as the other case, or it is less intuitive I guess, a bit of more thinking on the user end.

Maybe the wording of the count/cursor throws me off a bit.

It would be nice to have an arbitrary selection then use shortcuts to to skip or include, forwards or backwards, rather than just limited to just words. Maybe <C-M-n> one day, haha.

ninewise commented 4 years ago

Come to think of it, there's another way of doing this.

  1. Go to your first selection and make it (with v or however),
  2. m to save the selection,
  3. <Esc> to go back to normal mode,
  4. Navigate to make the next selection,
  5. | (selection union) to join the previous with this one.

Repeat steps 2 to 5 as much as required, possibly with multiple selections made each time.

ddkn commented 4 years ago

Haha, that does work but is much more cumbersome key press wise than your other suggestion which worked well today!

It is neat how there are many ways to string things together.

Thanks again for the help!

martanne commented 4 years ago

Hi, the problem is that viw in normal mode (which is what C-n essentially is, in fact it should probably be implemented by that mapping) does not behave properly.

Once you have the initial selection, C-n in visual mode should work as expected.

ddkn commented 4 years ago

Hi @martanne,

So if I understand correctly, if I make a selection in visual mode then hit C-n, it should select matching patterns? I tried that in a LaTeX table, trying to match 00 and & I included a video of me hitting C-n about 10 times for each case. For 00 it only caught 2 of the 4 occurrences in view, but didn't catch any &.

fails

I tried the & in multiple locations as well.

For reference I am using v0.6. So maybe I misunderstood what you said, or my version is having issues.

PS. I really enjoy using this editor, even using the above features to circumvent the issue is immensely helpful, and makes it feel more intuitive to work with and faster. I am transcribing written lectures in physics to LaTeX for a professor before classes start in September (currently at 223 out of 250~ish pages in about a week). So the features help a lot with copy pasting equations that are messy to retype out, the rotation of selections features are helpful to quickly move equations around, since LaTeX can get a bit unwieldy with long equations and bracket hell.

I really appreciate the work you have done!

martanne commented 4 years ago

Thanks, glad you like it.

The issue you reported initially (C-n on a single symbol) should hopefully be fixed by the latest commits?

The current logic for C-n in visual mode is as follows: if the existing selection is a word, then match complete words only. Otherwise also select partial matches.

I will later have to investigate further why it doesn't match all occurrences of 00 in your case.

ddkn commented 4 years ago

Oh, okay awesome! I will take a look after once I compile it, as I am 3 lectures from finishing today. But still have many other papers and a thesis to write at some point, haha. As of now, the process from above seems to work, with selecting all then unselecting the one ones I don't want.

erf commented 4 years ago

I noticed if i visually selected "Vis*" or "require(" i was unable to use C-n to select the next occurance.

EDIT: fixed now!