1、在.vimrc中添加
配置没有安装成功的话
git clone https://github.com/prettier/vim-prettier
Plug 'prettier/vim-prettier', { 'do': 'yarn install', 'for': ['javascript', 'typescript', 'css', 'less', 'scss', 'json', 'graphql', 'markdown', 'vue', 'yaml', 'html', 'php'] }
let g:prettier#autoformat = 0
let g:prettier#config#print_width = 120
autocmd BufWritePre *.js,*.json,*.css,*.scss,*.less,*.graphql,*.php Prettier
2、这样你的vim就可以:w就可以自动格式化代码了,
如何想要git commit hook格式化代码的话,请参考
https://blog.csdn.net/qq_35774849/article/details/107070026