First line starting with space affects cursor position when switching buffers

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
10 messages Options
Reply | Threaded
Open this post in threaded view
|

First line starting with space affects cursor position when switching buffers

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

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Erik Christiansen
On 31.05.18 23:25, [hidden email] wrote:
> 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.

A fresh edit (:e) is not a jump list return, so the behaviour is to be
expected. Try the ":bu" command instead, for better results.

Alternatively, the :help on ^O and ^I is terse, but do briefly describe
how to go back up the jump list, across files. Admittedly that is
laborious, but the following may be a useful alternative to :bu-ing about.

" Alt-O & Alt-I between files, just as ^O & ^I retrace move history:
" Thanks to Marcin Szamotulski.

nm <A-o> :call FileJump(v:count1, 'b')<cr>
nm <A-i> :call FileJump(v:count1, 'f')<cr>

Erik

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Chr. von Stuckrad
In reply to this post by dmccooey@comcast.net
On Thu, 31 May 2018, [hidden email] wrote:

> 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.

This is original default behaviour - open file, stand at first char.

But in my .vimrc I have the following snippet
(for so long, that I do not remember where from):
--------------------------------------------------------------------
    " Uncomment the following to have Vim jump to the last position when
    " reopening a file
    au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$")
    \| exe "normal! g'\"" | endif
---------------------------------------------------------------------
With it vim remembers the position-per-filename (in .viminfo)
and jumps to the position re-entering the file.

BUT the ':help viminfo' contains the following 'NOTE':
---------------------------------------------------------------------
The marks are only written when exiting Vim, which is fine because
marks are remembered for all the files you have opened in the
current editing session, unless ":bdel" is used.  If you want to
save the marks for a file that you are about to abandon with
":bdel", use ":wv".
---------------------------------------------------------------------

SO, what you (and me too) really need, is some way to make
sure the marks are written, even if we 'abandon the file' !
(Or how to make 'wv' the default instead of typing the v ???)
I assume ':e' does the same as (or imples) ':bdel' with the
current/old file here.

Stucki

--
Christoph von Stuckrad    * * | also XMPP = |Mail <[hidden email]> \
Freie Universitaet Berlin |/_*| 'jabber' via|Tel(Mo.,Mi.):+49 30 838-75 459|
IT Mathematik & Informatik|\ *|stucki@jabber|  (Di,Do,Fr):+49 30 77 39 6600|
Takustr. 9 / 14195 Berlin * * |.fu-berlin.de|Fax(home):   +49 30 77 39 6601/
                                           

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Andy Wokula
In reply to this post by dmccooey@comcast.net
Am 01.06.2018 um 08:25 schrieb [hidden email]:

> 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

--
Andy

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

dmccooey@comcast.net
On Friday, 1 June 2018 12:22:05 UTC-5, Andy Wokula  wrote:

> Am 01.06.2018 um 08:25 schrieb [hidden email]:
> > 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
>
> --
> Andy
This must be it.
I can confirm that 7.3 (for Mac) works ok.

Dave

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Bram Moolenaar
In reply to this post by Andy Wokula

Andy Wokula wrote:

> Am 01.06.2018 um 08:25 schrieb [hidden email]:
> > 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.

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

--
hundred-and-one symptoms of being an internet addict:
16. You step out of your room and realize that your parents have moved and
    you don't have a clue when it happened.

 /// Bram Moolenaar -- [hidden email] -- 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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

dmccooey@comcast.net
On Saturday, 2 June 2018 02:29:42 UTC-5, Bram Moolenaar  wrote:

> Andy Wokula wrote:
>
> > Am 01.06.2018 um 08:25 schrieb [hidden email]:
> > > 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.
>
> 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
>
> --
> hundred-and-one symptoms of being an internet addict:
> 16. You step out of your room and realize that your parents have moved and
>     you don't have a clue when it happened.
>
>  /// Bram Moolenaar -- [hidden email] -- 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    ///
Hello Bram,

When switching back and forth between two files using :e#,
and assuming there are no autocommands involved, does vim
normally put the cursor in the first line after each switch?

I ask because I don't have autocommands involved, and I don't
see vim behaving this way.

There may be some confusion in this thread, because Christoph's
reply referred to the case where a file is being opened for the
first time.  My post is not about that case.  When I open a
file for the first time, I expect vim to put the cursor in the
first line (and it does).

Dave

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Tony Mechelynck
On Mon, Jun 4, 2018 at 2:50 AM, [hidden email]
<[hidden email]> wrote:

> On Saturday, 2 June 2018 02:29:42 UTC-5, Bram Moolenaar  wrote:
>> Andy Wokula wrote:
>>
>> > Am 01.06.2018 um 08:25 schrieb [hidden email]:
>> > > 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.
>>
>> 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
>>
>> --
>> hundred-and-one symptoms of being an internet addict:
>> 16. You step out of your room and realize that your parents have moved and
>>     you don't have a clue when it happened.
>>
>>  /// Bram Moolenaar -- [hidden email] -- 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    ///
>
> Hello Bram,
>
> When switching back and forth between two files using :e#,
> and assuming there are no autocommands involved, does vim
> normally put the cursor in the first line after each switch?
>
> I ask because I don't have autocommands involved, and I don't
> see vim behaving this way.
>
> There may be some confusion in this thread, because Christoph's
> reply referred to the case where a file is being opened for the
> first time.  My post is not about that case.  When I open a
> file for the first time, I expect vim to put the cursor in the
> first line (and it does).
>
> Dave

When there are no autocommands involved, or when a file with no marks
remembered is opened, the cursor goes to the first line. I just
checked where in the first line, and it is on the first nonblank.

However there has been for some time an autocommand in
vimrc_example.vim, and now in defaults.vim, which sets the cursor at
the last known position, if there is one. That is the autocommand
mentioned by Chr. von Stuckrad, and nowadays the defaults.vim defines
it in the group vimStartup. I remember a time when that autocommand
didn't exist by default, though, so it must have been added to the
vimrc_example.vim (and IIRC in group vimrcEx) at some point in Vim 6
or 7. I just tried to put the cursor on the first character of the
first line, a space, but even after doing ":wv" prior to quitting the
file, it is reopened with the cursor on the first nonblank even though
the " mark is at column zero. But if the cursor is on a different line
than the first when quitting, then if it was in column zero, even on a
space, the file will be reopened with the cursor where it used to be.

This baffles me, because the autocommand in the defaults.vim reads:

    " When editing a file, always jump to the last known cursor position.
    " Don't do it when the position is invalid, when inside an event handler
    " (happens when dropping a file on gvim) and for a commit message (it's
    " likely a different one than last time).
    autocmd BufReadPost *
      \ if line("'\"") >= 1 && line("'\"") <= line("$") && &ft !~# 'commit'
      \ |   exe "normal! g`\""
      \ | endif

Now I named the file "xx.txt" (the filetype doesn't include "commit")
and when the cursor was on line 1, and the " mark is remembered as
"line 1 column zero" then line("'\"") is 1, which is >= 1 and <=
line("$"), isn't it? Yet this autocommand puts the cursor on the first
nonblank in column 1 in that case, but doing g`" manually, or even
doing :exe ":normal g'\"" manually, puts it in the first column, even
if that character is a space.


Best regards,
Tony.

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Andy Wokula
In reply to this post by Bram Moolenaar
Am 02.06.2018 um 09:29 schrieb Bram Moolenaar:

>
> Andy Wokula wrote:
>
>> Am 01.06.2018 um 08:25 schrieb [hidden email]:
>>> 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"

--
Andy

--
--
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 [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

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

Bram Moolenaar

Andy Wokula wrote:

> >> Am 01.06.2018 um 08:25 schrieb [hidden email]:
> >>> 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 -- [hidden email] -- 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 [hidden email].
For more options, visit https://groups.google.com/d/optout.