14

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?

0

3 Answers 3

16

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.

0
5

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.

0
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
5
  • Can you please explain what you mean by a dummy line to highlight?
    – user310756
    Commented Jun 29, 2013 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- Mod
    Commented Jun 29, 2013 at 6:03
  • what does adding the dummy line do to the indentation?
    – user310756
    Commented Jun 29, 2013 at 6:04
  • 1
    @Yve: It stops it from unindenting the block if it’s already indented.
    – Ry- Mod
    Commented Jun 29, 2013 at 17:15
  • thanks Mini, I love the script that was recommended, I'm actually finishing editing posts !
    – user310756
    Commented Jun 29, 2013 at 17:36

You must log in to answer this question.