When you type a code, and you press enter, the new line should be filled with x*4 spaces or x tabs. It's not that comfortable to copy tabs/spaces from the previous line, or paste the code to notepad, format it, then paste it back into this editor.
What I do in VS 2015 is:
- Select all my code and then press CTRL + SHIFT + TAB so it is indented as far left as possible. If you do not do this, it will have many tabs and then you would need to manually fix each line on stackoverflow.
- Then copy and paste on StackOverflow edit and select it all and press CTRL + K.
That is the best method I have found so far.
What you do is type your code and then highlight and press ctrl+k. I have done this a couple times and it works perfectly.
-
8This is the approach I use, which works until it doesn't - such as when I'm adding lines to an existing code block. – Drew Dormann Jul 19 '15 at 22:24
-
After the first block of code with white space, I have to manually reformat after that. But maybe the flip side is that this inconvenience encourages us to paste as little code as possible so that we focus on the most important content. – user4864716 Jul 20 '15 at 5:11
-
And as soon as you want to present correctly indented code, you count 4, 8, 12 spaces. Is is generally enough when pasting code from an IDE even if tabs can give strange results but taking code from a question and adding some line can be tedious – Serge Ballesta Jul 20 '15 at 5:44
-
Tab
and keep in clipboard whatever you want – Cliff Burton Jul 20 '15 at 14:31