Question

I'd like to have the tagbar VIM plugin launch when I open certain filetypes, so I added the following to my .vimrc:

if has("gui_running")
    autocmd BufEnter *.hs nested TagbarOpen

However, this isn't working as I expected. It opens a side window, but the side window displays nothing and my cursor is trapped within it. I cannot switch windows with a click or with the CTRL-W movement commands.

However, when I run TagbarOpen manually, it works just fine.

Anyone else tried this, or is the above the wrong command to issue?

Was it helpful?

Solution

Interesting, that's a side effect of a convenience functionality that I hadn't anticipated. What happens is this: If TagbarOpen is called while the window is already open, Tagbar makes the cursor jump to its window instead of just doing nothing (for convenience like I said). So every time you try to leave the window by switching to the Haskell window, the autocommand causes it to jump right back. I've pushed a change that removes this functionality -- it probably wasn't that useful to begin with. So if you give the development version on GitHub a try (https://github.com/majutsushi/tagbar), it should work.

That the window is empty has a different reason: Haskell is not supported by Exuberant Ctags by default. But someone wrote a nice alternative for Haskell that works with Tagbar here: https://github.com/bitc/lushtags.

OTHER TIPS

I actually have this exact configuration set up my vimrc for php files. Tagbar opens with function / variables loaded, cursor stays in php source file when Vim loads:

autocmd FileType php call SetPHPOptions()
function! SetPHPOptions()
setlocal shiftwidth=4 tabstop=4 softtabstop=4 expandtab makeprg=php-xdebug\ %
    :call tagbar#autoopen(0)
endfunction

substitute 'php' for 'hs' or any other file type you want. List of filetypes at:

$VIMRUNTIME/filetype.vim

Have it running on MacVim (snapshot 72, Vim 7.4), and latest build of tagbar from https://github.com/majutsushi/tagbar

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top