I have Visual Studio Code Insiders installed. Basically I've installed Go extension from Microsoft and written simple hello world app. Now I always use spaces to indent my code, but I saw that it changed to tabs of size 4. So I thought: yay, what a nice extension, now I can start to write my code.
Then I remembered, that the default code indent from gofmt should be 8 as tabs. And I checked. gofmt main.go indeed outputs my code with tabs of size 8. But vscode keeps doing tabs of size 4. I thought maybe it doesn't even call gofmt but when I go RPM->Format document with - it actually does. But still, tabs of size 4. What am I doing wrong in this scenario?
"editor.renderWhitespace": "all",
"editor.fontFamily": "Hack",
"editor.fontSize": 12,
"editor.minimap.enabled": false,
"editor.fontLigatures": true,
"workbench.editor.enablePreview": false,
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.cursorSmoothCaretAnimation": true,
"editor.detectIndentation": false
Those my only editor settings and I dont have any custom settings regarding Go extension
go fmt uses tab characters ("\t") to indent the beginning of a line. How a tab is displayed (tab width) is up to your text editor or IDE. I have Tab Width set to 4 in my text editors. My terminal program uses a tab width of 8.
For example, for xed,
Editor Preferences
Tabs
Use the Tab width spin box to specify the width of the space that xed
inserts when you press the Tab key.
Select the Insert spaces instead of tabs option to specify that xed
inserts spaces instead of a tab character when you press the Tab key.
Related
This is my setting:
but my code still show white space not the upper style:
I have solve this question.This is my steps:
First,open your Editor->Code Style,then uncheck the Detect and using existing file indents for editing option;
Second,open your Editor->Code Style->java , check the use tab character option.
You can try.
I have soft tabs enabled, but not only is the editor putting actual tabs in instead of spaces, if I type [space][space], it converts it to a tab. I've read that the editor tries to read existing files to guess your settings (I have Autodetect turned off if that matters), so I tried with a new file. Here is the relevant section of my settings file (which I edited through the GUI):
"ace": {
"#guessTabSize": false,
"#newLineMode": "unix",
"#tabSize": 2,
"#useSoftTabs": true
},
When I turn off soft tabs, it stops converting spaces into tabs, but either way, when I hit enter at the end of a line, autoindent uses a tab instead of spaces.
Cloud9 doesn't have any code that can convert two spaces into a tab.
When soft tabs is enabled it moves cursor as if two spaces is a tab, but that doesn't change characters in the file.
Enter at the end of line copies indentation from that line, and doesn't depend on tab settings.
How do you actually go about changing the "editor.tabSize" and "editor.insertSpaces" values for vscode? I've opened File > Preferences > User Settings and added:
// Place your settings in this file to overwrite the default settings
{
// Controls the rendering size of tabs in characters. If set to auto, the value will be guessed based on the opened file.
"editor.tabSize": 4,
// Controls if the editor will insert spaces for tabs. If set to auto, the value will be guessed based on the opened file.
"editor.insertSpaces": true,
}
However, when I open an html file with two-space tabs, pressing tab inserts two spaces, and when I open a file that uses \t tabs, pressing tab inserts \t.
What am I doing wrong that causes vscode to not respect my settings?
There is a trailing comma in your snippet and currently VSCode fails to understand settings with malformed JSON. I am happy to say that with the next update, this issue should be fixed :)!
The working version of settings is:
// Place your settings in this file to overwrite the default settings
{
// Controls the rendering size of tabs in characters. If set to auto, the value will be guessed based on the opened file.
"editor.tabSize": 4,
// Controls if the editor will insert spaces for tabs. If set to auto, the value will be guessed based on the opened file.
"editor.insertSpaces": true
}
In Eclipse, there are two distinct features: one to format a selection, one to just indent the lines, see e.g. Difference between Ctrl+Shift+F and Ctrl+I in Eclipse. I found the format feature in Visual Studio but how can I actually just indent the lines? Is there some built-in command for that or possibly a 3rd party add-on?
Note: I have asked a couple of friend that use VS daily and they all tried to persuade me that I am looking for the format feature. No I'm not. I tried to live with it for a while and it is just a different feature. I am after the indent/reindent only.
EDIT: I am looking for a clever indent, sometimes called reindent, which is different to just pressing Tab or Shift+Tab (increase/decrease indent level). The indent feature in Eclipse behaves like this:
It places a beginning of current line at the right position, no matter where that line was starting before. So instead of thinking whether you need to increase or descrease the indent level (Tab or Shift+Tab), you just invoke the indent command and it will do the right thing.
Invoking the indent command on an empty line places the caret at the right position for the user to start typing.
It never influences any character beyond the first non-whitespace character.
If you just want to indent some lines, you can
Select them.
Press Tab.
To un-indent them, replace the second step to: Shift+Tab.
You can find more VS shortcuts here.
There are toolbar buttons for this, with wonderfully inconsistent labels (at least in the Visual Studio 2013 I'm using)...
In the "Text Editor" toolbar (in my default setup), I have to buttons whose tooltips are:
"Decrease Line Indent"
"Increase Line Indent"
In the "Customize" dialog, on the "Commands" tab (with "Toolbar" set to "Text Editor") they appear in the list as:
"Line Unindent"
"Line Indent"
And finally, if you press the "Add Command..." button (on the "Customize" dialog) to produce the "Add Command" dialog and select the "Edit" category, you'll see these two entries:
"Outdent"
"Indent"
As far as I can tell, these are all the same two commands, which should do what you want.
They also appear in the Edit -> Advanced menu, at the very bottom.
----- Edit -----
I believe you might be able to turn off all of the "formatting" actions except for indentation, so that when you use the "auto-format" command, only the indentation is "formatted" for you. (Of course this prevents you from ever using the rest of the formatting features without turning them on again, but if you don't use them, this might work!)
When I indent by tabbing "Tab" key, the tab is replaced by 4 spaces. Does anyone know how could I set it to normal?
At the bottom of the editor window there is a menu for tab size, you can set the desired width there as well as turning on soft tabs which inserts spaces instead of tabs but treats them as tabs when editing. Your choice will be saved based on the active file type so make sure to set it when in a python file.