When editing a post, sometimes the code block has been indented too far and it forces a horizontal scrollbar unnecessarily.
Is there a quick way to correct this type of indentation or do I still have to go line by line deleting space?
Meta Stack Exchange is a question and answer site for meta-discussion of the Stack Exchange family of Q&A websites. It only takes a minute to sign up.Sign up to join this community
You can use the userscript by balpha♦ at Better handling of indentation and the TAB key when editing posts.
With that installed, you can simply Shift+Tab as many times as needed.
When multiple lines are selected, Tab and Shift-Tab indent and dedent these lines
When nothing is selected, Tab and Shift-Tab insert or remove whitespace to align the cursor on a tab boundary
In my opinion, this should be a standard feature.
Here's a little quirk with the markdown editor that you could use without having to install separate scripts. Given selected text that is currently unindented, pressing the code button (or Ctrl + K) will add four spaces to all the selected lines. If all the selected lines are indented by more than four spaces, it will remove four spaces.
With that in mind, if you wanted to unindent any bit of code, you could just select it and hit the code button.
There isn't a way to add indents as easily as far as I know unfortunately. For that, I just select four spaces, copy and paste where needed.
You can sort of indent and unindent using only CtrlK. To unindent, as @Jeff says, highlight the block and press, removing blank lines added before and after as necessary; to indent, add a dummy line to highlight. Like
aActual Indented Code