1

From time to time I need to include code under a bullet list or number list. When I do this I have to indent blocks of code 8 spaces instead of the typical 4. Is there a keyboard shortcut that will do this? I often use Control + K to do this, but selecting a block and doing this just undoes the indenting in this scenario.

Here's an example of the code block I'm talking about in case you're unaware of this technique.

Normal block of code (4 spaces)

#!/bin/bash    
echo "hello U&L world"

Block of code under a list (8 spaces)

  1. some list item #1

    #!/bin/bash        
    echo "hello U&L world #1"
    
  2. some list item #2

    #!/bin/bash    
    echo "hello U&L world #2"
    
  3. some list item #3

    #!/bin/bash    
    echo "hello U&L world #3"
    

2 Answers 2

2

I just found a really cool usersript that does just that: it enables using tab for indenting code in the SE editor.

https://stackapps.com/q/3247/17253

Hitting tab twice will double indent so you can easily use it to format code in lists. I've been using this for a few days and can't understand how I lived without it!

1
  • Confirmed it works. Thanks! Nice dig!
    – slm Mod
    Commented Feb 2, 2014 at 17:32
1

There isn't, but there's a pretty quick workaround described in WMD: Code inside lists on the main meta:

  • Indent the code 4 spaces with Ctrl+K
  • Add a single non-space character to the beginning of the first line
  • Indent the code 4 more spaces with Ctrl+K (the non-space character tricks the editor into thinking it needs to indent)
  • Remove the character you added to the first line
1
  • Thanks Michael, I couldn't find it when I searched.
    – slm Mod
    Commented Oct 20, 2013 at 20:40

You must log in to answer this question.

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