问题
I followed https://github.com/prettier/vim-prettier instructions and added
// @format
at the top of my .js
files.
I installed prettier with
cd ~/.vim/bundle/
git clone https://github.com/prettier/vim-prettier
but I can't see to get Prettier to work, either on file save or by using :Prettier
at the ex command line. Nothing changes
At the command line, when I run
$ npx prettier-eslint $PWD/'**/*.js'
I get newly formatted output as expected.
package.json
includes
"devDependencies": {
"eslint": "^6.8.0",
"eslint-plugin-jest": "^23.6.0",
"jest": "^25.1.0",
"prettier-eslint-cli": "^5.0.0"
回答1:
IF you are manually installing the prettier plugin then you have missed one step
what you will have to do is
cd ~/.vim/bundle/
git clone https://github.com/prettier/vim-prettier
cd vim-prettier
cd inside prettier root directory and doyarn install
ornpm install
the third step is important because you don't have prettier executable globally or in your project installed and I see in your question you have missed that step
And if you don't have prettier in your project ( in which you are running the format command ) or in vim-prettier
directory or globally installed you can specify prettier executable let g:prettier#exec_cmd_path = "~/path/to/cli/prettier"
Also note that i was using branch release/1.x
not the master for stability
来源:https://stackoverflow.com/questions/60105065/how-to-get-prettier-working-with-js-files-in-vim