Convert 2 spaces to tabs in Visual Studio Code - visual-studio-code

I was editing a project, as I have been for months, and randomly only one of my files converted all of its tabs into two spaces. I use "4 spaces" for my tabs, now this one single file decided to become 2 spaces. How can I fix this and convert this file back to 4 spaces? It is only affecting this file, all other files still use 4 spaces.
This thing is just buggy. It is now back to 4 spaces and I have no idea why.

Try going to settings (CTRL+, or CMD+, on Mac) and search for 'detect indentation'.
Play around with that setting as well as with the Tab Size setting. When you're done, go to your file, select all content (CTRL+A or CMD+A on Mac), unindent everything (SHIFT+TAB), then open the command pallete and search for 'Reindent'.
Click the 'Reindent Lines' option and see where it gets you.
Also, check if you have a .vscode folder in your project. It may contain settings that override your global vscode settings.

Related

How to display more files on top tab in VS Code?

Is there a way to configure VS Code to increase the number of files that are able to be displayed across the tabs at the top?
There are currently just 4 files1 visible in that top area, but ~10 would be ideal:
Example
Sublime text uses smaller font on file names (despite similar font size of the code itself), and so allows about twice as much space for displaying files:
Current work around
I hit opt + command + right arrow a few times to quickly survey open files.
Ideas
Perhaps open files could be quickly surveyed (without key presses) if it is possible to:
Expand the area to have more than 1 row of files
Configure VS Code to show only part of the filename
Use smaller font on the file names (not the code itself), similar to sublime text
Something else?
1 The habits of using long file names, and having a lot of files open at the same time don't help, I'm aware of that.
workbench.editor.tabSizing
There's the "workbench.editor.tabSizing": "shrink" setting value, which is documented as so:
Allow tabs to get smaller when the available space is not enough to show all tabs at once.
(the default value for workbench.editor.tabSizing) is "fit".
workbench.editor.wrapTabs
As other have mentioned, there's the workbench.editor.wrapTabs setting, which you can find more about in this Q&A: Multirow Tabs for VSCode.
TL;DR from the setting's description:
Controls whether tabs should be wrapped over multiple lines when exceeding available space or whether a scrollbar should appear instead. This value is ignored when #workbench.editor.showTabs# is disabled.
git.decorations.enabled
You can shave a few pixels by disabling git decorations if you're working on a git project (of course- this is only if you're okay with disabling git decorations). Git decorations add letter indicators to the tab handles that summarize what has changed about those files. Ex. "M" means the file has been modified, and "A" means it has been added.
"git.decorations.enabled": false
workbench.editor.tabCloseButton
You can shave a few pixels by disabling the close button on tabs (if you're okay with that (you'll still be able to close the tab with the associated keyboard shortcut, or by middle-clicking the tab handle)):
"workbench.editor.tabCloseButton": "off"
workbench.editor.showTabs
If your aim is really to declutter, you can take the hardcore/nuclear route and do:
"workbench.editor.showTabs": false,
Et voila! Now the tab handles take up zero space because they're gone :D (and you can navigate tabs using ctrl+tab and ctrl+shift+tab (that's on Windows and Linux- not sure what it is on MacOS), or by using the Explorer view's "Open Editors" section (you might need to enable it first under the three-dots menu))

How to allow tab to always insert a set number of spaces in Visual Studio (2017)?

I am using Visual Studio 1.19 on Ubuntu (deb). I already killed all the IntelliSense stuff and I wanted to also update tab behaviour. I want a tab to be just a tab. Sometimes when I am commenting (e.g. in C++), it tries to align with the line above and matches that line vertically resulting in more or less then 4 spaces that I desire. I tried playing with User Settings with no luck.
Which settings do I need to amend to achieve specified number of tabs at all times?

Use tab indentation for one-off file when Eclipse is configured to use spaces indentation without chanding preferences

I'm using Eclipse for PHP Developers (PDT). Normally I use spaces instead of tab characters for indentation. However, I'm editing someone else's file who indents using tabs and I want to preserve indentation style while editing their file. This is turning out to be difficult because whenever I press the Tab key it inserts spaces. I don't want to change my configuration to use spaces instead of tabs as I'll have to remember change it back. Is there a way I can insert a literal tab character?
I've tried copying a existing tab character in the file yet past results in spaces being inserted!
While I haven't found a way of inserting a literal tab character, with the AnyEdit Tools add-on installed I've found this simple procedure works for me:
Edit the file ignore the whitespace inconsitencies.
Once finished edits, right-click and select Convert > Spaces to Tabs.
Should work the other way round if one was normally used to Tab indentation.

Eclipse indents new line with tabs instead of spaces

I've followed all the suggestions here.
When I press return, I get a new line that is indented with tabs instead of spaces.
If I backspace to clear the tabs, and then press TAB a series of times, it correctly indents with spaces.
I'm pretty sure I have all my settings set up correctly. I created a new Code Style > Formatter policy for every language in the project, and specified to always use spaces. It seems as though these settings are partially active (ex: when I press tab), but inactive when I use return. I tried restarting Eclipse. I'll try restarting the computer now...
I'm using Mac OS X 10.9.2 and a Liferay Developer Studio (1.6.3.v201312111844) version of Eclipse (not sure which Eclipse build its based on though).
Can anyone think of another setting/solution to ensure that newlines are created with spaces instead of tabs? I recently saw http://editorconfig.org/, and I'm wondering if there's some interference.
Thanks for any suggestions
If the file has existing lines that are using tabs, then Enter will respect that and try to create new lines in a similar way (see this comment by topchef for a solution). Also, it could be something in Liferay Studio's proprietary settings is overriding Eclipse standard preferences (as suggested by user John).
Keep in mind that each type of editor in Eclipse can have its own preferences and perhaps that's what you're running into here. You can try to find them all by opening Preferences and searching for "indent" in the search field. That will show all the preferences pages where indentation can be configured.
Also note that the Formatter settings don't have any affect on as-you-type formatting; that's for when you select a file or group of files or part of a file and choose Source > Format from the menu.

Indentation issue using sublime text 2

I have the following problem.
I use ubuntu 12.04 and sublime-text-2 or gedit.
Sometimes i copy/paste something in a haml/ruby file, i indent it at 2 spaces, but when i push it up to github, the indentation is all wrong and not only the part I've copy/pasted. In my editor looks good.
If I open the file with LibreOffice/LeafPad the identation is like on github, but i wanna have it working on ST2.
Any suggestions?
To have correct indent across the service you should not use hard tabs
http://opensourcehacker.com/2012/05/13/never-use-hard-tabs/
You can achieve this functionality in Sublime Text 2 with a tab policy setting:
http://opensourcehacker.com/2012/05/11/sublime-text-2-tips-for-python-and-web-developers/#Configure_sane_tab_and_whitespace_policy_and_other_settings
Also not that you might need to choose new policy for existing files from View > Indentation menu.
You can also mass-convert existing files away from tabs.
With Sublime Text 2:
http://opensourcehacker.com/2012/05/11/sublime-text-2-tips-for-python-and-web-developers/#Converting_existing_files_to_use_spaces_instead_of_tabs
... or batch convert the whole project:
http://miohtama.github.com/vvv/tools/expandtabs.html