Vim for elixir

13 Nov 2016

During my two month sabbatical from work I am starting a small toy project using elixir. I finally have the time to play around with this great language. But no language is fun to write code in when your tooling is not configured correctly. In this blog post I will go through my current vim configuration for elixir.

vim-polyglot

Plug 'sheerun/vim-polyglot'

Vim-polyglot makes it really easy to have support for tons of programming languages inside of vim. You won't need to find out the package for a certain language, this plugin has them all. And the best part of it is that it loads the language support on demand.

vim-gutentags

Plug 'ludovicchabant/vim-gutentags'
let g:gutentags_cache_dir = '~/.tags_cache'

I am a heavy user of the tag system within vim. With it you can jump to the definition of a method, class or module using Ctrl-]. More details in the vim wikia. To always have an up to date tags definition file, I am using gutentags. It refreshes the tags file on save in the background.

To make ctags elixir aware I am using this config within my .ctags file.

Neomake

Plug 'neomake/neomake'
autocmd! BufWritePost * Neomake

If you are using vim and haven't tried Neomake yet, you are definitely doing it wrongTM. Neomake will execute code checks to find mistakes in the currently edited file. If you use neovim or vim > 8 it will use the background job system to prevent any blocking of your editor.

And to make it even better: if you look into the config for elixir you will see that it also uses credo to mark code consistency problems right in your editor.

phoenix.vim

Plug 'c-brenn/phoenix.vim'
Plug 'tpope/vim-projectionist'

I really love working with vim-rails, and this is the same thing for phoenix. It gives you methods to navigate to controllers, models, channels and other files with commands like :Emodel {name}.

Alchemist.vim

Plug 'slashmili/alchemist.vim'
let g:alchemist_tag_disable = 1

Together with deoplete this opens up a new world of tab completions. It exposes module and method definitions to your fingertips. This is one of the things that are really hard to do for languages like ruby.

My complete neovim config can be found in my dotfiles repo.

comments powered by Disqus