What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 131 Stack Exchange communities.

Possible Duplicate:
How do I format my code blocks?

Is there a dirt-simple way to post code snippets in a StackOverflow answer?

I've been putzing around the with either the 'inline' code curly braces, or this 'indent 4 spaces' concept. Still losing whitespace and/or wordwrapping where it shouldnt be.

share|improve this question

migrated from stackoverflow.com Jun 8 '12 at 20:54

This question came from our site for professional and enthusiast programmers.

marked as duplicate by Shadow Wizard, slhck, kiamlaluno, random Jun 9 '12 at 13:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

5  
Copy code, select it, Ctrl+K? Or I'm missing something? –  om-nom-nom Jun 8 '12 at 20:55
    
Well while the selected answere worked on some limited testing. On this question, stackoverflow.com/questions/9631801/…, still unable to get the code to format properly if copy-pasted then using the curly braces. You will see that instead, I linked to a posting on Microsoft Script Center. –  Real World IS Jun 10 '12 at 4:43

2 Answers 2

up vote 2 down vote accepted

Hold down Shift while you select the code block with either the mouse or arrow keys, this should highlight the block.

Now hit the {} button above the entry box, this should indent all the selected code by the necessary 4 spaces and also put blank lines before and after if necessary. You can see the effect immediately in the preview below the entry box.

share|improve this answer

In your favorite code editor, ensure that the farthest left indent of the code that you are about to copy is four characters from the left margin of the editor. Once you've done this, select and copy. Then, when you paste in the editor, you're already done.

For example, in my case, I'll select my code (visual studio), hit shift-tab (decrease indent) until at least one line of code has touched the left margin of the code editor, then I'll hit tab once. That adds four spaces of indent to the code. I then copy and paste it into the question editor.

share|improve this answer

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