I use Linux and usually run Vim in a terminal. Lately, I've been using Vim's clientserver functionality to interact with Vim remotely. I'm wondering if there's a way to focus the terminal/Vim window when interacting with Vim in this way. For example, in one terminal I run Vim as:

$ vim --servername VIM

and in another terminal I call the following command to open a text file in the first terminal:

$ vim --remote /path/to/file.txt

This command is successful, but doesn't focus the first terminal. Note that I tested this in Arch Linux with both Gnome and i3 window manager, and with both gnome-terminal and xterm.

Also, I've tried using Vim's foreground() command via vim --remote-send ':call foreground()<CR>', as well as the vim -f option. These commands didn't work for me, and based on Vim's documentation, I don't believe they should when Vim is run in a terminal. But please correct me if I'm wrong.

Additionally, I know that I could probably accomplish my goal by combining the Vim remote commands with a shell command that interacts with windows (e.g. xdotool or wmctrl). But I'm wondering if there's a better (and preferably native) way to do this.

1 Answer 1


I don't believe this is possible, other than by the methods you have already suggested.

I don't think Vim knows whether or not the terminal it is in has focus, and it definitely has no method of changing the window manager's state (except shell/system commands such as those you mention).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.