diff --git a/autoload/tagbar.vim b/autoload/tagbar.vim index 299ea63..15f18e4 100644 --- a/autoload/tagbar.vim +++ b/autoload/tagbar.vim @@ -1767,8 +1767,14 @@ function! s:OpenWindow(flags) abort endif let s:window_opening = 1 - let openpos = g:tagbar_left ? 'topleft vertical ' : 'botright vertical ' - exe 'silent keepalt ' . openpos . g:tagbar_width . 'split ' . '__Tagbar__' + if g:tagbar_vertical == 0 + let openpos = g:tagbar_left ? 'topleft vertical ' : 'botright vertical ' + let width = g:tagbar_width + else + let openpos = g:tagbar_left ? 'leftabove ' : 'rightbelow ' + let width = g:tagbar_vertical + endif + exe 'silent keepalt ' . openpos . width . 'split ' . '__Tagbar__' unlet s:window_opening call s:InitWindow(autoclose) @@ -3050,12 +3056,6 @@ function! s:ShowInPreviewWin() abort return endif - call s:GotoFileWindow(taginfo.fileinfo, 1) - call s:mark_window() - - " Check whether the preview window is already open and open it if not. - " This has to be done before the :psearch below so the window is relative - " to the Tagbar window. let pwin_open = 0 for win in range(1, winnr('$')) if getwinvar(win, '&previewwindow') @@ -3064,14 +3064,32 @@ function! s:ShowInPreviewWin() abort endif endfor + " We want the preview window to be relative to the file window in normal + " (horizontal) mode, and relative to the Tagbar window in vertical mode, + " to make the best use of space. + if g:tagbar_vertical == 0 + call s:GotoFileWindow(taginfo.fileinfo, 1) + call s:mark_window() + endif + + " Open the preview window if it is not already open. This has to be done + " explicitly before the :psearch below to better control its positioning. if !pwin_open silent execute \ g:tagbar_previewwin_pos . ' pedit ' . taginfo.fileinfo.fpath + if g:tagbar_vertical != 0 + silent execute 'vertical resize ' . g:tagbar_width + endif " Remember that the preview window was opened by Tagbar so we can " safely close it by ourselves let s:pwin_by_tagbar = 1 endif + if g:tagbar_vertical != 0 + call s:GotoFileWindow(taginfo.fileinfo, 1) + call s:mark_window() + endif + " Use psearch instead of pedit since pedit essentially reloads the file " and creates an empty undo entry. psearch has to be called from the file " window, and since we only want matches in the current file we disable diff --git a/doc/tagbar.txt b/doc/tagbar.txt index b227eda..d933392 100644 --- a/doc/tagbar.txt +++ b/doc/tagbar.txt @@ -388,11 +388,29 @@ Default: 0 By default the Tagbar window will be opened on the right-hand side of vim. Set this option to open it on the left instead. +If |g:tagbar_vertical| is used then setting this variable will open the Tagbar +window at the top, otherwise it will open at the bottom. + Example: > let g:tagbar_left = 1 < + *g:tagbar_vertical* +g:tagbar_vertical~ +Default: 0 + +If this is set to a positive value then the Tagbar window will be opened at +the top or bottom of the Vim window instead of at the side. This can be useful +for monitors that have been rotated into a vertical position. The value of +this variable will determine the number of lines to use for the Tagbar window. +See |g:tagbar_left| for configuring the position of the window. + +Example: +> + let g:tagbar_vertical = 30 +< + *g:tagbar_width* g:tagbar_width~ Default: 40 @@ -604,7 +622,7 @@ Example: *g:tagbar_previewwin_pos* g:tagbar_previewwin_pos~ -Default: topleft +Default: "topleft", or "rightbelow vertical" if |g:tagbar_vertical| is set The position of the preview window. Valid values are the window splitting commands that are described starting from |:vertical|. Set it to an empty diff --git a/plugin/tagbar.vim b/plugin/tagbar.vim index fe2a815..d9507fe 100644 --- a/plugin/tagbar.vim +++ b/plugin/tagbar.vim @@ -48,6 +48,11 @@ function! s:init_var(var, value) abort endif endfunction +if !exists('g:tagbar_vertical') || g:tagbar_vertical == 0 + let s:previewwin_pos = 'topleft' +else + let s:previewwin_pos = 'rightbelow vertical' +endif let s:options = [ \ ['autoclose', 0], \ ['autofocus', 0], @@ -59,15 +64,17 @@ let s:options = [ \ ['hide_nonpublic', 0], \ ['indent', 2], \ ['left', 0], - \ ['previewwin_pos', 'topleft'], + \ ['previewwin_pos', s:previewwin_pos], \ ['show_visibility', 1], \ ['show_linenumbers', 0], \ ['singleclick', 0], \ ['sort', 1], \ ['systemenc', &encoding], + \ ['vertical', 0], \ ['width', 40], \ ['zoomwidth', 1], \ ] +unlet s:previewwin_pos for [opt, val] in s:options call s:init_var(opt, val)