Add warning about vanilla Vim integration, recommend Neoformat (#1568)
* Add warning about vanilla Vim integration Fixes https://github.com/prettier/prettier/issues/743 Fixes https://github.com/prettier/prettier/issues/1191 Fixes https://github.com/prettier/prettier/issues/1466 * Recommend Neoformat over vanilla Vim integration See https://github.com/prettier/prettier/issues/743 See https://github.com/prettier/prettier/issues/1191 See https://github.com/prettier/prettier/issues/1466 * Remove vanilla Vim integration from README Since it's relatively broken, we don't want to recommend it. See https://github.com/prettier/prettier/pull/1568#issuecomment-300270038 This also adds a TOC link for the "Other `autocmd` events" section, which was previously missing.master
parent
93472d0998
commit
ebe85917a3
46
README.md
46
README.md
|
@ -16,8 +16,7 @@
|
|||
* [Atom](#atom)
|
||||
* [Emacs](#emacs)
|
||||
* [Vim](#vim)
|
||||
+ [Vanilla approach](#vanilla-approach)
|
||||
+ [Neoformat approach](#neoformat-approach)
|
||||
+ [Other `autocmd` events](#other-autocmd-events)
|
||||
+ [Customizing Prettier in Vim](#customizing-prettier-in-vim)
|
||||
* [Visual Studio Code](#visual-studio-code)
|
||||
* [Visual Studio](#visual-studio)
|
||||
|
@ -304,42 +303,6 @@ for on-demand formatting.
|
|||
|
||||
### Vim
|
||||
|
||||
For Vim users, there are two main approaches: one that leans on [sbdchd](https://github.com/sbdchd)/[neoformat](https://github.com/sbdchd/neoformat), which has the advantage of leaving the cursor in the same position despite changes, or a vanilla approach which can only approximate the cursor location, but might be good enough for your needs.
|
||||
|
||||
#### Vanilla approach
|
||||
|
||||
Vim users can add the following to their `.vimrc`:
|
||||
|
||||
```vim
|
||||
autocmd FileType javascript setlocal formatprg=prettier\ --stdin
|
||||
```
|
||||
|
||||
If you use the [vim-jsx](https://github.com/mxw/vim-jsx) plugin without
|
||||
requiring the `.jsx` file extension (See https://github.com/mxw/vim-jsx#usage),
|
||||
the FileType needs to include `javascript.jsx`:
|
||||
|
||||
```vim
|
||||
autocmd FileType javascript.jsx,javascript setlocal formatprg=prettier\ --stdin
|
||||
```
|
||||
|
||||
This makes Prettier power the [`gq` command](http://vimdoc.sourceforge.net/htmldoc/change.html#gq)
|
||||
for automatic formatting without any plugins. You can also add the following to your
|
||||
`.vimrc` to run Prettier when `.js` files are saved:
|
||||
|
||||
```vim
|
||||
autocmd BufWritePre *.js :normal gggqG
|
||||
```
|
||||
|
||||
If you want to restore cursor position after formatting, try this
|
||||
(although it's not guaranteed that it will be restored to the same
|
||||
place in the code since it may have moved):
|
||||
|
||||
```vim
|
||||
autocmd BufWritePre *.js exe "normal! gggqG\<C-o>\<C-o>"
|
||||
```
|
||||
|
||||
#### Neoformat approach
|
||||
|
||||
Add [sbdchd](https://github.com/sbdchd)/[neoformat](https://github.com/sbdchd/neoformat) to your list based on the tool you use:
|
||||
|
||||
```vim
|
||||
|
@ -373,15 +336,12 @@ If your project requires settings other than the default Prettier settings, you
|
|||
|
||||
```vim
|
||||
autocmd FileType javascript setlocal formatprg=prettier\ --stdin\ --parser\ flow\ --single-quote\ --trailing-comma\ es5
|
||||
```
|
||||
|
||||
Each command needs to be escaped with `\`. If you are using Neoformat and you want it to recognize your formatprg settings you can also do that by adding the following to your `.vimrc`:
|
||||
|
||||
```vim
|
||||
" Use formatprg when available
|
||||
let g:neoformat_try_formatprg = 1
|
||||
```
|
||||
|
||||
Each option needs to be escaped with `\`.
|
||||
|
||||
### Visual Studio Code
|
||||
|
||||
Can be installed using the extension sidebar. Search for `Prettier - JavaScript formatter`.
|
||||
|
|
Loading…
Reference in New Issue