From 151f9f857c415164f5865be270649a0797a0a7e7 Mon Sep 17 00:00:00 2001 From: w0rp Date: Sun, 19 Nov 2017 13:56:09 +0000 Subject: [PATCH] Add an FAQ entry explaining how to configure ALE for different buffers. --- README.md | 37 +++++++++++++++++++++++++++++++++++++ doc/ale.txt | 3 ++- 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 481e95a..1c69fb2 100644 --- a/README.md +++ b/README.md @@ -47,6 +47,7 @@ servers with similar enough protocols, like `tsserver`. 12. [How can I check JSX files with both stylelint and eslint?](#faq-jsx-stylelint-eslint) 13. [Will this plugin eat all of my laptop battery power?](#faq-my-battery-is-sad) 14. [How can I configure my C or C++ project?](#faq-c-configuration) + 15. [How can I configure ALE differently for different buffers?](#faq-buffer-configuration) @@ -640,3 +641,39 @@ 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](https://github.com/LucHermitte/local_vimrc) can be used for executing local vimrc files which can be shared in your project. + + + +### 5.xv. 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. + +```vim +" 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`. + +```vim +" 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. diff --git a/doc/ale.txt b/doc/ale.txt index 04f187d..ec201b1 100644 --- a/doc/ale.txt +++ b/doc/ale.txt @@ -414,7 +414,8 @@ including disabling ALE for certain buffers with |b:ale_enabled|. The |g:ale_pattern_options| setting can be used to configure files differently based on regular expressions for filenames. For configuring entire projects, the buffer-local options can be used with external plugins for reading Vim -project configuration files. +project configuration files. Buffer-local settings can also be used in +ftplugin files for different filetypes. ===============================================================================