Dart Support for Vim with dartfmt, ALE and Language Server Protocol

03/25/20191 Min Read — In DevTools, Vim, Dart

Here's how to get language support for the Dart language in (Neo)Vim.

Tools Needed

I assume that you installed (Neo)Vim and the Dart language. For example, Arch has a community package that easily installs dart with your package manager of choice.

Additional tools:

1. Install dartfmt and dart_language_server

Install both programs with the Dart SDK.

In your terminal:

pub global activate dart_language_server


pub global activate dart_style

You need to add the pub bin directory to your environment variables so that you can run the programs from every directory.

With bash or zsh:

export PATH="~/.pub-cache/bin:$PATH"

With fish:

set -U fish_user_paths ~/.pub-cache/bin $fish_user_paths

2. Install LSP Client for (Neo)Vim

If you want to install ALE and Vim Polyglot with minpac as package manager (add to your .vimrc):

call minpac#add('w0rp/ale')
call minpac#add('sheerun/vim-polyglot')

Don't forget to load your packages from the Vim command line!

:call minpac#update()

If you use a different package manager, please consult their installation instructions.

Add the following configuration options to your ALE setup (add to your .vimrc):

let g:ale_linters = {
\   'dart': ['language_server'],

let g:ale_fixers = {
\   'dart': ['dartfmt'],

3. Usage

Everything should now work out of the box when you open a Dart file in Vim. To run the ALE linting and fixing funtions, you either have to call them manually with :ALELint and :ALEFix or configure ALE to run them automatically.

Further Reading