Vim Tips Wiki
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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.