Convert tabs to spaces in Notepad++
Asked Answered
F

13

1259

How do I convert tabs to spaces in Notepad++?

I found a webpage that suggests it's possible, but I couldn't find any information about how to do it.

I would like to be able to do that, because some web forms don't respect code with tabs in them.

Foretell answered 18/1, 2009 at 12:10 Comment(0)
I
1300

To convert existing tabs to spaces, press Edit->Blank Operations->TAB to Space.

If in the future you want to enter spaces instead of tab when you press tab key:

  1. Go to Settings->Preferences...->Language (since version 7.1) or Settings->Preferences...->Tab Settings (previous versions)
  2. Check Replace by space
  3. (Optional) You can set the number of spaces to use in place of a Tab by changing the Tab size field.

Screenshot of Replace by space

Iciness answered 19/9, 2011 at 12:52 Comment(10)
This is not a very good solution since you need to do it every time you pres tab key..Wallywalnut
@Algina - you can change the settings for Notepad++ to automatically convert tabs to spaces - just go to: Settings - Preferences - Tab Settings - tick the box "Replace by Space" - like mrzli already described in this answer.Orient
This is affected by the tab size defined in "Settings" -- "Preferences" -- "Tab Settings" -- "Tab size", naturally.Disposal
I just want to add that the path for me was: Settings => Language Menu/Tab Settings => Replace by space (In the bottom right corner). It is almost as mrzli said, but I had a hard time noticing where it said Tab Settings. (I know I am blind!)Omaromara
There is no Settings -> Preferences... -> Tab Settings in Notepad++ v7.1 It's now under Settings -> Preferences -> LanguagePedagogue
I'm using v7.2.2 and I can change tabs to spaces using Edit -> Blank Operations -> Tab to Space. Also the Tab Settings are now in Edit -> Preferences -> Language. Although, I don't understand what the Tab Settings does. I've checked the Replace by space box for javascript, but I still get a tab when I press the tab key. Shouldn't it print 4 spaces instead?Mady
@Mady Noticed there's a javascript.js option. That solved the problem.Mady
One off topic remark. When writing makefile you must remember that tab is needed at beginning of every new rule.Pine
I would like to point out in the current version of Notepad++, you can choose what languages specifically you want to replace tabs with spaces and which you do not, if you want to be language specific. I'd add it myself, but the edit queue is full. The original answerer though is a hero.Sileas
Just remember the setup if you ever edit "makefiles" or Python ... just saying... Unfortunately, that setting is for all languages, so whatever choice you do, will apply to everything you edit in NPPVeto
V
592

Obsolete: This answer is correct only for an older version of Notepad++. Converting between tabs/spaces is now built into Notepad++ and the TextFX plugin is no longer available in the Plugin Manager dialog.

  • First set the "replace by spaces" setting in Preferences -> Language Menu/Tab Settings.
  • Next, open the document you wish to replace tabs with.
  • Highlight all the text (CTRL+A).
  • Then select TextFX -> TextFX Edit -> Leading spaces to tabs or tabs to spaces.

Note: Make sure TextFX Characters plugin is installed (Plugins -> Plugin manager -> Show plugin manager, Installed tab). Otherwise, there will be no TextFX menu.

Vagrant answered 18/1, 2009 at 20:37 Comment(5)
Just a poorly named feature in a poorly placed menu.Protecting
The best answer for the question (perhaps not as the author intended it) is the tabs to spaces plugin offered below. The question asks for all tabs to spaces, while this answer only converts leading spaces. If, for example, you need to convert tabular data spaced with tabs while maintaining column positions, this answer will not help you. The plugin is the only Notepad++ solution to that question which I can see here.Foreground
I needed to go into the plugin manager and install the TextFX plugin, but after I had this the rest of the instructions were fine.Monica
Answer which seems to be wrong. As Binary Phile indicates it only converts the leading tabs. In later versions there is also an option Edit -> Blank Operations -> TAB to space, but that does not work as requested either. As far as I see it there is no way currently in NP++ out of the box. Haven't tried the plugin Binary Phile mentions.Quintilla
BTW - after switching to replace by spaces (2 spaces) I had to close and open NP++ otherwise it was buggy (still did 4 spaces sometimes)Ceroplastic
M
238

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

Magee answered 18/1, 2009 at 12:14 Comment(2)
Version 5.9.3 has Edit->Blank Operations->TAB to Space. See answer by mrzli.Behoove
This changed again in version 7.1 (2016-10-16) (from "Language Menu/Tab Settings" to "Language")Malina
T
166

You need to replace \t - make sure you use extended mode!

Replace

Tribute answered 18/1, 2009 at 12:15 Comment(5)
just to emphasize, you need to put four space (or two, or whatever) in the "replace with" box.Ious
you can replace the \t (tab) to any number of spaces, see wiki.answers.com/Q/How_many_spaces_is_a_tabTribute
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.Hollerman
@Hollerman - 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.Sunk
@Sunk No, mercator's case is the universal case of how TAB works. Although mentioned in a comment and not in the original question, what essentially the OP wants is a transaperent switch from tabs to spaces, that is, he shouldnt know by looking after the conversion, that a conversion has been done. By taking the a selected text and expanding it to starts of lines, one could implement a calculation and do exactly what mercator implies. It is dependent only on the text expanded to line limits. So case by case decision is not needed. It is exactly what the expand command in UNIX doesProserpina
E
93

Follow this procedure to convert spaces to tabs or vice-versa:

Space - Tab

Englebert answered 16/7, 2013 at 7:24 Comment(1)
Available in Notepad++ v6.3.2 and several earlier versions.Hippomenes
I
14

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.
Identity answered 24/2, 2010 at 22:44 Comment(0)
B
9

In version 5.8.7:

Menu Settings -> Preferences... -> Language Menu/Tab Settings -> Tab Settings (you may select the very language to replace tabs to spaces. It's cool!) -> Uncheck Use default value and check Replace by space.

Screenshot of the Preferences dialog

Begorra answered 9/3, 2011 at 5:5 Comment(2)
What is meant by "the very language to replace tabs"?Malina
This changed again in version 7.1 (2016-10-16) (from "Language Menu/Tab Settings" to "Language")Malina
W
9

I did not read all of the answers, but I did not find the answer I was looking for.

I use Python and don't want to do find/replace or 'blank operations' each time I want to compile code...

So the best solution for me is that it happens on the fly!

Here is the simple solution I found:

Go to:

  1. Menu Settings -> Preferences
  2. Choose Tab Settings
  3. Choose your language type (e.g. Python)
  4. Select checkbox 'Use default value'
  5. Select checkbox 'Replace by space'

Enter image description here

Wallywalnut answered 10/4, 2015 at 17:43 Comment(1)
This changed again in version 7.1 (2016-10-16) (from "Language Menu/Tab Settings" to "Language" (and was "Tab Settings" in an even older version (as in this answer))).Malina
P
3

I follow this simple way:

  • Double click (Highlight) single tab (ie: \t).
  • Press ctrl + F (Find/repace).
  • You may not see \t or single tab area on Find What: field. But don't worry.
  • Enter a space in Replace With: field.
  • Click Replce All .

Done! :)

See:

Replace *Tab* by *Space* in <code>Notepad++</code>

Note: This method applies to reverse (Replace a space by a tab) case too.

Projection answered 18/1, 2009 at 12:10 Comment(1)
If you select "Extended" from Search Mode, you can enter \t and it will also find the tab. The problem with this solution is it doesn't adjust the spacing for the tab, i.e., if a tab has a maximum of 5 spaces, your text before the tab may be 1-4 spaces...Extinguish
T
3

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.

Tasimeter answered 12/11, 2009 at 17:5 Comment(2)
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.Intro
This changed again in version 7.1 (2016-10-16) (from "Language Menu/Tab Settings" to "Language")Malina
P
2

If you happen to work in a Unix environment, the expand command is what you need:

Proserpina answered 15/4, 2011 at 9:40 Comment(2)
Isn't Notepad++ Windows-only?Tabular
It's available in linux via Wine. Performance is pretty bad though, YMMVTula
R
2

Settings > Preferences > Tab Settings Check the "replace by space". Notice above it there is Tab size: 4 Click on the four and a window will open with the option to change the value to another integer.

Put in your desired integer and press the ENTER key.

There you have it <3.

Raynor answered 6/9, 2014 at 2:0 Comment(1)
Thanks! To be preciser: Settings > Preferences > Language > Tab Settings Check the "replace by space". (Notepad++ v7.9)Irrespective
P
0

Simple way is to search and replace TAB.

  1. In notepad++, double-click the tab area, it will select the TAB as show below
  2. Click, Control + F to find this particular pattern in search
  3. Select Replace and enter 4 spaces
  4. Replace all and done

enter image description here

Prismatic answered 30/11, 2023 at 19:50 Comment(2)
This answer repeats the information in several other answers and it does not properly handle TABs so the text after them lines up properly. Consider the lines xTABy, xxTABy and xxxTABy. Expect the y characters to be lined up vertically. The replace in this answer will not do that. Also, the RED text looks incomplete and possibly wrong. Entering four spaces after clicking the Replace button is not very useful.Hippomenes
Thanks @Hippomenes for pointing out issues. Many answers below are similar, I did add an image and provided clear steps which would make it easier to understand.***** Instruction are 1) Double click the TAB area which will auto select the TAB and then Control+F to to find and replace. Make sure there is no adjacent space next to the TAB which will make double click only select the TAB and not the adjacent spaces.Prismatic

© 2022 - 2024 — McMap. All rights reserved.