Quantcast
Channel: User Wilson F - Super User
Viewing all articles
Browse latest Browse all 15

Is there a way to fix multi-line indenting in Sublime Text 3 so that it adds the indenting characters for the first line inside the selection?

$
0
0

When I select several lines in Sublime Text 3 and indent them as a block (using either Tab or Ctrl+]), it adds the new whitespace characters at the beginning of the first line outside the selection instead of inside.

Say I have a block of code that looks like this (Note: all of the below is just to illustrate the idea; please don't start on me about where my braces are, or how much I indent, etc.):

int firstVar, secondVar;firstVar = 4;secondVar = 11;

Now, I come back to this code later and need to make the value assignments conditional:

int firstVar, secondVar;int myVar = 0;int result = someThing(myVar);if (result == GOOD_RESULT){firstVar = 4;secondVar = 11;}else{}

Of course, I want to indent it nicely, so I select the two items in the if clause and indent them as a block, with the Tab key, and Sublime Text, as expected, prepends indenting characters (a tab or a pre-determined number of spaces) to each selected line:

[snip]if (result == GOOD_RESULT){  firstVar = 4;  secondVar = 11;}else{}

Then, because I am just going to be assigning different values to them in the else clause, I copy and paste them there, ready to amend:

if (result == BAD_RESULT){  firstVar = 4;  secondVar = 11;}else{firstVar = 4;  secondVar = 11;}

And there's the problem: Sublime Text indented the first line of my block, but didn't include the indenting characters in the selection, so when I copy-and-pasted it, I didn't get the indenting of the first line. (I wish I could change the background colour to illustrate better.)

Not only that, but if I'd cut and pasted it instead, the indenting characters would have been left behind.

I can work around it somewhat by trying to remember to copy/cut before doing the indenting, but a) I don't always remember and b) then I have to indent the code twice.

Does anyone know of a fix for this?


Viewing all articles
Browse latest Browse all 15

Latest Images

Trending Articles





Latest Images