Prevent Visual Studio Code from replacing tabs with spaces on save - visual-studio-code

My problem is not present while editing a file, like here: Spaces to tabs in Visual Studio Code
VSC converts all tabs to spaces when I save the file. How could I stop that stupid behavior?
This are my actual user settings:
{
"editor.insertSpaces": false,
"editor.detectIndentation": false
}
Further informations:
"editor.formatOnSave": false

Wish I understood more about what's happening here, but in my case, what finally worked (for now) was unchecking "Editor: Insert Spaces" in my user prefs. Without this, disabling Save on Format didn't seem to help. ¯\_(ツ)_/¯

I had an extension which overrides the default behaviour:
https://marketplace.visualstudio.com/items?itemName=lonefy.vscode-JS-CSS-HTML-formatter

Related

Change line guide frequency in vscode

I have some dart code I am looking at in vscode.
The dart code uses 4 space indentation (literal 4 space, opposed to tabs).
When I view the code in vscode, it is putting line guides every two spaces. This doesn't make any sense since the indentation only occurs every 4 spaces. So it is essentially showing line guides to no where.
Observe the following screenshot
How can I fix this???
Go to Files > preferences > settings > select:Editor-Tab size You can change tab-size there.
Note: If you are using Eslint or Prettier make sure your editor settings are not overriding
The problem is that editor.tabsize setting is being overridden by language specific settings.
To fix I put the following in my user settings.json file...
"[dart]": {
"editor.tabSize": 4,
"editor.insertSpaces": true,
"editor.detectIndentation": false
},

Beautify on save in VS code?

I just installed a beautify extension for vs code
I want to have my code beautified whenever I save a file, but can't figure out how to configure it that way.
It says
Beautify on save will be enabled when "editor.formatOnSave" is true.
But i have no idea where to put it exactly as I cannot find the default option in any of the files.
I'm trying to switch to VS code and figure things out.
For Windows click on 'File' -> Preferences -> Settings. Then search for editor.formatOnSave, and put "true" instead of "false"
For Mac click on 'Code' (top left of screen, to the left of 'File', 'Edit', and 'View') -> Preferences -> Settings -> enter the term 'editor.formatOnSave' in the search settings box at the top of the page. Click on the tick to mark it as true.
Go to file--> preferences --> settings
In search type formatter and in default formatter select : prettier code formatter as shown in below screenshot.
I visited this question because my beautify was not working in VS code
And Adding the above mentioned setting fixed my issue but if you want your beautify to solve linting issue as well then you gonna have to added the below setting along with the above like this : (Hope this helps anyone)
{
"editor.formatOnSave": true,
"tslint.autoFixOnSave": true
}
My setup for Javascript relies on ESlint and Prettifier.
I got the autoformat/autofix configuring:
"editor.codeActionsOnSaveTimeout": 2000,
"editor.codeActionsOnSave": {
"source.fixAll": true
}
In addition to the other answers, it may be that you have to override or replace your defaultFormatter settings in your settings.json file if you use other formatters.
When I installed Prettier, for example, it installed as the default formatter for several different languages, including HTML, which is broken for Django HTML templates.
Open settings.json file (SO guide if you get stuck
In my case, prettier had installed as default as follows, but you might have another formatter instead:
"[html]": {
"editor.defaultFormatter": "esbenp.prettier-vscode"
},
If you remove esbenp.prettier-vscode and start typing a few characters, VScode will highlight in red you have entered an invalid formatter and suggest valid values. Once you have installed Beautify, you can replace this entry with: HookyQR.beautify
And make sure to follow the other answers on this post.

Disable vscode clear/remove not used code when save file

When I save file, VSCode auto cleans the not used code, How to Disable it? I want to make VSCode not to delete any line of my code.
Go to Visual Studio Code's settings page in JSON format then remove the line
"source.fixAll": true,
this line you will find inside of this object
"editor.codeActionsOnSave": {
},
After finding and testing, it can be configured at Workspace Settings > Go configurartion, override "go.formatOnSave": false, on the right side, disable formatting then the code will not be auto cleaned.
EDIT: Later then I meet this issue .

Disable word wrap in VS Code

I have the following settings in VS code to disable word wrap
"editor.wordWrap": "off",
"editor.wordWrapColumn": -1
Word wrap is still not turned off. This makes VS Code really unfriendly to use on my laptop with a small screen.
Is there some additional setting I can use?
I am on 1.17.1.
Are you using markdown? vscode changes some default settings:
"[markdown]": {
"editor.wordWrap": "off"
}
On version 1.17.1 try changing default settings (not overriding with user settings) to:
"editor.wordWrap": "off",
"editor.wordWrapColumn": 80,
That works for me. And you can also edit the user settings (via Code or directly editing settings.json file on AppData\Roaming\Code\User (at my computer) by just adding the wordWrap line.
After changing settings always close and reopen both VS Code and the file (as it saves it opened).
If you are dealing with a file that has very long lines, this could be the issue you are facing.
https://github.com/microsoft/vscode/issues/21124
It seems it is made that way by design to prevent slow load times. It can be manually overridden with ALT + Z shortcut while the file is opened. After that, it reverts to the old setting and you have to do it again.

VSCODE inserting spaces via format on save

VSCODE seems to be inserting spaces everywhere in my html code. I checked the settings and it's the following which is causing it: "editor.formatOnSave": true
Example:
How do I configure this to stop inserting spaces?
I have the following set :
"editor.formatOnSave": false,
"editor.insertSpaces": false
Now it is not inserting spaces. Hope it helps
Mine was caused by an extension JS/ CSS formatter, after i uninstalled and restart vscode works great.
After spending hours wondering why my django static links are broken smh
When saving, Visual Studio inserted a lot of spaces. This happened after an update of Visual Studio. This problem was because of an extension called Bracket Pair Colorizer. What I did was, uninstall and reinstall, and that solved the problem. I suggest to check all your extensions. It could be one of them.
I disabled the option of HTML formatting and no more space when saving files.
Settings > Extensions > HTML > Format: Enable
Enable/disable default HTML formatter.
What was the case with me is that I had the option Editor: Format on save mode to be set to file, this in combination with format on save would mean VS Code will try to format the entire file, resulting in spaces as defined in the formatter.
Change this to be modifictions, and VS Code will only save the lines you have made changes in.