-
Notifications
You must be signed in to change notification settings - Fork 29k
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
Separate tab size and indent size #42740
Comments
This is similar to GNU coding style (except it's two columns per indent instead of four), so enabling this would make it possible to use vscode for editing code of all GNU projects. |
Ditto for standard Java style, but all of this is already discussed in #5394, this (almost exactly) a duplicate issue. |
I really wish a feature for separate tab size and indent size existed. As it is now, I cannot use vscode because it doesn't support tabsize = 8, indentsize=4. I find this odd because Visual Studio does support it. |
Another ping in support of this feature. For anyone curious, the rationale was recently discussed for the Atom editor as it similarly lacks this concept from Visual Studio, Emacs, Vim: atom/atom#21371 |
Without this functionality, editing Makefiles is hard, since tab is used as a special character in make recipes, which you'd want to have clearly standing out by using a tab width of 8. But this does not conflict with the fact that you'd want a smaller indentation (e.g. 2 or 4), using spaces, in the rest of the makefile. |
Just dropping in to ping this issue. I've been following it for years now hoping it would get implemented at some point. I currently get by using vs code by formatting the document using a formatter that converts all tabs to spaces. This is not an ideal solution and it'd be great to see this feature implemented to work in a similar way to visual studio. I'm actually at a bit of a loss as to why it's lower on the priority list than some of the other issues that have been tackled. Please address this! |
I would very much need this too, in my current project. |
I am quite surprised that VScode lacks this feature. I think among the universe of editors only KDE's Kate handles this correctly, even Vim sucks at mixed tab and space indents. However to add the original comment of @bevolz this feature should have three options / levels:
In those options the action for pressing
Otherwise the implementation with mixed tabs and spaces will be a great way to ruin the day of Python programmers. |
+1 In Atom editor I had a CSS hack to draw TAB as 8 characters while the editor was still thinking it is 4-char long: atom-text-editor .invisible-character.hard-tab {
margin-right: 4ch;
} Since Atom has been discontinued, I want to migrate to VS Code fully. Unfortunately, I have to return to Atom whenever I access the legacy code. |
It seems this feature was already implemented 3 years ago, but was partly reverted simply because people couldn't agree on the name of the property. There's plenty of duplicate tickets for this, such as #5394 and #135058 so I think there's gotta be enough support to prioritize this feature. |
Awesome to see progress on this, thanks @zeroimpl. Do you also plan to include that every n spaces convert to 1 tab automatically? |
@timll At this point, I think the most important part is getting the distinction between tab size and indent size into the code base. Things like converting spaces to tabs can be extended later on; in fact, how to properly convert between spaces and tabs can be contested and language-specific; for instance, should you convert only leading spaces, or also spaces e.g. in front of a trailing line comment? So better keep that discussion separate. |
The clink project uses code from GNU Readline, and Readline uses tabwidth=8, shiftwidth=4. Readline code is unreadable in vscode. I would dearly love to see vscode gain the ability for tab width and shift/indent width to be different. |
From the discussion in PR #155450 this issue should not have been closed. That PR doesn't satisfy the second bullet, which is critical to the proper behavior of mixed tabs+spaces. Having tab always inject spaces regardless of the tabsize setting is incorrect behavior. |
@brlcad That is not necessarily incorrect behavior, though I acknowledge that it might be incorrect behavior for your use case. For me, editing huge makefiles, where space and tab are semantically different, and the long-standing convention has been that tabs expand to 8 spaces, but code is logically indented by two spaces, it really is the correct behavior. (Not trying to diminish your situation; just pointing out that this change was not worthless) |
Oh no! Correct -- this is still very incomplete, then. In a file where "indent with Tabs" is enabled and indent is 4 and tabwidth is 8, then one press of Tab should insert 4 spaces, and a second insert of Tab should end up recognizing that 8 spaces will be equal to 1 tab, and should replace the 4 spaces with a tab character. |
@magicus, @brlcad didn't say it was "worthless". The statement was that the behavior is not yet correct. Which is an accurate assessment. It's great that at least display works now. |
@magicus I'd argue that it's inconsistent and thus incorrect in comparison with existing editors that support mixed indentation+tab width settings. Emacs and Vim, for example, handle Makefile indentation with separate mode and settings respectively as tab is baked into the file format. To make that behavior default will likely result in awkward settings for the lionshare of C/C++ code wanting support as described by this issue's bulleted points. Not satisfying this issue's criteria was also the primary point. I'm not arguing whether the PR has value for other cases. The PR that was used as justification to close this issue does not satisfy this issue's second itemized bullet which described specific expected behavior. |
At least as a short-term fix, you could run the unix |
I have several ways I can manually compensate. It's frustrating and time consuming to take the compensating actions (or to write an extension to do it). What I would be most likely to do is one of these:
|
Reopening since the replacing as many spaces as possible with tabs part is not implemented via #155450 |
Haven't touched an IDE for about 5+ years, so thought it might be a good idea to give VScode a try: completely wrong, what a big disappointment. Formatting is really a nightmare especially wrt. tab handling and lang specific settings do not exist or do not work at all. 10+ years ago eclipse was even better than this. So I'll ditch this stone age thingy and recommend our students to use Eclipse or IntellJ. |
This has now been fixed, the tab stuff at least. I don't know anything about the language settings though. |
@astrelsky It is not fixed. I am on the latest version and cannot find a way to configure VS Code to work as described in the original issue description:
If there is a way to achieve this, please let me know, because it seems to be either too obscure, or something that is implemented by some extension that I'm missing? I've set the I've just updated to Just a note: the above described behavior is with |
I wouldn't say that is the expected behavior unless it is documented to do so. As far as I know there is no feature to do so but I think it would be possible to do with something like the trim trailing whitespace on file save feature. |
@astrelsky If you want to get into semantics, it is the behavior that is being requested to be implemented as a new feature in the current issue (notice the It is not (or less) desirable to have this done as a part of file saving. There are situations where you also want to have a non-conforming indent (one that does not adhere to VSCode's configured indenting rules), and implementing this feature as part of "Save File" (i.e., reformatting the whole file on save) would disallow that use case, potentially introducing unwanted/pointless merge differences which most developers don't like to deal with during code reviews. It's better to leave the file alone at save time and just apply the indenting rules at edit time, only for the edited lines. I'm not trying to nitpick or anything. These are just rules that most projects tend to follow. Leave existing formatting alone, and just apply the user's settings as they type. |
Visual Studio Code have not appear to have the ability to do the Tools->Options Tab settings of Visual Studio Professional where you can specify that tabs are 8 spaces but the indent size if 4? All our code uses that style and many other editors let you do this, but Visual Studio Code doesn't seem to support this. I've tried lots of things in Visual Studio Code but not found any combination of settings that work.
Using Visual Studio Code 1.19.3 (and also Visual Studio 2015 (and Professional 2012)).
In Visual Studio, setting tabs at 8 and spaces at 4 means (for a blank line):
The text was updated successfully, but these errors were encountered: