Convert tabs to spaces in Notepad++
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
Introduction
To convert tabs to spaces in Notepad++, go to Edit > Blank Operations > TAB to Space. This converts all existing tab characters in the current document to the equivalent number of spaces based on your configured tab size. To prevent future tabs from being inserted, go to Settings > Preferences > Language > Tab Settings and check Replace by space. These two steps handle both retroactive conversion and forward prevention.
Why Convert Tabs to Spaces
Tabs and spaces are both whitespace characters used for indentation, but they behave differently across environments. A tab character (\t, ASCII 9) is a single byte that gets rendered at a width determined by the viewer's settings. Spaces are literal characters that always occupy exactly one column.
This difference creates real problems:
- Code that looks aligned in one editor breaks in another when tab widths differ (4 vs. 8 is the classic conflict).
- Git diffs become harder to read when contributors mix tabs and spaces.
- Languages like Python treat tabs and spaces as different indentation and will raise
IndentationErrorwhen they are mixed. - Code review tools, terminal output, and web-based viewers all render tabs differently.
Most modern style guides (PEP 8 for Python, Google's style guides for Java and C++, Prettier defaults for JavaScript) standardize on spaces. Converting tabs to spaces in existing files brings them into compliance.
Converting Existing Tabs in the Current Document
This converts all tab characters that already exist in your file:
- Open the file in Notepad++.
- Go to Edit in the menu bar.
- Select Blank Operations.
- Click TAB to Space.
Every tab character in the document is replaced with the number of spaces specified in your tab size setting (default is 4).
To convert in the other direction (spaces back to tabs), use Edit > Blank Operations > Space to TAB (All) or Space to TAB (Leading), which only affects indentation at the beginning of lines.
Configuring Tab Settings for Future Editing
To ensure that pressing the Tab key inserts spaces instead of a tab character going forward:
- Go to Settings > Preferences.
- Click the Language tab on the left.
- In the Tab Settings section on the right, select the language you want to configure (or select [Default] for all languages).
- Check the Replace by space checkbox.
- Set the Tab size to your desired width (2, 4, or 8).
This setting applies to all future keystrokes. It does not retroactively convert existing tabs. For that, you still need the Edit > Blank Operations > TAB to Space step described above.
Per-Language Tab Configuration
Notepad++ allows different tab settings per language. This is useful when you work across projects with different conventions:
| Language | Common Tab Size | Common Convention |
| Python | 4 spaces | PEP 8 mandates 4 spaces |
| JavaScript/TypeScript | 2 spaces | Prettier/Airbnb default |
| Java | 4 spaces | Google/Oracle convention |
| C/C++ | 4 spaces | LLVM, Google style |
| Go | 1 tab | gofmt mandates tabs |
| Makefile | 1 tab | Required by make syntax |
| YAML | 2 spaces | Tabs are illegal in YAML |
| HTML/CSS | 2 spaces | Common web convention |
For Go and Makefiles, keep tabs. Converting to spaces in these languages breaks tools (make requires literal tabs for recipe lines, and gofmt enforces tabs).
Batch Conversion Across Multiple Files
To convert tabs to spaces across an entire project, use Notepad++'s Find and Replace with regular expressions:
- Press
Ctrl+Hto open Find and Replace. - Set Search Mode to Extended (not Regular Expression for this case).
- In Find what, type
\t. - In Replace with, type four spaces (or your preferred width).
- Click Replace All for the current file.
For multiple files, use Find in Files:
- Press
Ctrl+H, then click the Find in Files tab. - Set the Directory to your project folder.
- Set Filters to the file extensions you want (e.g.,
*.py *.js *.java). - In Find what, type
\t. - In Replace with, type your spaces.
- Click Replace in Files.
This approach works but has a limitation: it replaces every tab with exactly N spaces, regardless of column position. The TAB to Space blank operation is smarter because it accounts for tab stops (a tab at column 2 with tab size 4 becomes 2 spaces, not 4). For accurate conversion, use the blank operation on each file individually.
Command-Line Alternatives
When working with many files, command-line tools are often faster than doing it through the GUI:
The expand command is the most accurate because it calculates the correct number of spaces based on tab stop positions rather than doing a flat replacement.
Verifying the Conversion
After converting, verify that no tabs remain:
- In Notepad++, go to View > Show Symbol > Show All Characters.
- Tabs appear as right-pointing arrows. Spaces appear as dots.
- Scroll through the file or use Find (
Ctrl+F) with\tin Extended search mode to locate any remaining tabs.
You can also verify from the command line:
EditorConfig: Enforcing Consistency Across Editors
To prevent tab/space inconsistencies across your team regardless of which editor each person uses, add an .editorconfig file to your project root:
Notepad++ supports EditorConfig through a plugin (Plugins > Plugins Admin > search "EditorConfig"). Most other editors (VS Code, IntelliJ, Sublime Text) support it natively or through built-in plugins.
Common Pitfalls
- Converting tabs in Makefiles:
makerequires literal tab characters before recipe commands. Converting those tabs to spaces causes*** missing separator. Stop.errors. Always exclude Makefiles from batch conversion. - Converting tabs in Go source files:
gofmtenforces tabs for indentation. Converting to spaces meansgofmtwill revert your changes on the next format pass, creating noisy diffs. - Flat replacement vs. tab-stop-aware conversion: Replacing
\twith four spaces using Find and Replace does not account for tab stop positions. A tab at column 6 with tab size 4 should become 2 spaces (to reach column 8), but flat replacement inserts 4. Use Edit > Blank Operations > TAB to Space for correct results. - Mixing tabs and spaces in the same file: After converting, enable Replace by space in Preferences to prevent accidentally introducing new tabs. A single tab in a spaces-only file creates alignment bugs.
- Not configuring version control: Make the tab-to-space conversion a standalone commit with a clear message like "Convert tabs to spaces." Mixing it with logic changes makes code review difficult because every line appears changed.
- Forgetting to set the tab size before converting: If your tab size is set to 8 but your code was written with a 4-space convention, the conversion inserts 8 spaces per tab, doubling your indentation. Check the tab size in Preferences before running the conversion.
Summary
- Use Edit > Blank Operations > TAB to Space to convert existing tabs in the current document.
- Enable Settings > Preferences > Language > Tab Settings > Replace by space to prevent new tabs from being inserted.
- Configure tab size per language to match your project's style guide.
- For batch conversion across many files, use Find in Files with
\tor theexpandcommand-line tool. - Never convert tabs to spaces in Makefiles (required by
make) or Go files (required bygofmt). - Use
.editorconfigto enforce consistent indentation across all editors and team members.

