To set a custom text editor like vim as the default in MATE, open the Main Menu, navigate to Preferences > Preferred Applications, select the Utilities tab, and change the Text Editor dropdown to "Other." Enter the full path to your executable, such as /usr/bin/vim, or use x-terminal-emulator -e vim if you need it to launch within a terminal window for proper functionality.
Understanding Default Application Handlers in MATE
The MATE desktop environment relies on a system of MIME types and associated handlers to determine which application opens specific file formats. When you double-click a text file, the desktop environment checks its internal database to see which program is registered as the handler for that specific type. In many Linux distributions, the default text editor is set to a graphical application likemousepad or gedit. However, developers often prefer command-line tools like vim or nano for their efficiency and customization capabilities.
Changing the default editor through the GUI does not always update the underlying system configuration correctly, especially for terminal-based applications. This is because GUI editors run directly in the X11 or Wayland session, while terminal editors require a shell environment. If you simply select vim from the list without specifying how it should be launched, the system may fail to open the file or throw an error because it attempts to run the binary in a context that doesn't support standard input/output streams properly. Therefore, understanding the distinction between GUI and terminal execution is crucial for this configuration.
For more advanced configurations involving Vim, you might also want to check out Vim on Arch: /etc/vimrc can remap keys but not turn off syntax highlighting to ensure your editing experience is optimized after setting it as the default.
Navigating the Preferred Applications Interface
The primary interface for managing these defaults in MATE is the "Preferred Applications" tool. You can access this by clicking the MATE menu button (usually located at the bottom left or top left depending on your panel setup), typing "Preferred Applications" into the search bar, and launching the result. Alternatively, you can run the commandmate-preferred-applications in your terminal to open the dialog directly.
Once the window opens, you will see several tabs corresponding to different categories of applications: Web Browser, Mail Reader, Calendar, and Utilities. The Text Editor setting is located under the Utilities tab. By default, this dropdown likely shows a specific application name. To change it, you must click the dropdown menu. If your desired editor is listed there, you can select it directly. However, if you are using a less common editor or one that requires specific launch flags, you will need to select the "Other..." option at the bottom of the list.
Configuring Vim as the Default Editor
Selecting "Other..." opens a dialog where you can manually specify the command to execute. This is the most critical step for ensuring thatvim works correctly when invoked by the file manager. There are two main approaches here: launching vim directly or wrapping it in a terminal emulator.
If you choose to launch vim directly by entering its absolute path (e.g., /usr/bin/vim), the behavior depends on your system's configuration. On some systems, this might work if vim is aliased to a GUI version or if the desktop environment automatically spawns a terminal. However, this often results in the terminal closing immediately after the file opens, or the editor appearing in the background without a visible window, making it difficult to interact with.
A more robust solution is to force the editor to run inside a terminal. This ensures that vim has access to the necessary stdin/stdout channels and remains visible. To do this, you can use the generic terminal emulator command available on most Linux systems. Enter the following command in the "Command" field:
x-terminal-emulator -e vim %F
In this command, x-terminal-emulator is a symbolic link that points to your preferred terminal application (such as gnome-terminal, xfce4-terminal, or mate-terminal). The -e flag tells the terminal to execute the subsequent command upon opening. vim is the editor itself. The %F placeholder is important; it represents the full path to the file being opened. Without this placeholder, the editor would open without any file loaded, forcing you to manually open the file from within vim, which defeats the purpose of setting a default handler.
If you prefer to use a specific terminal emulator rather than the generic link, you can replace x-terminal-emulator with the actual command, such as mate-terminal or gnome-terminal. For example:
mate-terminal -e vim %F
This approach guarantees compatibility across different MATE setups. After entering the command, click "OK" to save the changes. Your new default text editor is now configured.
Verifying and Troubleshooting the Configuration
After saving the settings, it is essential to verify that the change took effect. Open your file manager (Nemo in MATE) and locate a plain text file, such as a.txt or .md file. Double-click the file. A terminal window should open, and vim should launch with the content of that file ready for editing.
If the file opens in the wrong editor, the system might be caching old preferences or using a different MIME type association. You can clear the cache by logging out and logging back in, or by running gtk-update-icon-cache if necessary. In rare cases, the MIME type associations might be stored in user-specific configuration files rather than the global preferred applications database. You can inspect these files by checking ~/.config/mimeapps.list. Look for lines starting with text/plain= to see what is currently assigned. If the entry there differs from your preferred application setting, you may need to edit this file manually or reset the associations using the xdg-mime command.
For those who have just installed Vim and are facing issues with key mappings or syntax highlighting after setting it as the default, refer to Mastering Vim: A Comprehensive Guide for deeper insights into configuring your environment.
Handling Multiple Editors
You are not limited to setting only one default editor. You can configure different editors for different MIME types. For instance, you might wantvim for source code files (text/x-script) and a lightweight GUI editor for simple notes. This granular control allows you to tailor your workflow precisely to your needs. The Preferred Applications interface provides a broad stroke for general text files, but for specialized workflows, manual MIME type editing offers greater flexibility.
Frequently Asked Questions
Why does my terminal close immediately after opening a file?
This usually happens because the command lacks the file path placeholder. Ensure you include %F at the end of your command string so the terminal knows which file to pass to vim. Without it, the editor launches empty and may exit if configured to quit on no arguments.
Can I use nano instead of vim for the default editor?
Yes, you can substitute vim with nano in the command string. Use x-terminal-emulator -e nano %F to set Nano as your default. The process is identical regardless of the specific terminal-based editor you choose.
How do I revert to the original default text editor?
Return to Preferred Applications > Utilities > Text Editor and select the original application from the dropdown list, such as Mousepad or Gedit. If "Other..." was selected previously, changing it back to a standard application will override the custom command.
Does this change affect all users on the system?
No, the Preferred Applications settings are typically stored in the user's home directory configuration files. Only the account you are currently logged into will see this change. Other users will retain their own default editor settings unless you modify system-wide MIME type configurations.
What if x-terminal-emulator points to the wrong terminal?
You can check which terminal x-terminal-emulator links to by running readlink -f $(which x-terminal-emulator) in your current terminal. If it is incorrect, you can update the alternatives using your distribution's package manager or replace x-terminal-emulator with the explicit name of your preferred terminal in the Preferred Applications command.