Restoring screen to previous display

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view

Restoring screen to previous display

Nikolai Weibull-2
Currently, whenever I switch buffers the cursor line is being centered
in the window.  I have 'hidden' set and use only one window for most
tasks, using :bn and :bp to switch between buffers.  I would like the
display of the buffer to remain the same between switches, so that I
don't get a centering effect of the cursor line.  I have tried the
following set of autocommands, but it seems that what is executed in
BufWinEnter is being overridden by a restoration function (in C)
executed by vim whenever autocommands have completed.

autocmd BufWinLeave * let b:last_pos_mark = Mark()

autocmd BufWinEnter * if exists("b:last_pos_mark") | exe b:last_pos_mark | endif

function! Mark(...)
  if a:0 == 0
    let mark = line(".") . "G" . virtcol(".") . "|"
    normal! H
    let mark = "normal!" . line(".") . "Gzt" . mark
    execute mark
    return mark
  elseif a:0 == 1
    return "normal!" . a:1 . "G1|"
    return "normal!" . a:1 . "G" . a:2 . "|"

Does anyone have any suggestions on another way of doing this?  I've
been unable to find anything in the tips section of


Nikolai Weibull: now available free of charge at!
Born in Chicago, IL USA; currently residing in Gothenburg, Sweden.