views:

27018

answers:

10

Does anyone know how to convert tabs to spaces in Notepad++? I found a webpage that suggests it's possible (http://www.texteditors.info/notepad-replacements-compared.php) but I couldn't find any information about how to do it. I like to be able to do that because some web forms don't respect code with tabs in it.

+39  A: 

Settings -> Preference -> Edit Components (tab) -> Tab Setting (group) -> Replace by space

In version 5.6.8 (and above):

Settings -> Preferences... -> Language Menu/Tab Settings -> Tab Settings (group) -> Replace by space

Aron Rotteveel
Thanks for the reply. I was hoping there was a way to just apply it to a highlighted block of text. I prefer to work with tabs. I just want to be able to switch to spaces before pasting some code into a form.
Helephant
While the reply by Dror is certainly the 'answer', this is definitely also helpful to know for other uses!
Marc Bollinger
Not the answer to the question but the answer that I was looking for. Cheers, Aron.
Brent Plump
It took me so long to find this...
nikic
Wow! So much rumour about an (apparently) simple task. Replace with \t and Extended switch works fine for me
waanders
Perfect. Just what I needed. Thanks!
Leif
+24  A: 
Dror
just to emphasize, you need to put four space (or two, or whatever) in the "replace with" box.
hasen j
you can replace the \t (tab) to any number of spaces, see http://wiki.answers.com/Q/How_many_spaces_is_a_tab
Dror
This will only work properly for tabs at the start of a line. E.g. in a line like this (using [tab] to represent a tab): "[tab]foo[tab]bar", with a tab size of 4 spaces, the first tab should be 4 spaces, but the second tab should be only 1 space.
mercator
@mercator - your case is entirely context-dependent. If that is the case, the OP can use 'Find Next'/'Replace' to jump to the next occurrence and make case-by-case decisions. The original question doesn't *seem* to indicate that concern.
DaveE
+44  A: 

First set the "replace by spaces" setting in Preferences. Next, open the document you wish to replace tabs with Highlight all the text Then select TextFX -> TextFX Edit -> Leading spaces to tabs or tabs to spaces

Yes, this is far more sensible than doing search/replace, and TextFX is built-in to Notepad++.
rjh
This is actually the best answer.
KyleFarris
Just a poorly named feature in a poorly placed menu.
spoulson
nice, wow, this is super good to know.
matt lohkamp
+3  A: 

There is no 'Edit Components' tab in the preferences setup. You need to go 'Language Menu/Tab Settings', there is an option in there to control tab behavior. You can even set it to work differently depending on the language of the file.

Elliot
And after setting it there, use TextFX *(TextFX -> TextFX Edit -> Leading spaces to tabs or tabs to spaces)* as described earlier. This is definitely the way to go in the latest version of Npp.
Cees Meijer
A: 

None of the presented solutions work in a more general situation where the tabs are NOT the first characters on a line.

Heikki
+2  A: 

the easy way:

  1. highlight a single tab area
  2. copy
  3. bring up find/replace
  4. paste into the find field
  5. click into the replace field and hit the space bar
  6. then replace all.
matt lohkamp
Maybe not the fanciest approach, but this worked for me.
Guy Starbuck
it's the lazy approach, which is generally my M.O. :]
matt lohkamp
This is the Notepad (not++) way of doing things, too.
maxwellb
A: 

Since I can't comment on other replies atm, I'll add my own here: All the answers telling how to replace tabs with spaces -- no matter how sophisticated the methods -- are something that good old Notepad could achieve easily (just follow the steps on matt lohkamp's reply). I would expect Notepad++ to have more advanced capabilities and be able to replace tabs in the middle of lines, as many people have commented on this thread. I hope someone comes up with a real solution; otherwise this question would be generic, applying to any text editor, not only to Notepad++.

edit: I just tried two programs after searching google. The first one (bluefive.pair.com/tabs2spaces.htm) was crap (it simply does that basic replacement even Notepad can do). The second one, though, worked like a charm. It's called CLR Tabs to Spaces and it handles middle-line tabs perfectly. I'll suggest the maker to convert it into a Notepad++ plugin :)

edit 2: I guess I overlooked a feature in tabs2spaces: the Fixed Layout Formatting mode seems to make it work more or less as expected; however, it is still less flexible than "CLR Tabs to Spaces", since the latter allows the user to change the amount of spaces per tab. By the way, after contacting the tool's developer, he quickly made a npp plugin out of it (as he has announced on this thread himself), so make sure to try it out!

Waldir
A: 

" The second one, though, worked like a charm. It's called CLR Tabs to Spaces and it handles middle-line tabs perfectly. I'll suggest the maker to convert it into a Notepad++ plugin :) " <<

Did you check the recency of this tool? Refer to the revision history...

" edit: I just tried two programs after searching google. The first one* was crap (it simply does that basic replacement even Notepad can do). " >>

I just can't believe it! Who would write such a tool...

Did you in fact check the documentation, a short and simple readme text file?

Did you check Fixed Layout Formatting? Did you? It may get results more to your liking. This is said to "work more or less intelligently".

[edit] I guess it is what you are after. In Fixed Layout Formatting mode it replaces Tabs by the correct number of spaces to get to the next Tab Stop. Currently, this mode uses Tab Stops set at a fixed distance of 8 characters. But this is likely to be changed in the near future. It may help you, however, to get started.

If 8 is not the desired number, you could do an additional replacement of each 8 space characters by the correct number. You would then be only left with strings of 7 or less consecutive space characters, which may need to be cut off or extended. [/edit]

By the way, this utility is way more recent and is freeware. Perhaps you could write this author also to get any additional features you would want.

bluefive.pair.com/tabs2spaces.htm

NoName
+1  A: 

i just posted a notepad++ plugin to convert tabs to spaces. yes, it converts tabs in the middle of a line. yes, it takes into account other characters within the tabbed field. check it out.

https://sourceforge.net/projects/tabstospacesnpp/

carl
What if I have a string that I want to define with a Tab in it? It changes my source code and string literals, too?
maxwellb
A: 

TABS2Spaces RC 1.05 is out now. It includes the desired functionality.

http://bluefive.pair.com/beta.htm

NoName
TABS2Spaces 1.05 has been released:http://bluefive.pair.com/tabs2spaces.htm
NoName
TABS2Spaces has been released:http://bluefive.pair.com/tabs2spaces.htm
NoName