Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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.

share|improve this question

4 Answers 4

up vote 28 down vote accepted

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=Process Viewer

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.

share|improve this answer
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
Thanks! this seems to work pretty well! –  philipballew Jan 24 '12 at 7:21
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 Excellent tip. Not necessarely for vim, but in general to add new applications to Open with... –  bioShark Feb 1 '12 at 21:01

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

share|improve this answer

Open defaults.list

sudo gedit /etc/gnome/defaults.list





Save and close.

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

share|improve this answer
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 at 11:02

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.

share|improve this answer
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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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