Github url

ale

by dense-analysis

dense-analysis /ale

Check syntax in Vim asynchronously and fix files, with Language Server Protocol (LSP) support

9.7K Stars 1.1K Forks Last release: about 1 month ago (v2.7.0) BSD 2-Clause "Simplified" License 3.4K Commits 34 Releases

Available items

No Items, yet!

The developer of this repository has not created any items for sale yet. Need a bug fixed? Help with integration? A different license? Create a request here:

Asynchronous Lint Engine Travis CI Build Status AppVeyor Build Status Join the chat at https://gitter.im/vim-ale/Lobby

ALE Logo by Mark Grealish - https://www.bhalash.com/

ALE (Asynchronous Lint Engine) is a plugin providing linting (syntax checking and semantic errors) in NeoVim 0.2.0+ and Vim 8 while you edit your text files, and acts as a Vim Language Server Protocol client.

A linting example with the darkspectrum color scheme in GVim.

ALE makes use of NeoVim and Vim 8 job control functions and timers to run linters on the contents of text buffers and return errors as text is changed in Vim. This allows for displaying warnings and errors in files being edited in Vim before files have been saved back to a filesystem.

In other words, this plugin allows you to lint while you type.

ALE offers support for fixing code with command line tools in a non-blocking manner with the

:ALEFix

feature, supporting tools in many languages, like

prettier

,

eslint

,

autopep8

, and more.

ALE acts as a "language client" to support a variety of Language Server Protocol features, including:

  • Diagnostics (via Language Server Protocol linters)
  • Go To Definition (
    :ALEGoToDefinition
    )
  • Completion (Built in completion support, or with Deoplete)
  • Finding references (
    :ALEFindReferences
    )
  • Hover information (
    :ALEHover
    )
  • Symbol search (
    :ALESymbolSearch
    )

If you don't care about Language Server Protocol, ALE won't load any of the code for working with it unless needed. One of ALE's general missions is that you won't pay for the features that you don't use.

Help Wanted: If you would like to help maintain this plugin by managing the many issues and pull requests that are submitted, please send the author an email at [email protected].

If you enjoy this plugin, feel free to contribute or check out the author's other content at w0rp.com.

Table of Contents

  1. Supported Languages and Tools
  2. Usage
    1. Linting
    2. Fixing
    3. Completion
    4. Go To Definition
    5. Find References
    6. Hovering
    7. Symbol Search
  3. Installation
    1. Installation with Vim package management
    2. Installation with Pathogen
    3. Installation with Vundle
    4. Installation with Vim-Plug
  4. Contributing
  5. FAQ
    1. How do I disable particular linters?
    2. How can I keep the sign gutter open?
    3. How can I change the signs ALE uses?
    4. How can I change or disable the highlights ALE uses?
    5. How can I show errors or warnings in my statusline?
    6. How can I show errors or warnings in my lightline?
    7. How can I change the format for echo messages?
    8. How can I execute some code when ALE starts or stops linting?
    9. How can I navigate between errors quickly?
    10. How can I run linters only when I save files?
    11. How can I use the quickfix list instead of the loclist?
    12. How can I check JSX files with both stylelint and eslint?
    13. How can I check Vue files with ESLint?
    14. Will this plugin eat all of my laptop battery power?
    15. How can I configure my C or C++ project?
    16. How can I configure ALE differently for different buffers?
    17. How can I configure the height of the list in which ALE displays errors?
    18. How can I see what ALE has configured for the current file?

1. Supported Languages and Tools

ALE supports a wide variety of languages and tools. See thefull list in theSupported Languages and Tools page.

2. Usage

2.i Linting

Once this plugin is installed, while editing your files in supported languages and tools which have been correctly installed, this plugin will send the contents of your text buffers to a variety of programs for checking the syntax and semantics of your programs. By default, linters will be re-run in the background to check your syntax when you open new buffers or as you make edits to your files.

The behaviour of linting can be configured with a variety of options, documented in the Vim help file. For more information on the options ALE offers, consult

:help ale-options

for global options and

:help ale-integration-options

for options specified to particular linters.

2.ii Fixing

ALE can fix files with the

ALEFix

command. Functions need to be configured either in each buffer with a

b:ale\_fixers

, or globally with

g:ale\_fixers

.

The recommended way to configure fixers is to define a List in an ftplugin file.

" In ~/.vim/ftplugin/javascript.vim, or somewhere similar. " Fix files with prettier, and then ESLint. let b:ale\_fixers = ['prettier', 'eslint'] " Equivalent to the above. let b:ale\_fixers = {'javascript': ['prettier', 'eslint']}

You can also configure your fixers from vimrc using

g:ale\_fixers

, before or after ALE has been loaded.

A

\*

in place of the filetype will apply a List of fixers to all files which do not match some filetype in the Dictionary.

Note that using a plain List for

g:ale\_fixers

is not supported.

" In ~/.vim/vimrc, or somewhere similar. let g:ale\_fixers = { \ '\*': ['remove\_trailing\_lines', 'trim\_whitespace'], \ 'javascript': ['eslint'], \}

If you want to automatically fix files when you save them, you need to turn a setting on in vimrc.

" Set this variable to 1 to fix files when you save them. let g:ale\_fix\_on\_save = 1

The

:ALEFixSuggest

command will suggest some supported tools for fixing code. Both

g:ale\_fixers

and

b:ale\_fixers

can also accept functions, including lambda functions, as fixers, for fixing files with custom tools.

See

:help ale-fix

for complete information on how to fix files with ALE.

2.iii Completion

ALE offers some support for completion via hijacking of omnicompletion while you type. All of ALE's completion information must come from Language Server Protocol linters, or from

tsserver

for TypeScript.

ALE integrates with Deoplete as a completion source, named

'ale'

. You can configure Deoplete to only use ALE as the source of completion information, or mix it with other sources.

" Use ALE and also some plugin 'foobar' as completion sources for all code. call deoplete#custom#option('sources', { \ '\_': ['ale', 'foobar'], \})

ALE also offers its own automatic completion support, which does not require any other plugins, and can be enabled by changing a setting before ALE is loaded.

" Enable completion where available. " This setting must be set before ALE is loaded. " " You should not turn this setting on if you wish to use ALE as a completion " source for other completion plugins, like Deoplete. let g:ale\_completion\_enabled = 1

ALE provides an omni-completion function you can use for triggering completion manually with

<c-x><c-o></c-o></c-x>

.

set omnifunc=ale#completion#OmniFunc

When working with TypeScript files, ALE supports automatic imports from external modules. This behavior is disabled by default and can be enabled by setting:

let g:ale\_completion\_tsserver\_autoimport = 1

See

:help ale-completion

for more information.

2.iv Go To Definition

ALE supports jumping to the definition of words under your cursor with the

:ALEGoToDefinition

command using any enabled Language Server Protocol linters and

tsserver

.

See

:help ale-go-to-definition

for more information.

2.v Find References

ALE supports finding references for words under your cursor with the

:ALEFindReferences

command using any enabled Language Server Protocol linters and

tsserver

.

See

:help ale-find-references

for more information.

2.vi Hovering

ALE supports "hover" information for printing brief information about symbols at the cursor taken from Language Server Protocol linters and

tsserver

with the

ALEHover

command.

The information can be displayed in a

balloon

tooltip in Vim or GVim by hovering your mouse over symbols. Mouse hovering is enabled by default in GVim, and needs to be configured for Vim 8.1+ in terminals.

See

:help ale-hover

for more information.

2.vii Symbol Search

ALE supports searching for workspace symbols via Language Server Protocol linters with the

ALESymbolSearch

command.

Search queries can be performed to find functions, types, and more which are similar to a given query string.

See

:help ale-symbol-search

for more information.

3. Installation

To install this plugin, you should use one of the following methods. For Windows users, replace usage of the Unix

~/.vim

directory with

%USERPROFILE%\vimfiles

, or another directory if you have configured Vim differently. On Windows, your

~/.vimrc

file will be similarly stored in

%USERPROFILE%\_vimrc

.

3.i. Installation with Vim package management

In Vim 8 and NeoVim, you can install plugins easily without needing to use any other tools. Simply clone the plugin into your

pack

directory.

Vim 8 on Unix

mkdir -p ~/.vim/pack/git-plugins/start git clone --depth 1 https://github.com/dense-analysis/ale.git ~/.vim/pack/git-plugins/start/ale

NeoVim on Unix

mkdir -p ~/.local/share/nvim/site/pack/git-plugins/start git clone --depth 1 https://github.com/dense-analysis/ale.git ~/.local/share/nvim/site/pack/git-plugins/start/ale

Vim 8 on Windows

# Run these commands in the "Git for Windows" Bash terminal mkdir -p ~/vimfiles/pack/git-plugins/start git clone --depth 1 https://github.com/dense-analysis/ale.git ~/vimfiles/pack/git-plugins/start/ale

Generating Vim help files

You can add the following line to your vimrc files to generate documentation tags automatically, if you don't have something similar already, so you can use the

:help

command to consult ALE's online documentation:

" Put these lines at the very end of your vimrc file. " Load all plugins now. " Plugins need to be added to runtimepath before helptags can be generated. packloadall " Load all of the helptags now, after plugins have been loaded. " All messages and errors will be ignored. silent! helptags ALL

3.ii. Installation with Pathogen

To install this module with Pathogen, you should clone this repository to your bundle directory, and ensure you have the line

execute pathogen#infect()

in your

~/.vimrc

file. You can run the following commands in your terminal to do so:

cd ~/.vim/bundle git clone https://github.com/dense-analysis/ale.git

3.iii. Installation with Vundle

You can install this plugin using Vundleby using the path on GitHub for this repository.

Plugin 'dense-analysis/ale'

See the Vundle documentation for more information.

3.iiii. Installation with Vim-Plug

You can install this plugin using Vim-Plugby adding the GitHub path for this repository to your

~/.vimrc

and running

:PlugInstall

.

Plug 'dense-analysis/ale'

4. Contributing

If you would like to see support for more languages and tools, pleasecreate an issueor create a pull request. If your tool can read from stdin or you have code to suggest which is good, support can be happily added for it.

If you are interested in the general direction of the project, check out thewiki home page. The wiki includes a Roadmap for the future, and more.

If you'd liked to discuss the project more directly, check out the

#vim-ale

channel on Freenode. Web chat is available here.

5. FAQ

5.i. How do I disable particular linters?

By default, all available tools for all supported languages will be run. If you want to only select a subset of the tools, you can define

b:ale\_linters

for a single buffer, or

g:ale\_linters

globally.

The recommended way to configure linters is to define a List in an ftplugin file.

" In ~/.vim/ftplugin/javascript.vim, or somewhere similar. " Enable ESLint only for JavaScript. let b:ale\_linters = ['eslint'] " Equivalent to the above. let b:ale\_linters = {'javascript': ['eslint']}

You can also declare which linters you want to run in your vimrc file, before or after ALE has been loaded.

" In ~/.vim/vimrc, or somewhere similar. let g:ale\_linters = { \ 'javascript': ['eslint'], \}

For all languages unspecified in the dictionary, all possible linters will be run for those languages, just as when the dictionary is not defined. Running many linters should not typically obstruct editing in Vim, as they will all be executed in separate processes simultaneously.

If you don't want ALE to run anything other than what you've explicitly asked for, you can set

g:ale\_linters\_explicit

to

1

.

" Only run linters named in ale\_linters settings. let g:ale\_linters\_explicit = 1

This plugin will look for linters in the [

ale\_linters

](https://github.com/dense-analysis/ale/blob/master/ale_linters) directory. Each directory within corresponds to a particular filetype in Vim, and each file in each directory corresponds to the name of a particular linter.

5.ii. How can I keep the sign gutter open?

You can keep the sign gutter open at all times by setting the

g:ale\_sign\_column\_always

to 1

let g:ale\_sign\_column\_always = 1

5.iii. How can I change the signs ALE uses?

Use these options to specify what text should be used for signs:

let g:ale\_sign\_error = '\>\>' let g:ale\_sign\_warning = '--'

ALE sets some background colors automatically for warnings and errors in the sign gutter, with the names

ALEErrorSign

and

ALEWarningSign

. These colors can be customised, or even removed completely:

highlight clear ALEErrorSign highlight clear ALEWarningSign

5.iv. How can I change or disable the highlights ALE uses?

ALE's highlights problems with highlight groups which link to

SpellBad

,

SpellCap

,

error

, and

todo

groups by default. The characters that are highlighted depend on the linters being used, and the information provided to ALE.

Highlighting can be disabled completely by setting

g:ale\_set\_highlights

to

0

.

" Set this in your vimrc file to disabling highlighting let g:ale\_set\_highlights = 0

You can control all of the highlights ALE uses, say if you are using a different color scheme which produces ugly highlights. For example:

highlight ALEWarning ctermbg=DarkMagenta

See

:help ale-highlights

for more information.

5.v. How can I show errors or warnings in my statusline?

vim-airline integrates with ALE for displaying error information in the status bar. If you want to see the status for ALE in a nice format, it is recommended to use vim-airline with ALE. The airline extension can be enabled by adding the following to your vimrc:

" Set this. Airline will handle the rest. let g:airline#extensions#ale#enabled = 1

If you don't want to use vim-airline, you can implement your own statusline function without adding any other plugins. ALE provides some functions to assist in this endeavour, including:

  • ale#statusline#Count
    : Which returns the number of problems found by ALE for a specified buffer.
  • ale#statusline#FirstProblem
    : Which returns a dictionary containing the full loclist details of the first problem of a specified type found by ALE in a buffer. (e.g. The first style warning in the current buffer.) This can be useful for displaying more detailed information such as the line number of the first problem in a file.

Say you want to display all errors as one figure, and all non-errors as another figure. You can do the following:

function! LinterStatus() abort let l:counts = ale#statusline#Count(bufnr('')) let l:all\_errors = l:counts.error + l:counts.style\_error let l:all\_non\_errors = l:counts.total - l:all\_errors return l:counts.total == 0 ? 'OK' : printf( \ '%dW %dE', \ all\_non\_errors, \ all\_errors \) endfunction set statusline=%{LinterStatus()}

See

:help ale#statusline#Count()

or

:help ale#statusline#FirstProblem()

for more information.

5.vi. How can I show errors or warnings in my lightline?

lightline does not have built-in support for ALE, nevertheless there is a plugin that adds this functionality: maximbaz/lightline-ale.

For more information, check out the sources of that plugin,

:help ale#statusline#Count()

and lightline documentation.

5.vii. How can I change the format for echo messages?

There are 3 global options that allow customizing the echoed message.

  • g:ale\_echo\_msg\_format

    where:

    %s

    is the error message itself

    %...code...%
    is an optional error code, and most characters can be written between the
    %

    characters.

    %linter%

    is the linter name

    %severity%
    is the severity type
  • g:ale\_echo\_msg\_error\_str
    is the string used for error severity.
  • g:ale\_echo\_msg\_warning\_str
    is the string used for warning severity.

So for example this:

let g:ale\_echo\_msg\_error\_str = 'E' let g:ale\_echo\_msg\_warning\_str = 'W' let g:ale\_echo\_msg\_format = '[%linter%] %s [%severity%]'

Will give you:

Echoed message

See

:help g:ale\_echo\_msg\_format

for more information.

5.viii. How can I execute some code when ALE starts or stops linting?

ALE runs its own autocmdevents when a lint or fix cycle are started and stopped. There is also an event that runs when a linter job has been successfully started. These events can be used to call arbitrary functions during these respective parts of the ALE's operation.

augroup YourGroup autocmd! autocmd User ALELintPre call YourFunction() autocmd User ALELintPost call YourFunction() autocmd User ALEJobStarted call YourFunction() autocmd User ALEFixPre call YourFunction() autocmd User ALEFixPost call YourFunction() augroup END

5.ix. How can I navigate between errors quickly?

ALE offers some commands with

<plug></plug>

keybinds for moving between warnings and errors quickly. You can map the keys Ctrl+j and Ctrl+k to moving between errors for example:

nmap <silent> <c-k> <plug>(ale_previous_wrap)
nmap <silent> <c-j> <plug>(ale_next_wrap)
</plug></c-j></silent></plug></c-k></silent>

For more information, consult the online documentation with

:help ale-navigation-commands

.

5.x. How can I run linters only when I save files?

ALE offers an option

g:ale\_lint\_on\_save

for enabling running the linters when files are saved. This option is enabled by default. If you only wish to run linters when files are saved, you can turn the other options off.

" Write this in your vimrc file let g:ale\_lint\_on\_text\_changed = 'never' let g:ale\_lint\_on\_insert\_leave = 0 " You can disable this option too " if you don't want linters to run on opening a file let g:ale\_lint\_on\_enter = 0

If for whatever reason you don't wish to run linters again when you save files, you can set

g:ale\_lint\_on\_save

to

0

.

5.xi. How can I use the quickfix list instead of the loclist?

The quickfix list can be enabled by turning the

g:ale\_set\_quickfix

option on. If you wish to also disable the loclist, you can disable the

g:ale\_set\_loclist

option.

" Write this in your vimrc file let g:ale\_set\_loclist = 0 let g:ale\_set\_quickfix = 1

If you wish to show Vim windows for the loclist or quickfix items when a file contains warnings or errors,

g:ale\_open\_list

can be set to

1

.

g:ale\_keep\_list\_window\_open

can be set to

1

if you wish to keep the window open even after errors disappear.

let g:ale\_open\_list = 1 " Set this if you want to. " This can be useful if you are combining ALE with " some other plugin which sets quickfix errors, etc. let g:ale\_keep\_list\_window\_open = 1

You can also set

let g:ale\_list\_vertical = 1

to open the windows vertically instead of the default horizontally.

5.xii. How can I check JSX files with both stylelint and eslint?

If you configure ALE options correctly in your vimrc file, and install the right tools, you can check JSX files with stylelint and eslint.

First, install eslint and install stylelint withstylelint-processor-styled-components.

Supposing you have installed both tools correctly, configure your .jsx files so

jsx

is included in the filetype. You can use an

autocmd

for this.

augroup FiletypeGroup autocmd! au BufNewFile,BufRead \*.jsx set filetype=javascript.jsx augroup END

Supposing the filetype has been set correctly, you can set the following options in a jsx.vim ftplugin file.

" In ~/.vim/ftplugin/jsx.vim, or somewhere similar. let b:ale\_linter\_aliases = ['css', 'javascript'] let b:ale\_linters = ['stylelint', 'eslint']

Or if you want, you can configure the linters from your vimrc file.

" In ~/.vim/vimrc, or somewhere similar. let g:ale\_linter\_aliases = {'jsx': ['css', 'javascript']} let g:ale\_linters = {'jsx': ['stylelint', 'eslint']}

ALE will alias the

jsx

filetype so it uses the

css

filetype linters, and use the original Array of selected linters for

jsx

from the

g:ale\_linters

object. All available linters will be used for the filetype

javascript

, and no linter will be run twice for the same file.

5.xiii. How can I check Vue files with ESLint?

To check Vue files with ESLint, your ESLint project configuration file must be configured to use the Vue plugin. After that, you need to configure ALE so it will run the JavaScript ESLint linter on your files. The settings you need are similar to the settings needed for checking JSX code with both stylelint and ESLint, in the previous section.

" In ~/.vim/ftplugin/vue.vim, or somewhere similar. " Run both javascript and vue linters for vue files. let b:ale\_linter\_aliases = ['javascript', 'vue'] " Select the eslint and vls linters. let b:ale\_linters = ['eslint', 'vls']

Run

:ALEInfo

to see which linters are available after telling ALE to run JavaScript linters on Vue files. Not all linters support checking Vue files.

If you don't want to configure your linters in ftplugin files for some reason, you can configure them from your vimrc file instead.

" In ~/.vim/vimrc, or somewhere similar. let g:ale\_linter\_aliases = {'vue': ['vue', 'javascript']} let g:ale\_linters = {'vue': ['eslint', 'vls']}

5.xiv. Will this plugin eat all of my laptop battery power?

ALE takes advantage of the power of various tools to check your code. This of course means that CPU time will be used to continuously check your code. If you are concerned about the CPU time ALE will spend, which will of course imply some cost to battery life, you can adjust your settings to make your CPU do less work.

First, consider increasing the delay before which ALE will run any linters while you type. ALE uses a timeout which is cancelled and reset every time you type, and this delay can be increased so linters are run less often. See

:help g:ale\_lint\_delay

for more information.

If you don't wish to run linters while you type, you can disable that behaviour. Set

g:ale\_lint\_on\_text\_changed

to

never

. You won't get as frequent error checking, but ALE shouldn't block your ability to edit a document after you save a file, so the asynchronous nature of the plugin will still be an advantage.

If you are still concerned, you can turn the automatic linting off altogether, including the option

g:ale\_lint\_on\_enter

, and you can run ALE manually with

:ALELint

.

5.xv. How can I configure my C or C++ project?

The structure of C and C++ projects varies wildly from project to project, with many different build tools being used for building them, and many different formats for project configuration files. ALE can run compilers easily, but ALE cannot easily detect which compiler flags to use.

Some tools and build configurations can generatecompile_commands.jsonfiles. The

cppcheck

,

clangcheck

,

clangtidy

and

cquery

linters can read these files for automatically determining the appropriate compiler flags to use.

For linting with compilers like

gcc

and

clang

, and with other tools, you will need to tell ALE which compiler flags to use yourself. You can use different options for different projects with the

g:ale\_pattern\_options

setting. Consult the documentation for that setting for more information.

b:ale\_linters

can be used to select which tools you want to run, say if you want to use only

gcc

for one project, and only

clang

for another.

You may also configure buffer-local settings for linters with project-specific vimrc files. local_vimrc can be used for executing local vimrc files which can be shared in your project.

5.xvi. How can I configure ALE differently for different buffers?

ALE offers various ways to configure which linters or fixers are run, and other settings. For the majority of ALE's settings, they can either be configured globally with a

g:

variable prefix, or for a specific buffer with a

b:

variable prefix. For example, you can configure a Python ftplugin file like so.

" In ~/.vim/ftplugin/python.vim " Check Python files with flake8 and pylint. let b:ale\_linters = ['flake8', 'pylint'] " Fix Python files with autopep8 and yapf. let b:ale\_fixers = ['autopep8', 'yapf'] " Disable warnings about trailing whitespace for Python files. let b:ale\_warn\_about\_trailing\_whitespace = 0

For configuring files based on regular expression patterns matched against the absolute path to a file, you can use

g:ale\_pattern\_options

.

" Do not lint or fix minified files. let g:ale\_pattern\_options = { \ '\.min\.js$': {'ale\_linters': [], 'ale\_fixers': []}, \ '\.min\.css$': {'ale\_linters': [], 'ale\_fixers': []}, \} " If you configure g:ale\_pattern\_options outside of vimrc, you need this. let g:ale\_pattern\_options\_enabled = 1

Buffer-local variables for settings always override the global settings.

5.xvii. How can I configure the height of the list in which ALE displays errors?

To set a default height for the error list, use the

g:ale\_list\_window\_size

variable.

" Show 5 lines of errors (default: 10) let g:ale\_list\_window\_size = 5

5.xviii. How can I see what ALE has configured for the current file?

Run the following to see what is currently configured:

:ALEInfo

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.