Vim readme (#1058)

* Moved Vim info to its own editor folder, started drafting new README

* Finished first draft, ready for PR

* Testing Readme layout

* Removed vim folder
master
Erick Romero 2017-03-20 23:12:10 -06:00 committed by Christopher Chedeau
parent 389d9d0fad
commit 24f9cc3a71
1 changed files with 37 additions and 4 deletions

View File

@ -223,11 +223,15 @@ Emacs users should see [this
folder](https://github.com/jlongster/prettier/tree/master/editors/emacs)
for on-demand formatting.
### Vim
### 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 set formatprg=prettier\ --stdin
```
@ -235,7 +239,7 @@ This makes Prettier power the [`gq` command](http://vimdoc.sourceforge.net/htmld
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
```
@ -243,10 +247,39 @@ 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
Plug 'sbdchd/neoformat'
```
Then make Neoformat run on save:
```vim
autocmd BufWritePre *.js Neoformat
```
#### Customizing prettier in Vim
If your project requires settings other than the default prettier settings you can pass arguments to do so in your `.vimrc` or [vim project](http://vim.wikia.com/wiki/Project_specific_settings), you can do so:
```vim
autocmd FileType javascript set 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
```
### Visual Studio Code
Can be installed using the extension sidebar. Search for `Prettier - JavaScript formatter`