Skip to content

elm-tooling/elm-vim

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

51 Commits
 
 
 
 
 
 

Repository files navigation

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, 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> 8.2 patch 929 or neovim, Elm syntax is already included in Vim!

(Alternatively 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.

vim-sleuth will set shiftwidth and expandtab according to your current file (or other similar files in your project). It is a great addition to elm-format and a Elm syntax.

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 a linter rule?"

Add a elm-analyse.json config file like this and add check names. We're not using elm-analyse anymore, but this should still work for most rules.

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

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

ElmCast/elm-vim is an older vim plugin people used before there existed a language server implementation. We're grateful it existed in the past, but the plugin 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.

Releases

No releases published

Packages

No packages published