I was thrilled to notice a GNOME launcher for vim in the vim-common package after I upgraded to Ubuntu 16.04, since it offers an alternative to gvim (a solid app, though not perfect for my workflow). But there is a problem with the vim launcher, reproduced easily as follows:

  1. Right-click a file and Open With > Vim (not Gvim!)... vim runs on your file in a terminal.
  2. Make some changes, but don't save them.
  3. Close the window from the title bar, as you would close gvim or any other app with pending changes.
  4. The changes are lost, since the vim process dies along with the terminal (leaving a swapfile)

I'd like to find a best-practice way of fixing the vim.desktop file (system version in /usr/share/applications) to make the vim launcher a viable alternative to gvim, since that default launcher is like an accident waiting to happen.

The option Terminal=true seems like a given, but Exec=vim %F is vulnerable to the window dying and therefore should be replaced with a wrapper script... but I need advice on

  • how that wrapper might handle the signal of the parent terminal dying
  • how to handle the dialogue with the user about saving the file

It seems to me like the second of these tasks is impossible, since you'd have to do IPC with the vim session itself to demand the file be saved or abandoned, according to the user's choice... but I thought I'd ask here before giving up.

I already know gvim is a workaround but that wouldn't be an answer to the question itself. I am just surprised that this weak vim launcher is provided with Ubuntu & other distros when it invites catastrophe into the editing process.

  • 3
    This is somewhat very difficult to address. The problem is that what is being sent when you press close window button is signals to Xorg server . The server will then close/kill the window, and that means all the children of that window (including the shell and vim) will receive SIGTERM as far as I know. Your best bet is to keep the swap files and remember to save them. And realistically speaking, vim is a command-line app. It's not designed to deal with signals from GUI – Sergiy Kolodyazhnyy Apr 23 '16 at 19:42

The answer lay in pursuing my inclination that a wrapper script was needed, with that script providing the means to run an interactive subshell (-i option to bash):


#!/bin/bash -f
bash -ic 'vim "$@"' vim "$@"

... then edit /usr/share/applications/vim.desktop or copy it to a new *.desktop file, with these changes:

Exec=gnome-terminal -e "vim-gnome-wrap %F"

Thanks to @muru for pointing out the other thread Unix & Linux: Terminal and Vim, where for the sake of the larger community I have provided a more detailed answer.


This problem has been discussed on Unix & Linux. Quite simply, there's no real way to do this. The simplest workaround is to run Vim in screen or tmux. Instead of:

Exec=vim %F


Exec=screen vim %F

Then, even if you do close the terminal, you can open another terminal and resume the session:

$ pgrep screen -a 
974 gnome-screensaver
7853 SCREEN vim
$ screen -r

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.