Indent/unindent blocks of code


Staff member
Apr 6, 2019
Chesapeake, VA
Programming Experience
If I use the editor toolbar to open the Insert Code dialogue, paste a block of with leading whitespace, select the code and then press Shift+Tab, the whitespace is trimmed such that the least-indented line(s) is left-aligned and all other indenting is maintained.
So I see part of the issue. I was using the the code BB tags, and then pasting in my code in between the begin and end-tags and then trying to do the Shift+Tab to try to unindent the block.

Unfortunately, with the "Insert Code" dialog, I'm only seeing the first line of the block being unindented.

So I go open the Insert Code dialog, and type in the following:

Then I press, Ctrl-A to select all. Then lastly I press Shift+Tab. Only the first line of the selected block is unindented. (If I press Tab, instead of Shift+Tab, the entire block correctly gets indented.)
I just checked it, and you're using the same version of opera as me.

You need to use actual code and not what you've quoted. In the Insert code blocks, it will only indent the first line. But not if you use actual code.

The simple solution is not to trim the white space when copying code.
Confirming it also works on Edge too, and so I will assume it will work on Chrome ;)
The simple solution is not to trim the white space when copying code.
Actually, the simple solution is to trim the whitespace when copying the code but to do so for the whole block rather than just the first line, which I see a ton of people do for some reason. Many people don't realise that you can hold down the Alt key while selecting text to select an arbitrary rectangular block, so if you start somewhere in from the left edge, the selection will start at the same column on every line.
Last edited:
Hmm I will have to check that out when I'm next in the IDE. I never have any issue posting. I always select a block and leave the indentation intact on every line.
Not all text editors implement the rectangular block text copying, but yes, I get the sentiment.
Okay. This time I put in real code instead of gibberish into the code dialog box, but it didn't unindent the code. See C SHARP RTL AND LTR SPECIAL CHARACTER
I just edited that post and it worked for me. I deleted the existing code tags, selected the code, copied it into the code window, selected it all (Ctrl+A) and then hit Shift+Tab and the leading whitespace was removed. In fact, I've noticed that doing that doesn't just remove whitespace but it also changes the indenting on individual lines to what they should be. I don't know what to tell you with regards to the same thing not working for you.

One thing that always happens for me too is that code copied from a post and pasted into the code window always doubles up on line breaks. Not sure whether it is turning both carriage returns and line feeds into line breaks or what. I usually just position the cursor at the start of the text and then hit Down and Delete alternately until I get tot he bottom.
        const string LRM = "\u200E";
        const string RLM = "\u200F";

        static void ShowStringDetails(string name, string s)
            Console.WriteLine($@"{name}: ""{s}""");
            Console.WriteLine($"{name}.Length: {s.Length}");

        static void Main(string[] args)
            var heb = "מזל טוב";
            var str1 = $"{heb,-30}";
            ShowStringDetails(nameof(str1), str1);

            str1 = RLM + str1;
            ShowStringDetails(nameof(str1), str1);

            var eng = "mazel tov";
            var str2 = $"{eng,-20}";
            ShowStringDetails(nameof(str2), str2);

            str2 = LRM + str2;
            ShowStringDetails(nameof(str2), str2);

            var strAll = str1 + str2;
            ShowStringDetails(nameof(strAll), strAll);
            MessageBox.Show(strAll, strAll.Length.ToString());

See above. Still indented. My repro steps where:

1) Open the attached file in Notepad, VSCode, or Visual Studio -- it didn't matter which editor I used.
2) Ctrl-A to Select All.
3) Ctrl-C to Copy.
4) Click on the "..." above in the toolbar. (I'm using Chrome.)
5) Select Code
6) Paste into the dialog
7) Press Shift-Tab to unindent.

So strange. Same thing in Opera.
Last edited:
Aha! That did the trick.
Top Bottom