12

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?

12

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.

  • 1
    This works brilliantly ty – Yvette Colomb Jun 29 '13 at 6:20
  • 3
    +1, Agree it should definitely be a standard feature. – Ben Lee Jun 29 '13 at 6:40
4

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.

  • I tried to edit your answer, as it took me some time to work out what AFAIK means. The edit was rejected, which is disappointing. – Yvette Colomb Jun 29 '13 at 4:32
3

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

a
    Actual
    Indented
        Code
  • Can you please explain what you mean by a dummy line to highlight? – Yvette Colomb Jun 29 '13 at 4:16
  • @Yve: You add the a before the indented code, then highlight the whole thing and re-indent, then delete the a and any extra blank lines. – Ry- Jun 29 '13 at 6:03
  • what does adding the dummy line do to the indentation? – Yvette Colomb Jun 29 '13 at 6:04
  • @Yve: It stops it from unindenting the block if it’s already indented. – Ry- Jun 29 '13 at 17:15
  • thanks Mini, I love the script that was recommended, I'm actually finishing editing posts ! – Yvette Colomb Jun 29 '13 at 17:36

You must log in to answer this question.

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