Is it possible to use terminal vim with xdg-open?

I don't have a GUI text editor because I only use vim through the terminal. (I don't care very much for gvim either.) Is it possible to tell xdg-open to open a terminal, then open vim with the selected file?


  • I'm posting a partial answer so people can complete them later. I haven't understood which types of files you want to open with vim. I'm assuming text/plain only. – thiagowfx Jan 7 '15 at 16:32

In either your .bashrc or .zshrc, depending whether you use bash or zsh respectively, export these two environment variables:

export EDITOR=vim
export VISUAL=vim

Adittionally, you might want to associate vim to the mimetype of text files:

xdg-mime default vim.desktop text/plain

Now you'll have to create a vim.desktop file in /usr/share/applications, which should execute the terminal emulator you want, opening vim.


I have to put a new answer, even if my comment only completes the answer by thiagowfx, because in the comments you cannot indent code.

The content of vim.desktop can be something like this:

[Desktop Entry]
Name=Vim Text Editor
Comment=Edit text files

I prefer to put it under ~/.local/share/applications.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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