39

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.

Jorge Castro
  • 73,717
philipballew
  • 2,469

5 Answers5

43

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.

Marty Fried
  • 18,944
23

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?

Achu
  • 21,407
12

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

3

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.

scribu
  • 1,351
2

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
texasflood
  • 457
  • 2
  • 6
  • 18