What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 134 Stack Exchange communities.

Possible Duplicate:
Add increase/decrease tab indent buttons to the editor toolbar

If you have some code which is heavy nested and you just copy some of the inner code you end up with a lot of useless space (if you don't have box-selection or don't know how to use it at least).

So wouldn't it be convenient if the "greatest common whitespace" in pasted text would be removed from each line automatically? Or if that is not going to happen how about two buttons which add/remove 4 spaces to/from all selected lines?

(Edit: I know you can use the normal code block button to shift code back but not all people do, and having a right shifting button would be nice for fixing code-internal indentation problems or if you paste a segment into the existing code and you want to line it up properly)

share|improve this question

marked as duplicate by Grace Note, jzd, random May 27 '11 at 21:44

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer 1

You can highlight the code and use the code format button to shift all code back. It will basically tab the code back.

Works great most of the time, unless the tab levels are way off.

Try editing my answer. If you highlight the code below and click the code format tool once it will shift to the proper place. Click it a second time and it will shift flush left.

Important Note
As in the comments below found that you must ensure all white space in from of first line is selected.

    //Some Code
    if (myTab >= TooMuch) {
        shiftLeft();
    }

Test 2:

        //Some Code
     if (myTab >= TooMuch) {
        shiftLeft();
     }
share|improve this answer
    
@Dustin I think H.B. is asking about shifting to the left. Not right. –  jzd May 27 '11 at 16:28
    
@jzd, I know it does that. Try it out! I made an example in my answer. –  Dustin Laine May 27 '11 at 16:28
    
@Dustin, it just shifts right once. If you click it again it un-does the action. It never shifts left. –  jzd May 27 '11 at 16:32
    
@jzd - Sorry, but you are wrong. I JUST did it! –  Dustin Laine May 27 '11 at 16:35
    
@Dustin, your example worked but mine didn't. I just edited your answer try the second test I just added. –  jzd May 27 '11 at 16:45
1  
@jzd It works, actually. –  Grace Note May 27 '11 at 16:47
    
@jzd - I just highlighted it, clicked the code button. It shifted everything left by a tab and made the highlighting work just as I stated. –  Dustin Laine May 27 '11 at 16:47
    
@jzd See this Meta question. Which, actually, points out that this is a duplicate request of this one, anyway. –  Grace Note May 27 '11 at 16:48
    
I am aware of this functionality, sadly it's only one way (unless there is something on the base level, in that case it shifts right) and most people don't even know that they could remove the redundant space with it. I'd also like to have right-shifting to fix internal indentation issues. –  H.B. May 27 '11 at 16:55
1  
@Grace, just tried your example as well and I think I found the issue. You have to also select all the whitespace in front of the first line. I was starting my selection at the first non-whitespace character or the middle of the whitespace, not the beginning of the line. –  jzd May 27 '11 at 16:55
    
Ahh, yes. I will add that to my answer to make sure it is clear. –  Dustin Laine May 27 '11 at 16:57
    
@jzd Huh, interesting. That's something I guess I subconsciously did each time. Good catch! –  Grace Note May 27 '11 at 17:02

Not the answer you're looking for? Browse other questions tagged .