How to Set up Vue Files Formatting in vs Code?

Good day.

I have installed the "Vetur" plugin. And I have nice features for my Vue files (Syntax-highlighting, Snippet, Emmet, Formatting, Auto Completion, Debugging). But I do not understand how to edit formatting settings! it transforms my code from this:

var map = {
q:"й",w:"ц",e:"у",r:"к",t:"е",y:"н",u:"г",i:"ш",o:"щ",p:"з",a:"ф",s:"ы",d:"в",

to that:

var map = {
  q: "й",
  w: "ц",
  e: "у",
  r: "к",
  t: "е",
  y: "н",
  u: "г",
  i: "ш",
  o: "щ",

How can I edit that behavior?

1

2 Answers

Easier method is to install vetur octref.vetur extension and then add a .vscode>settings.json with following

{
    "editor.defaultFormatter": "octref.vetur",
    "vetur.format.defaultFormatter.html": "prettier",
    "vetur.format.defaultFormatter.css": "prettier",
    "vetur.format.defaultFormatter.postcss": "prettier",
    "vetur.format.defaultFormatter.scss": "prettier",
    "vetur.format.defaultFormatter.less": "prettier",
    "vetur.format.defaultFormatter.stylus": "stylus-supremacy",
    "vetur.format.defaultFormatter.js": "prettier",
    "vetur.format.defaultFormatter.ts": "prettier"
}
3

Vetur uses prettier to format js code. You can see how to configure it here. All options for prettier are here. But as far as I know, there is no way to adjust the wrapping behaviour of object field definition in prettier.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest