martanne / vis

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

{ moves back a paragraph too much if cursor at start of line #1028

Closed ghost closed 1 year ago

ghost commented 2 years ago

Given the text:

First paragraph.

Another paragraph.

if cursor is on n of another, using { will bring me to the blank line between the two paragraphs, as expected. But if the cursor is on A of another, I'm brought to First: I'd expect to be brought at the blank line (this is the behavior in vim, and makes more sense/is more useful).

ninewise commented 2 years ago

That would indeed make more sense. A patch to fix this would be welcome, or I'll have a look at it myself later.

ghost commented 2 years ago

thanks. I'd like to give it a try myself, will report back.

ghost commented 2 years ago

the bug was introduced in f55312ba. I found that it also appears when using } if you are at EOL.

Reverting the commit fixes the issue completely (with the exception of } when cursor is on the virtual EOL), and doesn't seem to have side-effects.

The rationale for the commit was "ignoring blank lines". I'm not sure what it means: I tried on a test file with several blank lines in a row and the behavior is the same with the commit applied or reverted.

casr commented 2 years ago

I tried on a test file with several blank lines in a row and the behavior is the same with the commit applied or reverted.

What happens when you have a line that only has spaces, tabs or a combination of both between the paragraphs?

ghost commented 2 years ago

@casr

In a situation like this:

First

  <some whitespace>

Second

with the patch reverted:

if the cursor is on S, { moves at the start of line 4, then the start of line 2. IMHO this is correct (it's also how it works in vim).

jvvv commented 2 years ago

Rather than reverting the whole commit for f55312ba, I have tested a partial revert in bde0a89. My intent with this change is that I think it maintains the point of the original commit while also trying to address this issue.

Edit: I have rebased my fork on the 0.8 tag. Had to force push, so the new commit sha is 16acbd.