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.


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]
Comment=Edit file in Vim
Exec=vim %f
GenericName=Text Editor

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.

  • Just saw another answer when I posted this. Looks like I wasted time, but perhaps it will help anyway, somehow. – Marty Fried Jan 22 '12 at 22:18
  • Glad I could help. Thanks for letting me know. I learned something new, too, as I didn't know the answer, but decided it would be nice to know (and an exercise for my brain). :) – Marty Fried Jan 24 '12 at 19:22
  • BTW, from a different thread, if you want to use vim automatically instead of gedit for all types of files. I think you could edit /etc/gnome/defaults.list, and replace gedit with vim, to use the vim desktop file. I haven't tested this, though. – Marty Fried Jan 29 '12 at 21:21
  • 1
    +1 Excellent tip. Not necessarely for vim, but in general to add new applications to Open with... – bioShark Feb 1 '12 at 21:01
  • If you want vim to be the default choice for a file extension, not just another choice, add that extension to the Categories=. – Noumenon Dec 6 '19 at 0:02

Open defaults.list

sudo -H gedit /etc/gnome/defaults.list`





Save and close.

For more details and screenshot check this answer: How do I stop gedit from opening anything?

  • 2
    Excellent 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 use sudoedit than to run the editor under sudo – Darael Nov 20 '15 at 14:56

Save this as ~/.local/share/applications/vim.desktop:

[Desktop Entry]
Name=Vim Text Editor
Comment=Edit text files
Exec=vim %F

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".


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.

  • 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 1:42
  • Is gvim a Gnome app? I think the 'g' stands for 'graphical', not 'Gnome'. – voithos Feb 13 '12 at 6:51
  • @voithos: Indeed, the 'g' doesn't stand for 'Gnome'. Corrected. – scribu Feb 13 '12 at 8:01

Pure command line based method:

echo "[Desktop Entry]
Name=Vim Text Editor
Comment=Edit text files
Exec=vim %F
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

Not the answer you're looking for? Browse other questions tagged or ask your own question.