Frustrated by Formatting? Fixing Ubuntu Text Editor Tab Settings
In the world of Linux development, few things are as subtly maddening as a text editor that refuses to obey your indentation rules. You set your "Spaces per Tab" to 4, yet the cursor stubbornly jumps 2 spaces, or worse, inserts a literal tab character in a project that requires soft spaces. On Ubuntu, this issue is rarely a simple "glitch." Instead, it is usually the result of a hierarchical conflict where local project configurations, system-level GSettings, or "Adaptive Formatting" features override your manual preferences. Whether you are using the classic Gedit, the modern GNOME Text Editor, or VS Code, understanding the priority of these settings is key to regaining control over your code's whitespace.
Table of Content
- Purpose: Why Indentation Settings Fail
- The Hidden Culprits: EditorConfig and GSettings
- Step-by-Step: Troubleshooting by Editor Type
- Use Case: Python Indentation Errors
- Best Results: Enforcing Universal Standards
- FAQ
- Disclaimer
Purpose
The goal of this guide is to help you identify why your preferences are being bypassed. In Ubuntu, the "Text Editor" (gnome-text-editor) and older tools like Gedit rely on different backends. We will cover:
- Conflict Resolution: Identifying if a
.editorconfigfile is dictating terms to your editor. - System Overrides: Using
gsettingsto force the desktop environment to respect your choices. - Detection Logic: Disabling "Detect Indentation" features that guess your settings based on existing files.
The Hidden Culprits: EditorConfig and GSettings
Most modern editors prioritize Project-Specific Configs over Global User Settings. If you are working in a repository that contains a .editorconfig file, your editor will automatically adjust to the project's standard (e.g., 2 spaces) regardless of what your UI says.
Additionally, the default GNOME Text Editor in newer Ubuntu releases (24.04 and 25.10) sometimes fails to save UI changes to the DConf database. When the UI and the backend database (GSettings) desync, the editor defaults to its hardcoded behavior.
Step-by-Step: Troubleshooting by Editor Type
1. For GNOME Text Editor / Gedit (The Terminal Fix)
If the UI menu isn't working, you can force the setting through the terminal. This writes directly to the system's configuration database.
# For the modern GNOME Text Editor (Ubuntu 24.04+)
gsettings set org.gnome.TextEditor indent-width 4
gsettings set org.gnome.TextEditor tab-width 4
# For the classic Gedit
gsettings set org.gnome.gedit.preferences.editor tabs-size 4
gsettings set org.gnome.gedit.preferences.editor insert-spaces true
2. For Visual Studio Code (The "Detect" Fix)
VS Code has a feature called "Detect Indentation" that analyzes the file you just opened. If the file was written with 2 spaces, VS Code will switch your settings to 2 spaces automatically.
- Open Settings (
Ctrl + ,). - Search for "Detect Indentation" and uncheck the box.
- Search for "Tab Size" and set it to your preferred number.
- Check for a
.vscode/settings.jsonfolder in your current workspace, as this will override global settings.
3. Check for .editorconfig
Run the following command in your project root to see if an invisible config is haunting you:
find . -name ".editorconfig"
If found, you must either edit that file to match your preferences or delete it (though deleting it may break team formatting standards).
Use Case: Python Indentation Errors
A developer is working on a Python script where TabError: inconsistent use of tabs and spaces keeps appearing despite the editor showing "4 spaces."
- The Problem: The editor was set to 4 spaces, but "Insert Spaces" was toggled off, causing it to mix real Tab characters with spaces.
- The Fix: The developer used
gsettings set org.gnome.gedit.preferences.editor insert-spaces trueand then used the "Convert Tabs to Spaces" feature within the editor. - The Result: The Python interpreter successfully ran the script, and the visual 4-space indent remained consistent across all systems.
Best Results
| Scenario | Primary Action | Result |
|---|---|---|
| UI Settings Ignored | Use gsettings terminal commands |
Forces backend database update |
| Shared Projects | Create a .editorconfig file |
Overrides everyone's editor to match |
| Mixed Files | Disable "Detect Indentation" | Prevents the editor from guessing wrong |
| Visual Confusion | Enable "Draw Whitespace" | See exactly where tabs/spaces are used |
FAQ
Why does my tab size change when I open a specific file?
This is likely due to Adaptive Formatting or EditorConfig. The editor is trying to be helpful by matching the existing style of the file so you don't introduce "messy" diffs in version control.
I changed GSettings but nothing happened. Why?
Make sure you are targeting the right editor. Ubuntu 24.04 switched from gedit to gnome-text-editor as the default. The settings for one do not affect the other.
Is there a way to see tabs vs spaces?
In most editors, look for a "Render Whitespace" or "Show Invisibles" option in the View menu. In GNOME Text Editor, you can enable this via: gsettings set org.gnome.TextEditor draw-spaces ['tab', 'space'].
Disclaimer
Modifying system gsettings can affect all instances of the application. Be cautious when using --break-system-packages or similar force commands in other contexts. This guide assumes a standard Ubuntu GNOME environment. If you are using KDE (Kate) or XFCE (Mousepad), the configuration paths will differ.
Tags: Ubuntu_Linux, TextEditor, Gedit, Coding_Standards