The code in my post appears to have improper indentation, but the indentation in the editor differs. There is usually a different amount of indentation between the two, which must be so because there are tabs used in the code. I'm afraid others will assume that I'm unaware of proper indentation, thus this will become part of a review.

What are some methods for removing these tabs and replacing them with spaces?

share
    
    
@Malachi: It's not quite the same. That question states: I've replaced tabs with spaces in my editor. This question is for those who haven't done that yet. –  Jamal May 20 at 17:18
add comment

4 Answers

Tabs to Spaces Online Converter

There's a (web)app for everything. In this case thanks to Anders Åberg, who was thoughtful enough to even include a feature for adding four additional spaces to the beginning (to generate a markdown code block).

share
3  
Where has this been all my life?!? –  Jamal May 15 at 18:14
add comment

Using Microsoft Word

  1. Paste the code (extra text is okay) and place the cursor at the beginning
  2. Open Find and Replace
    • Enter ^t into the Find field
    • Enter the desired number of spaces into the Replace field
  3. Click on Replace All
  4. Replace the old text in the editor with this fixed text

enter image description here

This image is from Word 2010 and may differ from other versions.

share
5  
Word!!! ???? My Word! –  rolfl May 15 at 0:40
    
@rolfl: It works for me. ;-) –  Jamal May 15 at 0:41
2  
+1 for red free hand circle! Keep up the good work @Jamal! –  Marc-Andre May 16 at 17:31
add comment

Using vim

Select the code, and paste it in to an empty vim terminal/screen.

Enter the following sequence:

:set ts=4
:set expandtab
:retab

Select the code out again.

share
add comment

Rolf Actually posted an answer Here that shows how to format code for posting here from Eclipse and NotePad++

I use NotePad++ which is why I remember that we had discussed this elsewhere.

  • Using Notepad++

    1. CtrlA
    2. Edit->Blank Operations->Tab to Spaces
    3. CtrlC
    4. CtrlW to close file
    5. AltTab back to Stack Overflow
    6. CtrlV to paste fixed code back again

I stole a lot of Rolf's answer for this

share
add comment

You must log in to answer this question.

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