From 9ee3e581d49bc5c6447b5070b76b26440f8c6bf2 Mon Sep 17 00:00:00 2001 From: Jack Franklin Date: Wed, 28 Jun 2017 17:20:34 +0100 Subject: [PATCH] (docs): Document using Prettier + Vim using ALE (#2333) --- README.md | 2 +- editors/vim/README.md | 56 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 56 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 75a7a377f..6ec658217 100644 --- a/README.md +++ b/README.md @@ -583,7 +583,7 @@ for on-demand formatting. ### Vim -Vim users can simply install either [sbdchd](https://github.com/sbdchd)/[neoformat](https://github.com/sbdchd/neoformat) or [mitermayer](https://github.com/mitermayer)/[vim-prettier](https://github.com/mitermayer/vim-prettier), for more details see [this directory](https://github.com/prettier/prettier/tree/master/editors/vim) +Vim users can simply install either [sbdchd](https://github.com/sbdchd)/[neoformat](https://github.com/sbdchd/neoformat), [w0rp](https://github.com/w0rp)/[ale](https://github.com/w0rp/ale), or [mitermayer](https://github.com/mitermayer)/[vim-prettier](https://github.com/mitermayer/vim-prettier), for more details see [this directory](https://github.com/prettier/prettier/tree/master/editors/vim). ### Visual Studio Code diff --git a/editors/vim/README.md b/editors/vim/README.md index b7893c326..5d5e55d1d 100644 --- a/editors/vim/README.md +++ b/editors/vim/README.md @@ -13,6 +13,10 @@ + [vim-prettier - Installation](#vim-prettier---installation) + [vim-prettier - Usage](#vim-prettier---usage) + [vim-prettier - Configuration](#vim-prettier---configuration) + * [ALE](#ale) + + [ALE - Installation](#ale--installation) + + [ALE - Usage](#ale--usage) + + [ALE - Configuration](#ale--configuration) * [Running manually](#running-manually) + [Running Prettier manually in Vim](#running-prettier-manually-in-vim) @@ -21,7 +25,7 @@ ## Vim and Prettier integration -Vim integration can be achieved by installing either [sbdchd](https://github.com/sbdchd)/[neoformat](https://github.com/sbdchd/neoformat) or [mitermayer](https://github.com/mitermayer)/[vim-prettier](https://github.com/mitermayer/vim-prettier) +Vim users can simply install either [sbdchd](https://github.com/sbdchd)/[neoformat](https://github.com/sbdchd/neoformat), [w0rp](https://github.com/w0rp)/[ale](https://github.com/w0rp/ale), or [mitermayer](https://github.com/mitermayer)/[vim-prettier](https://github.com/mitermayer/vim-prettier). -------------------------------------------------------------------------------- @@ -197,6 +201,56 @@ g:prettier#config#parser = 'flow' ``` -------------------------------------------------------------------------------- +### ALE + +### ALE - Installation + +[ALE](https://github.com/w0rp/ale) is an asynchronous lint engine for Vim that +also has the ability to run formatters over code, including Prettier. For ALE +to work you'll have to be using either Vim 8 or Neovim as ALE makes use of the +asynchronous abilities that both Vim 8 and Neovim provide. + +The best way to install ALE is with your favourite plugin manager for Vim, such +as [Vim-Plug](https://github.com/junegunn/vim-plug): + +```vim +Plug 'w0rp/ale' +``` + +You can find further instructions on the [ALE repository](https://github.com/w0rp/ale#3-installation). + +### ALE - Usage + +Once you've installed ALE you need to enable the Prettier fixer: + +```vim +let g:ale_fixers = {} +let g:ale_fixers['javascript'] = ['prettier'] +``` + +ALE will first use the Prettier installed locally (in +`node_modules/.bin/prettier`) before looking for a global installation. + +You can then run `:ALEFix` in a JavaScript file to run Prettier. + +## ALE - Configuration + +To have ALE run `prettier` when you save a file you can tell ALE to run +automatically: + +```vim +let g:ale_fix_on_save = 1 +``` + +To configure Prettier, you can set `g:ale_javascript_prettier_options`. This is +a string that will be passed through to the Prettier command line tool: + +```vim +let g:ale_javascript_prettier_options = '--single-quote --trailing-comma es5' +``` + +-------------------------------------------------------------------------------- + ### Running manually #### Running Prettier manually in Vim