1155

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.

Donald Duck
  • 6,488
  • 18
  • 59
  • 79
Helephant
  • 15,502
  • 7
  • 37
  • 35
  • 5
    Tab indent = 1x character, Space indent = more than 3x characters. – Yousha Aleayoub Dec 17 '15 at 20:13
  • SciTE does this quite easily. Too bad it doesn't extend as well as Notepad++. – bvj Oct 22 '17 at 04:05
  • 1
    I appear to have entered the Twilight Zone. My Notepad++ is always triple-spacing each tab, and nothing I've updated in the IDE has changed the behavior. I've been using it for years and never ran into this problem before o_o. Even down-grading didn't remove the problem. So yep. I'm calling it. Twilight Zone feature. – kayleeFrye_onDeck Jan 31 '18 at 03:15
  • 2
    @YoushaAleayoub 1 space = 1 space, 1 tab = different for everyone. – csabinho Sep 08 '19 at 17:14
  • 4
    @csabinho that's the point. So everyone can customize it and set it to their own size. #Freedom :) – Yousha Aleayoub Sep 12 '19 at 07:17

15 Answers15

1134

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

Ale
  • 136
  • 7
mrzli
  • 15,001
  • 3
  • 35
  • 41
  • 1
    This is not a very good solution since you need to do it every time you pres tab key.. – Alg_D Mar 06 '15 at 19:30
  • 31
    @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. – AddingColor Apr 13 '15 at 05:59
  • 3
    This is affected by the tab size defined in "Settings" -- "Preferences" -- "Tab Settings" -- "Tab size", naturally. – caw Sep 14 '15 at 02:02
  • 7
    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!) – Dzyann May 04 '16 at 13:22
  • 12
    There is no Settings -> Preferences... -> Tab Settings in Notepad++ v7.1 It's now under Settings -> Preferences -> Language – Dave Burton Oct 19 '16 at 21:05
  • 3
    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? – akinuri Feb 03 '17 at 03:55
  • 1
    @akinuri Noticed there's a `javascript.js` option. That solved the problem. – akinuri Feb 03 '17 at 21:14
  • One off topic remark. When writing makefile you must remember that tab is needed at beginning of every new rule. – panako Oct 24 '19 at 13:42
588

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
user48821
  • 5,991
  • 2
  • 14
  • 7
  • 1
    Yes, this is far more sensible than doing search/replace, and TextFX is built-in to Notepad++. – rjh Mar 07 '09 at 14:05
  • 132
    Just a poorly named feature in a poorly placed menu. – spoulson Dec 16 '09 at 19:51
  • 14
    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. – Binary Phile Apr 08 '11 at 18:46
  • 4
    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. – Rebecca Chernoff Sep 12 '11 at 04:12
  • 12
    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. – Stijn de Witt Oct 25 '11 at 12:08
  • 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) – brittohalloran Nov 21 '11 at 15:40
  • And when you have a table row of data? Where the tabs isn't leading and you want that converted to spaces? – thomthom Feb 05 '13 at 10:23
  • 1
    I would also add, the BUILT-IN solution, mentioned below, should be the best answer. It converts ANY tab to a space and it doesn't require downloading anything at all. Just go to the menu option and do it. – Tom Padilla Nov 25 '14 at 15:17
228

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

Matthew Murdoch
  • 28,946
  • 26
  • 89
  • 125
Aron Rotteveel
  • 73,917
  • 17
  • 100
  • 128
  • 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 Jan 18 '09 at 12:17
  • 3
    While the reply by Dror is certainly the 'answer', this is definitely also helpful to know for other uses! – Marc Bollinger Jul 22 '09 at 21:12
  • Not the answer to the question but the answer that I was looking for. Cheers, Aron. – BrezzaP Aug 15 '09 at 10:18
  • Wow! So much rumour about an (apparently) simple task. Replace with \t and Extended switch works fine for me – waanders Sep 16 '10 at 08:26
  • Perfect. Just what I needed. Thanks! – Leif Sep 29 '10 at 20:41
  • 3
    Version 5.9.3 has Edit->Blank Operations->TAB to Space. See answer by mrzli. – koppor Sep 09 '12 at 10:33
  • [This changed again in version 7.1 (2016-10-16)](https://stackoverflow.com/questions/455037/convert-tabs-to-spaces-in-notepad/7471232#7471232) (from *"Language Menu/Tab Settings"* to *"Language"*) – Peter Mortensen Jul 03 '18 at 08:33
155

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

Replace

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Dror
  • 7,077
  • 2
  • 36
  • 43
  • 23
    just to emphasize, you need to put four space (or two, or whatever) in the "replace with" box. – hasen Jan 18 '09 at 12:26
  • 1
    you can replace the \t (tab) to any number of spaces, see http://wiki.answers.com/Q/How_many_spaces_is_a_tab – Dror Jan 18 '09 at 12:31
  • 7
    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 Jan 18 '09 at 18:39
  • 1
    @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 Nov 12 '09 at 17:11
  • 4
    @DaveE 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 does – Paralife Apr 15 '11 at 09:38
  • 2
    The other answers may answer the specific question, but I think this answer is best, as it answers how to replace tab with ANYTHING, not just spaces. – Kik Oct 02 '14 at 15:49
  • 1
    @Kik wright said.. Other answers seems much complicated for a simple solution. This one is pretty direct – Clain Dsilva Feb 05 '15 at 09:27
  • Thanks ... This was the answer I was looking for. – Allan F Apr 06 '20 at 00:37
84

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

Space - Tab

Keshava GN
  • 4,070
  • 2
  • 33
  • 44
26

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.

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
carl
  • 369
  • 3
  • 4
  • 1
    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 Jul 01 '10 at 12:45
  • Works like a charm for tabs to spaces. That's all it does, though. – Binary Phile Apr 08 '11 at 18:44
  • Thank you, this is great. It's actually the only real answer to the question that covers all situations - leading tabs or embedded tabs, and taking location in the text and proper tab width into consideration. – RenniePet Jun 25 '11 at 21:05
  • This should be the answer for this question, especially now that TextFX isn't in the default installation of Notepad++. The plugin works flawlessly. Thank you! – Brown Oct 17 '11 at 15:40
  • Awesome work! Now if there was only an easy way to convert a whole directory of files! :) – Nathan Moinvaziri Aug 18 '12 at 01:52
  • 2
    Version 5.9.3 has Edit->Blank Operations->TAB to Space. See answer by mrzli. – koppor Sep 09 '12 at 10:32
11

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.
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
matt lohkamp
  • 2,066
  • 3
  • 27
  • 47
  • 2
    it's the lazy approach, which is generally my M.O. :] – matt lohkamp May 20 '10 at 21:51
  • 3
    This is the Notepad (not++) way of doing things, too. – maxwellb Jul 01 '10 at 12:45
  • In Notepad++ 6.5.5, trying TO TABS (from commas), this was the only approach that worked for me: type a `tab`, select it and `copy`, and it gets pasted into the replace field. (Putting `/t` in the `Replace with` box did *not* work, regardless of whether I selected `Extended` or `Regular Expression`.) – Doug_Ivison Jun 03 '14 at 14:54
  • 5
    @Doug_Ivison That's because `/t` is not an escape sequence; it's a slash, and a letter t. If you want to replace tabs, use `\t`. Hence `Extended (\n, \r, \t, \0, \x...)`. – Dan Bechard Jul 14 '14 at 20:21
  • @Dan You're right... thanks. The copy/paste works, and `\t` works. – Doug_Ivison Jul 15 '14 at 14:06
8

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

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Stephenmjm
  • 111
  • 1
  • 5
7

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

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Alg_D
  • 1,815
  • 4
  • 22
  • 49
  • [This changed again in version 7.1 (2016-10-16)](https://stackoverflow.com/questions/455037/convert-tabs-to-spaces-in-notepad/7471232#7471232) (from *"Language Menu/Tab Settings"* to *"Language"* (and was *"Tab Settings"* in an even older version (as in this answer))). – Peter Mortensen Jul 03 '18 at 08:37
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.

Elliot
  • 4,173
  • 7
  • 37
  • 62
  • 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 Dec 09 '09 at 11:32
  • [This changed again in version 7.1 (2016-10-16)](https://stackoverflow.com/questions/455037/convert-tabs-to-spaces-in-notepad/7471232#7471232) (from *"Language Menu/Tab Settings"* to *"Language"*) – Peter Mortensen Jul 03 '18 at 08:34
2

CLR Tabs to Spaces plugin should be a good option. I have used it and it worked.

Pupil
  • 23,141
  • 5
  • 40
  • 62
  • flawless victory! highlight text, plugins > CLR Tabs to Spaces > Tabs to Spaces. this plugin takes into account how many spaces are required for the tab i.e. your spaced output looks exactly the same as your tabbed output. – sonjz Mar 07 '13 at 17:05
2

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.

Keshava GN
  • 4,070
  • 2
  • 33
  • 44
  • 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... – sonjz Mar 07 '13 at 16:46
  • 1
    Don't know why this answer was downvoted, but to me it is perhaps the best because it embodies the following: KISS. Obviously it will never cover all the corner cases and configuration galore a plug-in would bring, but then again, having to rely on a plug-in for something so simple is just crazy for the general case. KISS all the way. – luis.espinal Aug 14 '13 at 20:45
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.

  • Thanks! To be preciser: Settings > Preferences > Language > Tab Settings Check the "replace by space". (Notepad++ v7.9) – Guido Lange Nov 11 '20 at 10:09
2

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

Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123
Paralife
  • 5,754
  • 8
  • 37
  • 57
0

The following way is the best way in my opinion:

Download:

  1. Notepad++
  2. The plugin http://sourceforge.net/projects/tabstospacesnpp/?source=typ
  3. Read the instructions and it will convert tabs to spaces.
Peter Mortensen
  • 28,342
  • 21
  • 95
  • 123