From 290b71e2b7038cf64f9a1d3ece72a0bb4b0cb994 Mon Sep 17 00:00:00 2001 From: Jan Larres Date: Mon, 11 Nov 2013 17:12:40 +1300 Subject: [PATCH] Skip preview window when jumping to tag --- autoload/tagbar.vim | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index 13a779b..dd90f90 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -2944,7 +2944,7 @@ function! s:JumpToTag(stay_in_tagbar) abort let tagbarwinnr = winnr() - call s:GotoPreviousWindow(taginfo.fileinfo) + call s:GotoFileWindow(taginfo.fileinfo) " Mark current position so it can be jumped back to mark ' @@ -3558,29 +3558,39 @@ function! s:GetTagInfo(linenr, ignorepseudo) abort return taginfo endfunction -" s:GotoPreviousWindow() {{{2 -" Try to switch to the previous buffer/window; if the buffer isn't currently -" shown in a window Tagbar will open it in the first window that has a -" non-special buffer in it. -function! s:GotoPreviousWindow(fileinfo) abort +" s:GotoFileWindow() {{{2 +" Try to switch to the window that has Tagbar's current file loaded in it, or +" open the file in a window otherwise. +function! s:GotoFileWindow(fileinfo) abort let tagbarwinnr = bufwinnr('__Tagbar__') call s:winexec('wincmd p') let filebufnr = bufnr(a:fileinfo.fpath) - if bufnr('%') != filebufnr - let filewinnr = bufwinnr(filebufnr) - if filewinnr != -1 - call s:winexec(filewinnr . 'wincmd w') - else + if bufnr('%') != filebufnr || &previewwindow + " Search for the first real window that has the correct buffer loaded + " in it. Similar to bufwinnr() but skips the previewwindow. + let found = 0 + for i in range(1, winnr('$')) + call s:winexec(i . 'wincmd w') + if bufnr('%') == filebufnr && !&previewwindow + let found = 1 + break + endif + endfor + + " If there is no window with the correct buffer loaded then load it + " into the first window that has a non-special buffer in it. + if !found for i in range(1, winnr('$')) call s:winexec(i . 'wincmd w') - if &buftype == '' + if &buftype == '' && !&previewwindow execute 'buffer ' . filebufnr break endif endfor endif + " To make ctrl-w_p work we switch between the Tagbar window and the " correct window once call s:winexec(tagbarwinnr . 'wincmd w')