How do I set up my Vala IDE in Vim

Today I want to share how I set my Vim for Vala coding. It is not a fully-loaded IDE but it works for me very well. Hopefully it will help you too. First I would like to show a screenshot of Vim session when I’m hacking GNOME Gnames: Gnomine.

It shows basically three awesome Vim plugins (Tagbar, Fuzzyfinder and Nerdtree) and the terminal multiplexer, Tmux. For those are not familiar with the plugins, Tagbar shows the class variables, functions, etc for easy jumping. Nerdtree is a file explorer. Fuzzyfinder is a nifty buffer switcher. Note that at the bottom of the screenshot, Tmux has three windows, named as ‘src’,’build’ and ‘bash’ and Vim is running in ‘src’ window now. Such a setting makes you quickly switch back and forth between ‘src’ window for editing and ‘build’ window for building, or ‘bash’ window for something else.

I guess most Vim users have already known these. So the real story I’m going to tell is how to make tagbar work with Vala code. Tagbar is based on  ctags however the official ctags doesn’t support Vala. Luckily I have found anjuta-tags is a ctags clone with Vala support. Type in commandline to see if you have anjuta-tags available. It should be installed along with Anjuta. Therefore I replaced the default ctags with anjuta-tags by copying anjuta-tags to a location before ctags in PATH and rename it as ctags. I guess another way is to add

let g:tagbar_ctags_bin = "anjuta-tags"

in your .vimrc file.

That is NOT enough yet. You can generate Vala tags with anjuta-tags but Tagbar still shows nothing. Now you need to edit $VIM/autoload/tagbar.vim by adding the following lines.

" Vala {{{3
 let type_vala = {}
 let type_vala.ctagstype = 'vala'
 let type_vala.kinds = [
 \ {'short' : 'c', 'long' : 'classes', 'fold' : 0},
 \ {'short' : 'd', 'long' : 'delegates', 'fold' : 0},
 \ {'short' : 'e', 'long' : 'enumerations', 'fold' : 0},
 \ {'short' : 'E', 'long' : 'error domains', 'fold' : 0},
 \ {'short' : 'f', 'long' : 'fields', 'fold' : 0},
 \ {'short' : 'i', 'long' : 'interfaces', 'fold' : 0},
 \ {'short' : 'm', 'long' : 'methods', 'fold' : 0},
 \ {'short' : 'p', 'long' : 'properties', 'fold' : 0},
 \ {'short' : 'r', 'long' : 'error codes', 'fold' : 0},
 \ {'short' : 's', 'long' : 'structures', 'fold' : 0},
 \ {'short' : 'S', 'long' : 'signals', 'fold' : 0},
 \ {'short' : 'v', 'long' : 'enumeration values', 'fold' : 0}
 \ ]
 let type_vala.sro = '.'
 let type_vala.kind2scope = {
 \ 'i' : 'interface',
 \ 'c' : 'class',
 \ 's' : 'structure',
 \ 'e' : 'enum'
 \ }
 let type_vala.scope2kind = {
 \ 'interface' : 'i',
 \ 'class' : 'c',
 \ 'struct' : 's',
 \ 'enum' : 'e'
 \ }
 let s:known_types.vala = type_vala

Also, remember to check out for syntax highlighting:-)


8 responses to this post.

  1. Thanks for the post. Before seeing this working with vala on vim as such a pain!


  2. Awesome vim-tweaking!
    I code mainly in C and Bash (sometimes in Java) and I’m using a very basic vim configuration. When I have the time to go into further details in my .vimrc and vim plugins I think this post will come handy!


  3. Hi! Glad you like Tagbar 🙂

    One tip, though: you don’t need to change the plugin files to define a new type, you can put it into your vimrc. Here’s what that would be in your case (let’s hope WordPress doesn’t mangle it):

    let g:tagbar_type_vala = {
        \ 'ctagstype' : 'vala',
        \ 'kinds'     : [
            \ 'c:classes',
            \ 'd:delegates',
            \ 'e:enumerations',
            \ 'E:error domains',
            \ 'f:fields',
            \ 'i:interfaces',
            \ 'm:methods',
            \ 'p:properties',
            \ 'r:error codes',
            \ 's:structures',
            \ 'S:signals',
            \ 'v:enumeration values'
        \ ],
        \ 'sro'        : '.',
        \ 'kind2scope' : {
            \ 'i' : 'interface',
            \ 'c' : 'class',
            \ 's' : 'structure',
            \ 'e' : 'enum'
        \ },
        \ 'scope2kind' : {
            \ 'interface' : 'i',
            \ 'class'     : 'c',
            \ 'struct'    : 's',
            \ 'enum'      : 'e'
        \ }
    \ }

    I have seen a few other instances of people modifying the plugin files directly, I wonder if I didn’t explain it well enough in the manual?


    • Hi Jan,

      It is my great pleasure to have the author of Tagbar leaving comments in my post! I like tagbar very much! Sure your vimrc vala setting for Tagbar is a better way to add a new Language:-) When I made an attempt to add Vala support in Tagbar, I found it so tempting to just copy and paste the existing example (e.g. C# support) just a few lines away in the plugin file itself:-)

      Would you mind adding Vala support in your new release of Tagbar?:-)


      • Sorry for the late reply, I was quite busy this week. Also for some reason I couldn’t get scopes to work for me, even with the newest Anjuta source from git — maybe some of my libraries are outdated. I’ve just looked at the source instead to see what exactly it does.

        I’ve added support for Vala now, it should work automatically if anjuta-tags is in your $PATH. I had to do a few changes in the initialisation code so you wouldn’t get errors when opening Vala files without anjuta-tags being available. So essentially you shouldn’t have to configure anything now! (Note that the code is only in the Github repository at the moment, I haven’t released a new version yet.)

        Let me know if it works for you (and if the default ordering of kinds makes sense) 🙂

      • It is so nice that you have added Vala support in Tagbar! I’m using it right now. It works like a charm! Thank you so much!

  4. Out of curiosity, what font and what theme are you using?


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: