The 'edit existing' plugin for vim/vim.gtk3 which worked well in previous installs and did exactly what the OP is requesting, got broken on Xubuntu 24.4 (with vim9.1).
This worked out-of-the box on Ubuntu 20.4 and 22.4 - they had a script named 'editexisting' in the /usr/share/vim/vim(version)/pack/dist/opt/editexisting/plugin/ directory, which was auto-activated via a script in the /usr/share/vim/addons directory.
This is no longer the case in the vim9 install on Ubuntu 24 - and even if you enable it by adding packadd! editexisting in your ~/.vimrc file, it finds the existing instance, but fails to raise its window to the foreground.
Here is what I did on Xubuntu 24.4, which fixed it for me.
(1) copy the editexisting.vim script to a place where it will be auto-loaded (don't do this, if on your OS it is already being loaded, but just doesn't work - instead, edit the file where it is as per step (2) below, or disable the OS installed copy before making your own). Note, the file location is for vim9.1, change as needed:
mkdir -p ~/.vim/plugin cp /usr/share/vim/vim91/pack/dist/opt/editexisting/plugin/editexisting.vim ~/.vim/plugin
Try it out: when re-opening a file that's already edited, gvim will no longer display an error about the swap file existing, instead it should show a message like File is being edited by <instancename>.
If that works, but the window isn't raised, do:
(2) make a replacement for the vim's 'foreground()' function, which no longer works on some window managers (it is BROKEN on my Xubuntu 24.04, for example).
# get wmctrl, if not installed already # (use your OS package manager in place of 'apt-get install', as needed) sudo apt-get install wmctrl mkdir -p ~/bin # or ~/.local/bin or whatever you have in the PATH cat >~/bin/raise_gvim <<"END" #!/bin/sh [ -z "$1" ] && exit 1 wid=`wmctrl -l | awk '/ '"$1"'$/ {print $1}'` [ -z "$wid" ] && exit 1 # echo $wid wmctrl -i -R "$wid" # NOTE: use '-a' instead of '-R', if you prefer to have the WM jump to the workspace # where the window is, rather than bring it to the current workspace. END chmod +x ~/bin/raise_gvim
Re-start your shell, to ensure ~/bin is in the PATH (required, if you just created ~/bin - in many distros, the /etc/profile script doesn't add ~/bin if it doesn't exist).
Test it, before proceeding - the wmctrl command worked for my window manager, but there's no guarantee that it will work for you. Edit something with gvim, note the instance name, it will normally be something like GVIM, GVIM1, GVIM2, ... Switch to a shell window and run this:
raise_gvim GVIM1 # replace the instance name, as needed
If this raises your editor window, you're almost set. Now, edit ~/.vim/plugin/editexisting.vim and replace
call remote_expr(servername, "foreground()")
with this:
exe ":silent !raise_gvim " . servername
NOTE: the old answer suggesting the use of --remote or --remote-silent DOES NOT WORK. First, it will mess up if you do 'gview' on a file that's already open with 'gvim' or vice-versa. Also, it will cause all files to be edited in the same instance of GVIM (in a single window-manager window) rather than open a new one for each new file. That's not what most people want when they use the GUI variant of VIM.