How to get Prettier working with js files in vim?

那年仲夏 提交于 2021-02-08 11:27:50

问题


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

  1. cd ~/.vim/bundle/
  2. git clone https://github.com/prettier/vim-prettier
  3. cd vim-prettier cd inside prettier root directory and do yarn install or npm 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!