4

I have just setup the nice inverse search feature, from okular, by using the command gvim --remote-silent +%l %f as a custom-editor.

It seems to work perfectly fine except a small bug that has been annoying me for the last many hours:

Once the shift+click is used in okular, the cursor in the gvim window has indeed moved to the right location, but the window-in-focus (or active window, or current window or window-in-selection) has not been shifted to gvim window. I have to manually select the vim window either by mouse or by keyboard shortcuts such as Alt+tab.

On the other hand its annoying to see that, if I used kile editor to setup this inverse search, the focus is indeed being shifted to kile!

Additionally, there was no such problem with forward search, setup from Vim using the instructions to invoke okular by a system call to okular --unique .... according to these instructions. The focus indeed shifted to okular as expected.

PS: I am on Ubuntu 14.04

7
  • Does gvim take the focus but the window does not rise? Or does it not take the focus? Either way, this is probably a matter for your window manager and will depend on which one you're using. It may be that you can configure the command to tell gvim to request focus/rise. But whether that's permitted will still depend on your window manager in the end.
    – cfr
    Jul 4, 2016 at 14:40
  • Wouldn't it be better to switch to Emacs, a real editor after all?
    – Keks Dose
    Jul 4, 2016 at 15:29
  • @cfr yes you are right. my problem is only that the window doesn't focus and also doesn't raise. My window manager is exactly what Ubuntu-14.04 LTS gives by default. And I strongly believe there should be a way. Jul 5, 2016 at 1:49
  • 1
    @KeksDose Please don't bring vim/emacs flame wars here. Really.
    – cfr
    Jul 5, 2016 at 1:59
  • Since I use Kile and it just works, I'm not likely to be much help. But I could, if I needed to, set Kile-specific settings to control focus using my window manager's option. As it is, I have focus-stealing-prevention set to 'Low' globally anyway. I deliberately have focus and raise distinct (click to raise, but focus follows mouse). So the global stuff seems to be enough for my Okular/Kile combo. (It is sometimes slow, but only if the window hasn't been active for a while.) I suspect your best bet is to ask on an Ubuntu board rather than here.
    – cfr
    Jul 5, 2016 at 2:03

1 Answer 1

2

I found a solution for this problem. The idea is to use xdotool. See also this question on askubuntu.com.

1. Install xdotool

On Ubuntu you can do this by

sudo apt install xdotool

2. Write a bash script

Save the following script as gvim-raise.sh somewhere on your $PATH.

#!/bin/bash    
gvim --servername GVIM --remote +$1 $2 ; xdotool search --name "/* - GVIM" windowactivate

Make it executable by

chmod +x gvim-raise.sh

3. Configure Okular

Put this line in Okular's editor option

gvim-raise.sh %l %f

Then everything should work as expected.

1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .