Instructions to get started with Elm tooling in Vim.
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).
- CoC.nvim (recommended): Install
CoC. Look into elm-language-server README orCoCwiki for setup and usage instructions. - ale: Install
aleand useelm_lslinter. Seeelm-language-serverREADME,aleREADME andaledocs for usage instructions. - LanguageClient-neovim: Install
LanguageClient-neovimand see elm-language-server README.
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.)
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.
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
Install vim-test to run tests. It contains elmtest.vim. :TestFile will execute elm-test.
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',
\ ]
\}There is an example configuration to showcase a small Vim setup for Elm.
It's a good idea to take a look how others are configuring their environments. Here are some examples:
andys8/dotfilesAugustin82/vimantoine-atmire/vim-elmcpehota/dotfileshulufei/dotfilesMiaxos/Home-leojpod/dotfiles
Frequently asked questions. Feel free to contribute.
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.
Add "coc.preferences.formatOnSaveFiletypes": ["elm"] to coc-settings.json.
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 uses floating windows to display diagnostics (error messages). By default only the first 8 lines are shown.
- Raise maximum number of error lines displayed with
diagnostic.maxWindowHeight - Disable floating window and use
diagnostic.messageTarget"echo"instead - Look into how to scroll inside the floating window.
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
}
}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.