Cursor column not remembered when swapping buffers with "set hidden"

27 views
Skip to first unread message

Jean Johner

unread,
Mar 19, 2010, 9:55:42 AM3/19/10
to vim_dev
Hello,
The following is extracted from vim_use thread with the same title for
which I got no replies.

Please do the following (unix vim7.2.394):

1) With "set nohidden" in .vimrc (default)
gvim file1
Put the cursor on line 4, column 10 (not line 1)
:e file2
Use Menu/Buffers/Previous (or :bprevious)
Buffer file1 is reopened with cursor on line 4, column 10

Explanation: with "set nohidden", file1 is really closed so that :bp
reopens it with the autocmd g`" executed.

2) With "set hidden" in .vimrc
gvim file1
Put the cursor on line 4, column 10 (not line 1)
:e file2
Use Menu/Buffers/Previous (or :bprevious)
Buffer file1 is reopened with cursor on line 4, colum 1
(Idem for any line).

Do you reproduce that?
It looks like a bug.

Best regards
Jean Johner

James Vega

unread,
Mar 19, 2010, 10:16:18 AM3/19/10
to vim...@googlegroups.com
On Fri, Mar 19, 2010 at 9:55 AM, Jean Johner <jean....@cea.fr> wrote:
> 2) With "set hidden" in .vimrc
> gvim file1
> Put the cursor on line 4, column 10 (not line 1)
> :e file2
> Use Menu/Buffers/Previous (or :bprevious)
> Buffer file1 is reopened with cursor on line 4, colum 1
> (Idem for any line).

This is expected behavior. See ":help 'startofline". You'll likely
want to ":set nostartofline" for the behavior you desire.

--
James
GPG Key: 1024D/61326D40 2003-09-02 James Vega <jame...@jamessan.com>

Jean Johner

unread,
Mar 20, 2010, 6:03:42 AM3/20/10
to James Vega, vim...@googlegroups.com
On Mar 19, 3:16 pm, James Vega <james...@jamessan.com> wrote:
> This is expected behavior.  See ":help 'startofline".  You'll likely
> want to ":set nostartofline" for the behavior you desire.

Hi James,
Setting "nostartofline" solves the problem, but it results in keeping
the cursor column also for CTRL-F, gg ... which in my opinion is not
natural.

Presently, the situation is as follows:
1)
set sol (default)
set nohidden (default)
autocmd g`" in .vimrc (default .vimrc)
Result: the cursor column is remembered with :bprevious

2)
set sol (default)
set hidden (to be able to edit a new buffer without
saving)
autocmd g`" in .vimrc (default .vimrc)
Result: the cursor column is NOT remembered with :bprevious

In my opinion, the cursor column should be remembered in case 2)

Best regards
Jean Johner

James Vega

unread,
Mar 20, 2010, 9:38:53 AM3/20/10
to vim...@googlegroups.com
On Sat, Mar 20, 2010 at 03:03:42AM -0700, Jean Johner wrote:
> On Mar 19, 3:16 pm, James Vega <james...@jamessan.com> wrote:
> > This is expected behavior.  See ":help 'startofline".  You'll likely
> > want to ":set nostartofline" for the behavior you desire.
>
> Hi James,
> Setting "nostartofline" solves the problem, but it results in keeping
> the cursor column also for CTRL-F, gg ... which in my opinion is not
> natural.
>
> Presently, the situation is as follows:
> 1)
> set sol (default)
> set nohidden (default)
> autocmd g`" in .vimrc (default .vimrc)

Which is run on BufReadPost (if it's the autocmd listed at ":help
last-position-jump"). That happens here because when 'nohidden' is set
and you switch buffers, the buffer is unloaded. When you switch back to
that buffer, it is re-read from disk, therefore the BufReadPost autocmd
is executed.

> Result: the cursor column is remembered with :bprevious
>
> 2)
> set sol (default)
> set hidden (to be able to edit a new buffer without
> saving)
> autocmd g`" in .vimrc (default .vimrc)

In this situation, the BufReadPost autocmd isn't being run because the
buffer is still in memory. You could try also running the autocmd on
BufEnter in order to achieve your desired behavior.

> Result: the cursor column is NOT remembered with :bprevious

Note that there is no "default" vimrc. There's an example vimrc that's
shipped with Vim and some Linux distributions provide a system-wide
vimrc that is sourced before the user's vimrc.

signature.asc

Jean Johner

unread,
Mar 22, 2010, 7:07:40 AM3/22/10
to James Vega, vim...@googlegroups.com
On Mar 20, 2:38 pm, James Vega <james...@jamessan.com> wrote:
> In this situation, the BufReadPost autocmd isn't being run because the
> buffer is still in memory.  You could try also running the autocmd on
> BufEnter in order to achieve your desired behavior.
Replacing BufReadPost with BufEnter in vimrc_example.vim solves the
problem.

Thank you James

Jean Johner

Reply all
Reply to author
Forward
0 new messages