Sublime Forum

How to keep the first line indentation selected when indenting?

#1

On this gif bellow I got some text unindented selected. Then I press tab to indent them. This is my tab command:

    { "keys": ["tab"], "command": "reindent", "context":
        [
            { "key": "setting.auto_indent", "operator": "equal", "operand": true },
            { "key": "selection_empty", "operator": "equal", "operand": true, "match_all": true },
            { "key": "preceding_text", "operator": "regex_match", "operand": "^$", "match_all": true },
            { "key": "following_text", "operator": "regex_match", "operand": "^$", "match_all": true }
        ]
    },
    { "keys": ["tab"], "command": "indent", "context":
        [
            { "key": "text", "operator": "regex_contains", "operand": "\n" }
        ]
    },

Now the indentation created on the first line is out of the selection bounds after the indent command:

Then I have to select them manually later, after the indentation.

  1. So, should be necessary write a package with a new indent command?
  2. Or is there some package which does this already?

Therefore pseudocode could be something like:

  1. Call default indent command to do the indentation, and
  2. Later select the spaces until find the start of the line, from the first cursor/caret.
0 Likes

#2
1 Like

#3

Thanks! Works like a charm.

I have an issue that is driving me insane with Sublime Text 3. When I select multiple lines by clicking on the side of the line and dragging, I then hit tab to correct the indentation, but then I want to move the entire line to another spot except I have to re-select it because the first line is only selected from where the text starts, not where the line starts.

Let’s see if I can illustrate this… Below is the lines I have:

Text Line 1
Text Line 2

I select them (selection shown using *)

*Text Line 1
Text Line 2*

I indent the lines and now the selection looks like this:

    *Text Line1
    Text Line 2*

Notice the selection starts with the text. I want the selection to stay at the beginning of the line like this:

*   Text Line 1
    Text Line 2*

I have searched everywhere but apparently I’m the only one that is bothered by this. Every other code editor I have used does it the way I want.

0 Likes

#4

agreed - personally I’d class it as a bug that ST doesn’t work like this automatically, it gets me everytime when indenting code to paste as a code block on the forums

1 Like

#5

I opened a issue on the core:

  1. $1746 Keep the first line indentation selected when indenting text
1 Like

#6

For any lost souls out there still suffering from this… There’s a fix called FixSelectionAfterIndent
https://packagecontrol.io/packages/FixSelectionAfterIndent

0 Likes