如何让 Prettier 在 vi​​m 中处理 js 文件? [英] How to get Prettier working with js files in vim?

查看:28
本文介绍了如何让 Prettier 在 vi​​m 中处理 js 文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了 https://github.com/prettier/vim-prettier 说明和添加

I followed https://github.com/prettier/vim-prettier instructions and added

// @format

在我的 .js 文件的顶部.

at the top of my .js files.

我安装了更漂亮的

cd ~/.vim/bundle/
git clone https://github.com/prettier/vim-prettier

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

在命令行,当我运行时

$ npx prettier-eslint $PWD/'**/*.js' 

我按预期获得了新格式化的输出.

I get newly formatted output as expected.

package.json

包括

"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

你要做的是

  1. cd ~/.vim/bundle/
  2. git clone https://github.com/prettier/vim-prettier
  3. cd vim-prettier cd 在 prettier 根目录下并执行 yarn installnpm install
  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

如果你的项目中没有 prettier(你在其中运行 format 命令)或 vim-prettier 目录或全局安装,你可以指定 prettier 可执行文件 let g:prettier#exec_cmd_path = "~/path/to/cli/prettier"

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"

另请注意,我使用的是 branch release/1.x 不是为了稳定性而使用的大师

Also note that i was using branch release/1.x not the master for stability

这篇关于如何让 Prettier 在 vi​​m 中处理 js 文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆