Vim Tips Wiki

Optionally open matching or selected tag in full height vertical window

1,625pages on
this wiki
Add New Page
Talk0 Share
Tip 1004 Printable Monobook Previous Next

created September 26, 2005 · complexity intermediate · author Michael Watkins · version 6.0

I prefer the tags to have a full height window off to the right, most of the time. This script and mappings give both.

" preview window... to get it to open vert right, or horiz as desired
function PreviewTag(top)
  "by MW
  set previewheight=25
  exe "silent! pclose"
  if &previewwindow " don't do this in the preview window
  let w = expand("<cword>") " get the word under cursor
  exe "ptjump " . w
  " if any non False arg, open in simple horiz window so simply return
  if a:top
  " otherwise, make it vertical
  exe "silent! wincmd P"
  if &previewwindow " if we really get there...
    if has("folding")
      silent! .foldopen " don't want a closed fold
    wincmd L " move preview window to the left
    wincmd p " back to caller
    if !&previewwindow " got back
      wincmd _
      " make caller full size (I use minibufexplorer and for some reason
      " the window is altered by the preview window split and manipulation
      " so wincmd _ sets it back... your mileage may vary

" right hand window full height preview window
inoremap <C-]> <Esc>:call PreviewTag(0)<CR>
nnoremap <C-]> :call PreviewTag(0)<CR>
" simple "above the caller" preview window,
nnoremap <M-]> :call PreviewTag(1)<CR>
inoremap <M-]> <Esc>:call PreviewTag(1)<CR>
" close preview
noremap <M-[> <Esc>:pc<CR>

Here's what I use for Python and Quixote (python web framework) exctags generation (FreeBSD user here) - ptl files are Quixote Python Template Language files, essentially Python, and this exctags cmd line builds an appropriate tags file:

function WritePythonTags()
  let foo = system("/usr/bin/ctags *.py *.ptl")

" attempt to write / update tags file on every save...
" better way? not sure I care, its fast enuf.
au BufWritePost *.py,*.ptl call WritePythonTags()


See script#1343 to automatically update tags files upon saving.

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.