Open vimrc
:
vim ~/.vim/vimrc
Add Vundle plugin to vimrc:
Plugin 'prettier/vim-prettier'
Save and install within Vim:
:PluginInstall
Then either install prettier
globally:
# with npm
npm install -g prettier
# or with yarn
yarn global add prettier
Or within the local bundle repository itself:
cd ~/.vim/bundle/vim-prettier
# with npm
npm install
# or with yarn
yarn
Now you can run prettier in Vim:
:Prettier
Vim 8+:
:PrettierAsync
Make sure to overwrite default prettier configuration. E.g.,
let g:prettier#config#bracket_spacing = 'true'
let g:prettier#config#jsx_bracket_same_line = 'false'
Running before saving in Vim:
let g:prettier#autoformat = 0
autocmd BufWritePre *.js,*.jsx,*.mjs,*.ts,*.tsx,*.css,*.less,*.scss,*.json,*.graphql,*.md,*.vue PrettierAsync