/elm-vim

How to setup Vim tooling for working with Elm

Primary LanguageVim Script

elm-vim

Instructions to get started with Elm tooling in Vim.

Setup

Language Server

Install elm-language-server and its dependencies. It provides most features, e.g. diagnostics (elm make), linting (elm-analyse), jump to definition, formatting (elm-format) and more. It is a standalone implementation of the language server protocol (LSP). There exist multiple language server client implementations (e.g. CoC or ale).

Syntax highlighting

If you have Vim/Neovim > 8.2 patch 929, Elm syntax is already included in Vim!

Otherwise install elm-vim-syntax to add syntax highlighting and indentation.

Code formatting

elm-format is used by elm-language-server to format code. An alternative is ale's elm-format fixer.

Linting

elm-analyse is used by elm-language-server for static code analysis of elm code. It doesn't need to be installed manually. Its checks can be configured.

Snippets

elm-language-server provides snippets (e.g. with CoC).

An alternative is to install Ultisnips for snippet functionality. Install honza/vim-snippets which contains elm.snippets

Tests

Install vim-test to run tests. It contains elmtest.vim. :TestFile will execute elm-test.

Tagbar

Install majutsushi/tagbar and configure content displayed in the tagbar.

let g:tagbar_type_elm = {
      \ 'kinds' : [
      \ 'f:function:0:0',
      \ 'm:modules:0:0',
      \ 'i:imports:1:0',
      \ 't:types:1:0',
      \ 'a:type aliases:0:0',
      \ 'c:type constructors:0:0',
      \ 'p:ports:0:0',
      \ 's:functions:0:0',
      \ ]
      \}

Configuration examples

There is an example configuration to showcase a small Vim setup for Elm.

User configurations

It's a good idea to take a look how others are configuring their environments. Here are some examples:

FAQ

Frequently asked questions. Feel free to contribute.

"How do I configure CoC and set up keybindings?"

Start with the official CoC example configuration. Then start to look into our example configuration and user configurations. It'll take some time and tweaking until you find a configuration that's perfect for you.

"How can I format files on save with CoC?"

Add "coc.preferences.formatOnSaveFiletypes": ["elm"] to coc-settings.json.

"CoC or the language server is not working. How can I debug?"

With CoC you can use :CocInfo to see all client/server messages or :CocOpenLog to show the log. Set elmLS.trace.server to verbose. Make sure you're using a valid elm project with an elm.json file or verify behavior with elm-spa-example.

"CoC shows only first lines of error message in floating window"

CoC uses floating windows to display diagnostics (error messages). By default only the first 8 lines are shown.

"How can I disable elm-analyse inside of elm-language-server?"

It's possible to configure when elm-analyse will be triggered or disable it with config "elmAnalyseTrigger": "never". See "server settings".

"How can I disable an elm-analyse rule?"

Add a elm-analyse.json config file like this and add check names.

{
  "checks": {
    "UnusedTypeAlias": false
  }
}

"What about ElmCast/elm-vim and Zaptic/elm-vim?"

ElmCast/elm-vim an older vim plugin people used before there existed a language server implementation. We're grateful it existed in the past, but seems to be unmaintained and isn't necessary anymore.

Zaptic/elm-vim is a maintained fork. It can be a simple alternative to the elm-language-server with fewer features and easier setup.