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

Navigate Soft Tabs As If They Are Hard Tabs #2798

Closed
jednano opened this issue Feb 8, 2016 · 26 comments · Fixed by #107126
Closed

Navigate Soft Tabs As If They Are Hard Tabs #2798

jednano opened this issue Feb 8, 2016 · 26 comments · Fixed by #107126
Assignees
Labels
editor-commands Editor text manipulation commands feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-testplan
Milestone

Comments

@jednano
Copy link

jednano commented Feb 8, 2016

If implemented properly, the user should not even realize they are working with spaces for indentation, which is one of the greatest pains of a person who prefers tabs for indentation working on a file that has spaces for indentation.

Spaces should be treated as if they were tabs under the following conditions

  1. The text editor's insertSpaces setting is true (or leading spaces precede tab characters on a line).
  2. The cursor is within the range of leading indentation.
    1. We can't possibly guess where indentation ends and alignment begins, so this includes all leading whitespace (both spaces and tab characters, assuming each tab character is the width of tabSize).
  3. The user attempts to do any of the following:
    1. Arrow-key navigation.
    2. Backspace.
    3. Delete.
    4. Mouse selections (more difficult to implement, I'm sure).

Examples of how spaces are treated as tabs

  1. If the cursor is at the beginning of the line and the right arrow key is pressed, the cursor jumps tabSize spaces, instead of just one.
  2. If tabSize is 4 and the cursor is on position 6 (between tabs) and the left arrow key is pressed, the cursor jumps 2 spaces instead of 4, landing gracefully on a tab stop.
  3. If tabSize is 4 and the cursor is on position 4, but the first non-whitespace character is on position 6, then the space on position 5 is assumed to be alignment; thus, a right arrow key press would land on position 5.
  4. The backspace and delete keys should eliminate up to tabSize spaces in one batch, so that a single undo operation restores all of the spaces that were deleted.
  5. Ideally, mouse selections would also be restricted to tab stops, so you can't individually select the spaces between a single indent.

Exposing an editor setting

  • Perhaps an editor setting called navigateSoftTabsAsHard should be exposed for those who wish to opt in or out of this feature. The default value is debatable.
@jednano
Copy link
Author

jednano commented Feb 8, 2016

The mere existence of TabSanity and the fact that it has been downloaded 1596 times is a testament that I'm not alone in these frustrations.

@alexdima alexdima self-assigned this Feb 8, 2016
@jamesmenera
Copy link

@jedmao does TabSanity work in vscode? Or are you saying they should add it? Because this behavior is killing me slowly. Is there a work around for this? I care about 1, 2, 3 the most.

@jednano
Copy link
Author

jednano commented Feb 10, 2016

@jamesmenera, TabSanity does not work in vscode. I'm proposing it be baked into the editor itself. There is no workaround, currently.

@jednano
Copy link
Author

jednano commented Feb 10, 2016

@jamesmenera it looks like vscode.commands.executeCommand() can run cursorLeft, cursorRight and other commands to control the cursor. This might be the next step for a TabSanity extension. I'm digging deeper when I have time.

@egamma
Copy link
Member

egamma commented Feb 10, 2016

This extension might help somewhat
https://marketplace.visualstudio.com/items?itemName=jrieken.backspace-plusplus

@jednano
Copy link
Author

jednano commented Feb 10, 2016

Thanks @egamma. @jamesmenera I'm working on TabSanity for vscode right now and I'm definitely making some good progress. I will keep everyone updated on this thread.

@alexdima alexdima added the feature-request Request for new features or functionality label Feb 11, 2016
@alexdima alexdima removed their assignment Feb 11, 2016
@jednano
Copy link
Author

jednano commented Feb 11, 2016

@jamesmenera I've published an alpha version of TabSanity here. There are definitely some kinks to work out, but as long as you don't go crazy with multiple cursors and such you should be fine.

@stephenmartindale
Copy link

Without any add-ons, full-fat Visual Studio's block indentation (with tabs as spaces) solves most of the problems because, if you are indented and add a new line, a single back-space is all that is required to jump out one indentation level. As it stands, VS Code handles this poorly - if you use soft tabs and need to get out by one indentation level, you have to press backspace n times where n is your tab width!

@stephenmartindale
Copy link

@egamma: Thanks for suggesting that extension - it's properly brilliant! I hope the VS Code devs are reading this thread because I would love to see that behaviour as a first-class option or even the default behaviour of the backspace key when soft-tabs are enabled.

@jednano
Copy link
Author

jednano commented Apr 1, 2016

@stephenmartindale, it's not just backspace, but arrow-key navigation as well. The TabSanity plugin resolves both, but there are some kinks with multiple cursors I haven't yet had the time to sort out.

@Noitidart
Copy link

Noitidart commented Mar 5, 2017

I'm trying to make the move from Atom and the "Atomic Soft Tabs" feature is what I am missing a lot. Atom defines this as "Skip over tab-length runs of leading whitespace when moving the cursor.". It's the first setting visible in Atom's settings:

I have been trying TabSanity in VSCode and haven't found issues with it yet. I do work a lot with multiple cursors though, I'm hoping it hangs in there.

@aniforprez
Copy link

aniforprez commented Mar 11, 2019

Over 2 years later and nothing? I love everything about VSCode except the fact that this still isn't a thing yet. Please give us the option to navigate soft tabs as hard tabs without needing an extension

@vedmant
Copy link

vedmant commented Mar 31, 2019

There is a good example of how PHPStorm handles it, https://blog.jetbrains.com/phpstorm/2014/09/smart-backspace-in-phpstorm-8/ VSCode really lacks feature like this.

@aniforprez
Copy link

@vedmant Are you sure VS Code doesn't have this? The author of Backspace++ discontinued work on his extension because the feature was already in. I'm talking about simply navigating the spaces as if they were tabs which requires this extension

@jednano
Copy link
Author

jednano commented Mar 31, 2019

And I'm not really actively developing TabSanity either. It's way more complicated than it originally seemed, especially where multiple cursors are concerned.

@aniforprez
Copy link

@jedmao hey thanks for the great work you've done so far. Yeah there's a few difficulties when using tabsanity that I wish weren't there. I really really just wish VS Code would add this natively. It's literally the one thing it's missing for me

@vedmant
Copy link

vedmant commented Apr 1, 2019

@aniforprez I checked VS configuration, didn't find anything related to this feature.

@aniforprez
Copy link

aniforprez commented Apr 1, 2019

@vedmant I cannot find a setting for it myself but after disabling all the extensions, VS Code behaves as expected when erasing multiple spaces using backspace that are the configured tab length. The Delete button will only delete a single space regardless. But navigating those tab-configured spaces is a chore which Tabsanity solves once it's enabled

@vedmant
Copy link

vedmant commented Apr 1, 2019

@aniforprez I'm talking about a bit different functionality, when backspace deletes whole line when it's currently on the right indent, or it goes to right indent when it has more whitespace before cursor, check animation here https://blog.jetbrains.com/phpstorm/2014/09/smart-backspace-in-phpstorm-8/

@aniforprez
Copy link

OH I'm so sorry I completely misunderstood because I didn't pay close attention to the animation. Yeah currently VS Code does not have such a feature and it does look pretty useful if you don't need to delete individual tabs. I do wonder though if it wouldn't get confusing in languages like Python where indentation is everything and if you want to move the scope of a line whether this would conflict with such an operation.

@vedmant
Copy link

vedmant commented Apr 1, 2019

@aniforprez It's very useful feature, I so used to it in PHPStorm, that it's now a pain to work without it in VScode. It will not have any issues with Python, if you need to go one indent left just press Tab + Shift. And also this feature can be optional.

@fifn2
Copy link

fifn2 commented Apr 24, 2019

This would be a good to have feature. I use a lot of soft tabs.

@Timmmm
Copy link
Contributor

Timmmm commented Sep 18, 2020

atomic_tabs

I'll put the code up at some point. It's probably full of bugs and I have never worked on VSCode before so it probably needs someone at Microsoft to do properly, but it wasn't much code. It actually took longer to add the new setting than to implement the logic.

@jednano
Copy link
Author

jednano commented Sep 18, 2020

Yeah, now try it with multiple cursors!

@Timmmm
Copy link
Contributor

Timmmm commented Sep 18, 2020

They work fine as far as I can tell. I'll upload a video tomorrow.

@Timmmm
Copy link
Contributor

Timmmm commented Sep 20, 2020

Video showing multiple cursors and weird mixed tab files.

There is one bug with the mouse handling (that I know of). Hopefully someone from Microsoft can help with that.

@alexdima alexdima self-assigned this Nov 21, 2020
@alexdima alexdima modified the milestones: Backlog, November 2020 Nov 21, 2020
@alexdima alexdima mentioned this issue Nov 30, 2020
2 tasks
@github-actions github-actions bot locked and limited conversation to collaborators Jan 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
editor-commands Editor text manipulation commands feature-request Request for new features or functionality insiders-released Patch has been released in VS Code Insiders on-testplan
Projects
None yet
Development

Successfully merging a pull request may close this issue.

12 participants