Running gVim as a single instance

192 views
Skip to first unread message

Bernhard Heijstek

unread,
Oct 24, 2011, 11:40:07 AM10/24/11
to v...@vim.org
I want it in such a way that on double clicking an already opened file, or a new file, gVim uses the same window. From this question asked previously on Stackoverflow (http://stackoverflow.com/questions/936501/let-gvim-always-run-a-single-instance) I figured out how to do this by putting up an alias like:

alias gvim="gvim --remote-tab-silent" || gvim

This works great for the terminal without any problems. To enable this for the desktop too, I tried editing the /usr/share/applications/gvim.desktop. The default execution command in gvim.desktop is:

gvim -f %F

I changed this to:

gvim --remote-tab-silent %F

This gives me trouble when I'm trying to open an already opened file. It takes too long to open and doesn't open in the end. What may have caused the problem? I'm running Gnome 2.x and Vim 7.2.x if it matters. I also tried compiling Vim 7.3 on another machine and the problem still exists.

The Vim Wikia (http://vim.wikia.com/wiki/Launch_files_in_new_tabs_under_Unix) suggests using:

gvim -p --remote-tab-silent %F 


as the execution command in gvim.desktop. This too does not work.

Ben Fritz

unread,
Oct 25, 2011, 12:00:06 PM10/25/11
to vim_use


On Oct 24, 10:40 am, Bernhard Heijstek <bernhard.heijs...@yahoo.com>
wrote:
> I want it in such a way that on double clicking an already opened file, or a new file, gVim uses the same window. From this question asked previously on Stackoverflow (http://stackoverflow.com/questions/936501/let-gvim-always-run-a-singl...I figured out how to do this by putting up an alias like:
>
> alias gvim="gvim --remote-tab-silent" || gvim
>
> This works great for the terminal without any problems. To enable this for the desktop too, I tried editing the /usr/share/applications/gvim.desktop. The default execution command in gvim.desktop is:
>
> gvim -f %F
>
> I changed this to:
>
> gvim --remote-tab-silent %F
>

I will preface this by saying, I have no idea how gvim.desktop works
or what it does. I'm starting to use Ubuntu on a somewhat regular
basis, but I'm still a Linux noob.

Nevertheless, "gvim -f" does something ENTIRELY different from gvim --
remote{anything} and this may cause a problem.

gvim -f prevents the GUI from forking. This is normally used for when
you want to use gvim as your editor in processes which expect the
editor to launch and block execution until you're done editing. For
example, as the editor used to enter comments in a Mercurial or
Subversion checkin.

The --remote series of commands, by comparison, launches a Vim which
does nothing except forward a command to a different (existing) Vim
instance, and then exits.

Obviously, if an application is expecting the first behavior, and gets
the second, problems may happen. But again, I have no idea what this
gvim.desktop file is expecting.

> This gives me trouble when I'm trying to open an already opened file. It takes too long to open and doesn't open in the end. What may have caused the problem? I'm running Gnome 2.x and Vim 7.2.x if it matters. I also tried compiling Vim 7.3 on another machine and the problem still exists.
>
> The Vim Wikia (http://vim.wikia.com/wiki/Launch_files_in_new_tabs_under_Unix) suggests using:
>
> gvim -p --remote-tab-silent %F 
>
> as the execution command in gvim.desktop. This too does not work.

The -p should be unnecessary. The --remote-tab-silent should do that
for you. But it suffers the same problem as above, if indeed it is a
problem.

Bernhard Heijstek

unread,
Oct 27, 2011, 5:38:49 PM10/27/11
to vim...@googlegroups.com
I finally figured a way to do this. The catch was to change the value of "StartupNotify" in /usr/share/applications/gvim.desktop from "true" to "false"

Source: http://www.phacks.net/open-multiple-text-files-as-tabs-gvim-kde4

Reply all
Reply to author
Forward
0 new messages