简体   繁体   English

如何让 Prettier 在 vi​​m 中处理 js 文件?

[英]How to get Prettier working with js files in vim?

I followed https://github.com/prettier/vim-prettier instructions and added我按照https://github.com/prettier/vim-prettier说明添加了

// @format

at the top of my .js files.在我的.js文件的顶部。

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.但我看不到让 Prettier 工作,无论是在文件保存上还是在 ex 命令行中使用:Prettier 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"

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 cd vim-prettier cd 在 prettier 根目录中并执行yarn installnpm 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"如果您的项目(在其中运行格式命令)或vim-prettier目录或全局安装中没有更漂亮的文件,您可以指定更漂亮的可执行文件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另请注意,我使用的branch release/1.x不是为了稳定性而使用的 master

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM