Monday, June 4, 2018

Re: First line starting with space affects cursor position when switching buffers

Andy Wokula wrote:

> >> Am 01.06.2018 um 08:25 schrieb dmccooey@comcast.net:
> >>> Hello,
> >>>
> >>> I have encountered what appears to be a bug in vim,
> >>> but it might be a feature that I would like to disable.
> >>>
> >>> To reproduce the problem:
> >>>
> >>> Use vim to create a new file, and add 10 or so lines of text to the file.
> >>> In the first line, put at least two characters, and make sure the first character is a space or tab.
> >>> Place the cursor on the last line (or any line other than the first line).
> >>> Save the file (:w) and switch (:e) to view another file.
> >>> Switch back (:e) to the original file.
> >>> Notice that the cursor is on the first line, not where it was originally.
> >>>
> >>> I am using vim 8.0 for Mac.
> >>>
> >>> Dave McCooey
> >>
> >> I've seen this too for a long time (before v8.0), but didn't bother to investigate ...
> >> It's easy to "fix": just don't start the first line with whitespace.
> >>
> >> Ok, I did some bisecting (first time ^^):
> >>
> >> gvim-v7-4-674.exe (and earlier) works ok
> >> gvim-v7-4-675.exe (and later) shows the bug
> >>
> >> Someone should take a look at Patch 7.4.675
> >
> > That patch looks fine.
>
> There must be something wrong with this patch.
>
> > Vim normally puts the cursor in the first line. There must be an
> > autocommand that is moving it to the last used position, the problem is
> > most likely in that autocommand.
> >
> > You can use $VIMRUNTIME/macros/editexisting.vim
>
> I checked again with the raw binaries (no scripts loaded ¹): the same.
>
> To reproduce:
> :edit +$ some-file.ext
>
> " reload the file:
> :edit
>
> " or (but it doesn't matter):
> :noauto edit
>
> Normally, reloading keeps the cursor position, unless
> the first line matches ^\s\+\S and the current Vim is 7.4.675 or newer.
>
>
> ¹ -N -u NONE -i NONE --cmd "set go+=M go-=T"

I somehow missed that this is specifically about ":edit" and "edit #".
That's where the original position is used even in compatible mode.

Looks like it's caused by the change to keep the column set by an
autocommand. Previously we only kept the line, and moving the cursor to
the first non-blank confuses it.

--
How To Keep A Healthy Level Of Insanity:
7. Finish all your sentences with "in accordance with the prophecy".

/// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: