Take the 2-minute tour ×
Web Applications Stack Exchange is a question and answer site for power users of web applications. It's 100% free, no registration required.

Stack Overflow has a button you can press to indent a block of text four spaces so Markdown will treat it as code. GitHub uses Markdown, too, but does not seem to have formatting buttons.

Does GitHub have a keyboard shortcut or button to indent a block of code? Or will I have to copy the code to a text editor, indent it, and paste it back in?

share|improve this question

3 Answers 3

GitHub Flavored Markdown supports an alternative syntax for code formatting (notice the backticks):

```
#include <stdio.h>

int main(void)
{
    puts("Hello, world\n");
    return 0;
}
```

This does not require you to indent the code. Another bonus: you can specify the programming language to enable syntax highlighting:

```ruby
require 'redcarpet'
markdown = Redcarpet.new("Hello World!")
puts markdown.to_html
```
share|improve this answer
1  
This is the best answer because GFM extends the Markdown standard so you don't need to indent. If only we could get some sort of consensus on what flavor should become the standard. –  styfle Feb 22 at 0:19

Select the lines you want to indent and hit Tab twice. Shift+Tab unindents.

share|improve this answer
    
This doesn't work for me in either Firefox or Chrome. What browser are you using? –  Joey Adams Oct 22 '12 at 19:00
    
@JoeyAdams I've just tried with Chrome and Firefox. Also, it doesn't work in Gist (the editor is just a textarea). –  Francesc Rosàs Oct 24 '12 at 23:42

There is no keyboard shortcut to automatically indent a block of code.

You will either have to find a browser extension, like a userscript, or write one yourself. Or just add the four leading spaces as you would now.

You can see a list of current GitHub keyboard shortcuts by Shift + ? and clicking "See all" when on any GitHub page.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.