Re: Multiple windows and tabs on the same buffer

1 view
Skip to first unread message

Ben Schmidt

unread,
Jan 17, 2008, 3:54:54 PM1/17/08
to vim...@googlegroups.com, vim...@googlegroups.com
Tony Mechelynck wrote:
> albiejvr wrote:
>> Nathaniel Whiteinge wrote:
>>> If I have a multiple windows open all viewing different parts of the
>>> same buffer, then open a new tab on that buffer, the cursor position
>>> is reset to the first line in all the windows in that first tab. Is
>>> this normal?
>>>
>> What command are you using to open the new tab on your buffer?
>>
>> When I use
>>
>> :tabedit %
>>
>> it positions the cursor at the same position in the file as in the
>> window where I executed the command from.
>>
>> If I instead use
>>
>> :tabnew
>> :e filename.txt
>>
>> the cursor seems to be automatically positioned at the highest (furthest
>> down the file) line number that I have the buffer already open at.
>>
>> There is probably some setting to determine the cursor position in a
>> newly-opened file, but I don't know it.
>
> With the autocommand defined at lines 66sqq of $VIMRUNTIME/vimrc_example.vim,
> ":e filename.txt" places the cursor wherever it was when you latest edited
> that file:
>
> " When editing a file, always jump to the last known cursor position.
> " Don't do it when the position is invalid or when inside an event handler
> " (happens when dropping a file on gvim).
> autocmd BufReadPost *
> \ if line("'\"") > 0 && line("'\"") <= line("$") |
> \ exe "normal! g`\"" |
> \ endif

The OP's problem was not where the cursor was placed in the newly opened tab, but
that the cursor moved in his already open tab. That is my experience also, and I'm
sure it would be very annoying. The problem only occurs if you open the new tab
page editing a file in your current tab page using a single command (e.g. :tabedit
% or :tabedit and giving a filename of a currently displayed file). After the new
tab has appeared, with the cursor positioned as expected, do a gt (or a few) to
return to your original tab and you will find all the windows editing that file
have scrolled to line 1. This is surely a bug. CCing vim_dev.

Ben.


Send instant messages to your online friends http://au.messenger.yahoo.com

Reply all
Reply to author
Forward
0 new messages