1

I need to set on my Linux box VIM as default mime application for editing text file. On zsh I managed to wrap a function from vim --remote. But I would like to use it for default xdg-mime application (in the same way emacsclient is doing for emacs).

2

xdg-open relies on .desktop files, so you'll have to create on and then associate it with the right mimetypes. If you can't/won't use GVim, you can still piggy-back on its .desktop file.

$ grep -v Comment /usr/share/applications/gvim.desktop 
[Desktop Entry]
Name=GVim
GenericName=Text Editor
GenericName[de]=Texteditor
TryExec=gvim
Exec=gvim -f %F
Terminal=false
Type=Application
Icon=vim
Categories=Utility;TextEditor;
StartupNotify=true
MimeType=text/plain;

Copy the contents to a vim.desktop, while:

  • replacing gvim with vim for TryExec
  • using your vim --remote command for Exec. %F, as you might have deduced, will be replaced with the filenames.

Then, copy this to ~/.local/share/applications and mark it as executable:

cp vim.desktop ~/.local/share/applications
chmod +x ~/.local/share/applications/vim.desktop

In whatever method you use to access launchers for your installed apps (Unity's Dash, GNOME Shell's Overview, MATE/XFCE/Clementine's menu, etc.), you should see a new Vim entry, indicating that the .desktop file was correctly created.

Now, to associate it with text files, you can do:

xdg-mime default vim.desktop text/plain
| improve this answer | |
  • @EnricoPirani out of curiosity, what is your vim --remote command? Can you add it to the question? – muru Sep 24 '15 at 12:36
  • you mean the zsh snippet? – Enrico Pirani Sep 24 '15 at 13:07
  • @EnricoPirani yes, or whatever you will be using in the .desktop file. – muru Sep 24 '15 at 13:09
  • For vim.desktop as you wrote I used vim --remote %F – Enrico Pirani Sep 24 '15 at 13:12
  • @EnricoPirani Sigh. Being Vim, I imagined some complex incantation. :D – muru Sep 24 '15 at 13:13

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.