Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vs code, code formatting is not working. #622

Closed
3 tasks done
lzl124631x opened this issue Jan 5, 2018 · 13 comments
Closed
3 tasks done

vs code, code formatting is not working. #622

lzl124631x opened this issue Jan 5, 2018 · 13 comments

Comments

@lzl124631x
Copy link

lzl124631x commented Jan 5, 2018

  • I have searched through existing issues
  • I have read through docs
  • I have read FAQ

Info

  • Platform: Win
  • Vetur version: 0.11.5
  • VS Code version: 1.19.1

Problem

I uninstalled all the extensions and reinstalled vetur several times, vue code formatter still doesn't work.

image

{
    "window.openFilesInNewWindow": "off",
    "explorer.confirmDelete": false,
    "[vue]": {
        "editor.formatOnSave": true,
                
    },
    "files.associations": {
        "*.vue": "vue"
    }
}

Reproducible Case

@lzl124631x
Copy link
Author

I found that formatting will happen when I save file, but only formats JS and CSS, html is not formatted.
image
But still ctrl+k, ctrl+f(command for code formatting) doesn't work.

@lzl124631x
Copy link
Author

https://github.com/vuejs/vetur/blob/master/docs/formatting.md. Where is this setting?

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

@lzl124631x
Copy link
Author

lzl124631x commented Jan 5, 2018

I added the following setting to .vscode/settings.json.

{
    "vetur.format.defaultFormatter.html": "js-beautify-html"
}

The formattingOnSave for HTML does work.

  • Why is the default html formatter disabled?
  • Can you add "where to add those json config"? You only listed those json but didn't say where to put it.

--

update: How to edit .vscode/settings.json?

ctrl + shift + p > Configure Language Specific Settings > Vue > Edit the file.

My current settings:

{
    "window.openFilesInNewWindow": "off",
    "explorer.confirmDelete": false,
    "[vue]": {
        "editor.formatOnSave": true,
                        
    },
    "files.associations": {
        "*.vue": "vue"
    },
    "vetur.format.defaultFormatter.html": "js-beautify-html"
}

@cmnzs
Copy link

cmnzs commented Jan 10, 2018

I think this has some more info about why it is disabled: #484

@liuguangyong93
Copy link

me too,Ctrl+K,Ctrl+F doesnot work, it has been resolved??

@HerringtonDarkholme
Copy link
Member

As @cmnzs has said, html formatting is disabled by default because our formatter doesn't work well enough.

@octref
Copy link
Member

octref commented Jan 16, 2018

@lzl124631x
I'm curious about why you are getting "No formatter installed" error.

If you remove this:

    "files.associations": {
        "*.vue": "vue"
    }

Do you still get that error?

@octref
Copy link
Member

octref commented Jan 31, 2018

@percy507 That is WRONG advice. You should not associate Vue with html.

@MrFoxPro
Copy link

MrFoxPro commented May 26, 2018

I solved this by removing all parameters in template tag (e.g. src, lang)

@gayanSandamal
Copy link

Mine is fixed.

  1. Install Prettier extension.
    URL - https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode
  2. Go to File > Preferences > Settings
  3. Add below,
    "prettier.singleQuote": true,
    "prettier.semi": false,
    "prettier.eslintIntegration": true
  4. Save.
  5. Try Alt + Shift + F

@arturmaiz
Copy link

Try go to vetur configuration, and change => "vetur.format.defaultFormatter.html": "js-beautify-html"

@songfs
Copy link

songfs commented Oct 28, 2020

me too,Ctrl+K,Ctrl+F doesnot work, it has been resolved??

this problem has been resolved?

@yogithesymbian
Copy link

I added the following setting to .vscode/settings.json.

{
    "vetur.format.defaultFormatter.html": "js-beautify-html"
}

The formattingOnSave for HTML does work.

  • Why is the default html formatter disabled?
  • Can you add "where to add those json config"? You only listed those json but didn't say where to put it.

--

update: How to edit .vscode/settings.json?

ctrl + shift + p > Configure Language Specific Settings > Vue > Edit the file.

My current settings:

{
    "window.openFilesInNewWindow": "off",
    "explorer.confirmDelete": false,
    "[vue]": {
        "editor.formatOnSave": true,
                        
    },
    "files.associations": {
        "*.vue": "vue"
    },
    "vetur.format.defaultFormatter.html": "js-beautify-html"
}

its work, thank you...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

10 participants