From 151832d234d031081c95b7bc95b4457d0ad92979 Mon Sep 17 00:00:00 2001 From: Jan Larres Date: Tue, 22 Mar 2011 01:36:28 +1300 Subject: [PATCH] Save the view when redisplaying the same file to avoid distracting jumps (idea taken from NERDTree) --- plugin/tagbar.vim | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/plugin/tagbar.vim b/plugin/tagbar.vim index 3bc7031..3ea93d8 100644 --- a/plugin/tagbar.vim +++ b/plugin/tagbar.vim @@ -1379,6 +1379,13 @@ function! s:RenderContent(fname, ftype) let lazyredraw_save = &lazyredraw set lazyredraw + if a:fname == s:current_file + " We're redisplaying the same file, so save the view + let saveline = line('.') + let savecol = col('.') + let topline = line('w0') + endif + setlocal modifiable silent! %delete _ @@ -1488,10 +1495,21 @@ function! s:RenderContent(fname, ftype) setlocal nomodifiable - " Make sure as much of the Tagbar content as possible is shown in the - " window by jumping to the top after drawing - execute 1 - call winline() + if a:fname == s:current_file + let scrolloff_save = &scrolloff + set scrolloff=0 + + call cursor(topline, 1) + normal! zt + call cursor(saveline, savecol) + + let &scrolloff = scrolloff_save + else + " Make sure as much of the Tagbar content as possible is shown in the + " window by jumping to the top after drawing + execute 1 + call winline() + endif let &lazyredraw = lazyredraw_save