How can I change the default text editor from gedit to vim? When I click on a text file, I want it to open in vim under the terminal instead of gedit.
5 Answers
You don't say how you are clicking on this file, so I will explain a way to do it in Gnome from Nautilus. It should work in other cases, I believe.
First, to get Vim (or any app) into the "open with other application" list, you need to create a .desktop file in ~/.local/share/applications
with a line in it like this: Exec=<command> %f
. I just made one called vim.desktop with these lines:
[Desktop Entry]
Categories=;
Comment=Edit file in Vim
Exec=vim %f
GenericName=Text Editor
Hidden=false
Icon=vim
Name=Vim
Terminal=true
Type=Application
Version=1.0
This made "Vim" appear in the list of possible apps when I right-clicked in Nautilus, and opened the file as expected.
Let me know if there are any problems.

- 18,466
Open defaults.list
sudo -H gedit /etc/gnome/defaults.list`
Replace
text/plain=gedit.desktop
with
text/plain=gvim.desktop
Save and close.
For more details and screenshot check this answer: How do I stop gedit from opening anything?
-
2Excellent answer! I'd like to add to this to open it with sudo vim /etc/gnome/defaults.list and then use the command %s_gedit_gvim_g – brunch875 Aug 27 '14 at 11:02
-
In general, it's better to set
EDITOR
and usesudoedit
than to run the editor undersudo
– Darael Nov 20 '15 at 14:56 -
Note that in Ubuntu 23.04 the correct path to the
defaults.list
file is/usr/share/applications/defaults.list
. Modification of/etc/gnome/defaults.list
does not have any effect. Also, if you want to replace the default Text Editor with Gedit and vice versa, their desktop entries areorg.gnome.gedit.desktop
and/etc/gnome/defaults.list
respectively. – Kyselejsyreček Apr 20 '23 at 06:54
Save this as ~/.local/share/applications/vim.desktop
:
[Desktop Entry]
Name=Vim Text Editor
Comment=Edit text files
Exec=vim %F
Terminal=true
Type=Application
Icon=vim
Categories=Utility;TextEditor;
StartupNotify=true
MimeType=text/plain;
Then in Nautilus right-click on a text file, choose "Properties" and go to "Open with". If vim isn't shown here click "Show other applications". Select vim and click "Set as default".

- 87,389
The problem with the vim.desktop
approach is that each time it will open a new terminal window, instead of using an existing vim instance. This is probably not what you want, but I don't think there's any way around it.
The next best thing is using gvim
, which is a GUI app, instead of a terminal app.

- 1,351
-
I think by default gvim will also open a new instance. There is a way around this, I think by using a gvim switch. I used to have it open in a new tab with the existing gvim before I reinstalled Ubuntu. – Marty Fried Jan 23 '12 at 01:42
-
Is
gvim
a Gnome app? I think the 'g' stands for 'graphical', not 'Gnome'. – voithos Feb 13 '12 at 06:51 -
Pure command line based method:
echo "[Desktop Entry]
Name=Vim Text Editor
Comment=Edit text files
Exec=vim %F
Terminal=true
Type=Application
Icon=vim
Categories=Utility;TextEditor;
StartupNotify=true
MimeType=text/plain;" > ~/.local/share/applications/vim.desktop
cp /etc/gnome/defaults.list ~/defaults.list.bak # backup
sudo sed -i "s/=gedit\.desktop/=vim\.desktop/" /etc/gnome/defaults.list
mkdir ~/.icons
wget -O ~/.icons/vim.png http://en.xn--icne-wqa.com/images/icones/1/4/vim.png # if you want an icon

- 457
- 2
- 6
- 18
Categories=
. – Noumenon Dec 06 '19 at 00:02