3

I'm using KDE 5 with multiple desktops (in a 3x4 grid) and I regularly open Vim from the command line, e.g. with

gvim file.txt

The problem is when I do this, GVim often appears on a different desktop than the one I am currently focused on. I then have to go and find it, and bring it on to the desktop I am working on. This is inconvenient!

Some other curious details are:

  • As well as opening on the wrong desktop, GVim is always at the back of the window list, so it's hidden behind other windows.

  • (That actually helps me to find it. I have a keybind to cycle windows on all desktops, and since GVim at the far end of the window list, I can find it quickly by cycling backwards.)

  • I have not understood the pattern of which desktop GVim chooses to open on, however it seems to choose a recently used workspace, rather than one of the empty ones I rarely use. On rare occasions, it does actually choose the desktop I am on!

Of all the applications I use, GVim is the only one with this behaviour. How can I stop it?

1

Update: I thought this solution was working, but it isn't working for me now.

It may be part of a solution.

This is probably a better solution, found from this question: https://askubuntu.com/questions/109696/gvim-always-opens-in-workspace-4

The problem may be caused by setting lines and/or columns from your .vimrc

The workaround is to move that setting into an autocommand.

" BAD.  Do not do this.
if has('gui_running')
    set lines=999 columns=999
endif

" GOOD.  Do this instead.
autocmd GUIEnter * :set lines=999 columns=999

However there was one other contributing factor:

  • I had been running gvim filename.txt &

    (The reason is not really important, but: This was part of a script that can start many different editors, some of which do need to be run in the background.)

Using & to run in the background was causing problems. GVim sometimes didn't like that it was disconnected from stdin. Possibly due to some of the plugins I was running. Perhaps Coc or ALE or Vim addon manager was trying to use stdin.

Solution:

  • Don't use & to background the process when starting gvim

    Let gvim background itself.

0

Once again the other solutions are failing me. So now I have a new workaround (for KDE 5):

  • Right click on GVim's titlebar and select More Actions > Configure Special Application Settings

  • Add the property Virtual Desktop

  • Configure that to Apply Initially and All Desktops

    (also known as making the window "sticky")

This will guarantee the window appears on the current desktop.

However it does mean that after the window opens, I need to:

  • Press my keyboard shortcut (or use window buttons) to remove the sticky / all-desktop flag from the window
0

Update: I thought this solution was working, but it isn't working now.

This seems like a rare issue, but I found a thread where people have a similar problem on a different window manager: https://github.com/awesomeWM/awesome/issues/2411

It seems like the problem is that GVim is making a geometry request that causes the window manager to place it on a different desktop.

A workaround is to tell the window manager to ignore GVim's geometry requests.

On KDE 5 that can be done with the following steps:

  • Right click on GVim's titlebar and select More Actions > Configure Special Application Settings

  • Add the property Ignore Requested Geometry

  • Configure that to Force and Yes

Now save the settings. The next time you start GVim, hopefully it will open on the desired desktop!

If you have a different window manager than KDE, you may be able to find a different way to "ignore geometry requests". Hope this helps!

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.