Editing /etc/vimrc on Arch Linux remaps keys successfully because it executes before user-specific configurations, but syntax highlighting often persists due to the default runtime path or conflicting settings in ~/.vimrc. To disable highlighting globally, you must ensure syntax off is placed correctly and check for overriding plugins or file-type detection that re-enables it.
Understanding the Execution Order of Vimrc Files
When you modify/etc/vimrc, you are editing the system-wide configuration file that applies to all users on the Arch Linux installation. Vim loads this file early in its initialization process, which is why your key remappings take effect immediately. However, the behavior of syntax highlighting is more complex because it interacts with the file type detection system.
Vim determines the file type based on the extension or content of the file you open. Once a file type is detected, Vim automatically runs scripts located in the after/ftplugin directories within the runtime path. These scripts often contain commands like syntax enable or specific highlight groups that can override previous settings. If you place syntax off in /etc/vimrc, it might be executed before the file type is even known, leading to the highlighting being turned back on later by these auto-detected plugins.
This design ensures that users get appropriate syntax coloring for code files out of the box. However, for users who prefer a plain text environment or have performance concerns, this automatic behavior can be frustrating. The key is to understand that /etc/vimrc is not the last word; user-specific files and runtime plugins can overwrite its directives.
Distinguishing Between User and System Configurations
It is crucial to distinguish between/etc/vimrc and ~/.vimrc. The former affects every user, while the latter affects only your personal session. If you are trying to disable syntax highlighting for all users, /etc/vimrc is the correct place. However, if you find that changes here are ignored, it is likely because a plugin or a user-level config is re-enabling it. Always check if other users on the system have customized their own ~/.vimrc files, as these are sourced after /etc/vimrc and will take precedence for those specific users.
Why Syntax Highlighting Persists Despite Configuration
The most common reason syntax highlighting remains active when you expect it to be off is the interaction with Vim's built-in file type detection. When you open a file, Vim checks its name against patterns defined in the runtime directory. If it matches a known type, such as.py for Python or .c for C, it triggers the corresponding ftplugin scripts.
These scripts often call syntax on explicitly. Even if you set syntax off in /etc/vimrc, the subsequent execution of the ftplugin script will turn it back on. This is intentional behavior designed to provide a helpful coding experience. Additionally, some distributions, including Arch, may include additional packages or plugins that alter the default runtime path, introducing more opportunities for overrides.
If you are using a minimal Arch installation, you might not have many extra plugins, but the base Vim package itself includes robust file type support. Therefore, simply turning off syntax in the main config file is rarely enough to suppress it for all file types permanently.
Solutions to Disable Syntax Highlighting Globally
To effectively disable syntax highlighting across the board, you need to intervene at the right stage of the initialization process. Here are the most reliable methods to achieve this on Arch Linux.Method 1: Using After Directories
The most robust way to override default behaviors is to use theafter/ directory structure. Vim sources files in after/ directories after the main configuration files. You can create a file in /usr/share/vim/after/syntax/ or manipulate the runtime path to ensure your settings run last. However, a simpler approach for global disabling is to prevent the file type detection from triggering syntax highlighting altogether.
You can add the following line to /etc/vimrc:
filetype off
This command disables the entire file type detection mechanism, which includes syntax highlighting, indentations, and plugins associated with file types. While this solves the highlighting issue, it also removes helpful features like automatic indentation for Python files. Use this only if you do not rely on these features.
Method 2: Explicitly Disabling After Detection
If you want to keep other file type features but just stop syntax highlighting, you can intercept the process. Add this to/etc/vimrc:
autocmd FileType * syntax off
This autocommand triggers every time a file type is detected, immediately turning off syntax highlighting regardless of what the ftplugin script tried to do. This is generally safer than filetype off because it preserves indentation and other non-highlighting features.
Method 3: Checking for Conflicting Plugins
Sometimes, the issue is not Vim itself but a plugin installed via a package manager or manually. On Arch, you might have installedvim-runtime or similar packages that include extra scripts. Check your ~/.vimrc and any plugin managers (like Vundle or Pathogen) to see if they are explicitly enabling syntax. If you find a line like syntax on in your user config, comment it out or remove it. Remember that /etc/vimrc runs first, so user configs will always win if they contain conflicting commands.
For more advanced configuration techniques, you might want to explore broader Vim customization strategies. You can read more about this in our guide on Mastering Vim: A Comprehensive Guide.
Verifying Your Configuration
After making changes to/etc/vimrc, you should verify that they are applied correctly. Restart Vim and open a file with syntax highlighting, such as a .js or .py file. If the colors are still present, run the command :scriptnames in Vim. This lists all scripts that were sourced during startup. Look for lines that mention syntax or ftplugin and check the order. If a script is sourcing after your /etc/vimrc entry, it confirms that an override is occurring.
You can also test the effectiveness of your autocommand by checking the value of the g:syntax_on variable. If it is unset or false, highlighting should be disabled. If you are still experiencing issues, consider checking if your Arch Linux system has updated Vim recently, as version changes can sometimes alter default behaviors or runtime paths.
For those interested in optimizing their editor further, understanding how to merge lines or manipulate text efficiently is also valuable. You can learn about Merging lines with a specific pattern in VIM to enhance your workflow alongside these configuration tweaks.
Frequently Asked Questions
Does editing /etc/vimrc affect all users on Arch Linux?
Yes, changes to/etc/vimrc apply to every user on the system because it is the system-wide configuration file. However, individual user settings in ~/.vimrc can override these global settings for specific accounts.
Why does my syntax highlighting turn back on after I disable it?
This usually happens because Vim's file type detection system runs scripts after your initial configuration. These scripts, located inafter/ftplugin directories, often explicitly enable syntax highlighting for recognized file types, overriding your earlier syntax off command.
Can I disable syntax highlighting without losing indentation features?
Yes, using an autocommand likeautocmd FileType * syntax off allows you to keep file type detection for indentation and other features while specifically suppressing syntax coloring. This is preferable to using filetype off, which disables all file type related functionality.
How can I check which scripts are overriding my Vim settings?
Run the command:scriptnames inside Vim. This lists every script loaded during startup in the order they were sourced. By examining this list, you can identify if a plugin or runtime script is loading after your /etc/vimrc entries and causing the override.