Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Focus Events Not Firing #1

Open
Morley93 opened this issue Mar 24, 2015 · 29 comments
Open

Focus Events Not Firing #1

Morley93 opened this issue Mar 24, 2015 · 29 comments

Comments

@Morley93
Copy link

I recently installed this plugin and can't get it to trigger focus events as advertised. My installation was performed using the Plug plugin manager as specified on the readme. I have put set -g focus-events on into my tmux.conf file and made sure it is sourced prior to testing. I have also tried setting tmux focus events manually as an ex command as described in the reproduction steps. Additionally, I have tried using my preferred terminal emulator (urxvt) with the same result.

Details

OS: Arch Linux
vim version: 7.4 (up to date from Arch Linux gvim package at the time of posting, configuration attached).
tmux version: 1.9a
Gnome terminal version: 3.14.2-1

Steps to reproduce

  1. Open tmux in gnome-terminal.
  2. Enter the tmux ex command :set -g focus-events on
  3. Open a file with vim.
  4. Open the file from step 3 in another editor, make modifications and save.
  5. Refocus vim.

Expected behaviour: Vim immediately gives a notification that the file has changed, prompting to reload it by pressing L.
Actual behaviour: Vim gives no notification that the file has changed.

Thanks in advance for any support on this.

Attachments

vimversion

@bruno-
Copy link
Member

bruno- commented Apr 2, 2015

Hi,
thank you for the detailed info about the issue.

I think the issue might be in step 2. You're doing this :set -g focus-events on *after* tmux started. Did you try setting this option in your tmux.conf and *starting* tmux process with that option?

See this comment from the guy that had a similar issue in vitality.vim plugin.

Let me know the result!

@adambiggs
Copy link

I'm having the same problem in NeoVim/iTerm on mac. I have focus-events turned on in my tmux.conf.

tmux 1.9a
zsh 5.0.7
NeoVim 0.0.0-alpha+201504021155
iTerm2 2.9.20150330-nightly

@bruno-
Copy link
Member

bruno- commented Apr 3, 2015

Hey,
I couldn't make this work with neovim. It's "documented" in the readme section here.

Can you please try vanilla vim?

@Morley93
Copy link
Author

Morley93 commented Apr 3, 2015

Just to clarify, I do have set -g focus-events on in my tmux.conf to ensure that the option is set when the tmux process starts. I have also tried this on another of my Arch Linux machines (with both gnome-terminal and urxvt) with the same results.

Perhaps another of my vim/tmux plugins/options is conflicting and preventing the plugin from working?

@adambiggs
Copy link

@bruno- oops I missed that note about it not working in NeoVim.

@bruno-
Copy link
Member

bruno- commented Apr 8, 2015

@Morley93, what is the result of running this in vim's command line:

:set <F24>
:set <F25>

The output should look like this for F24 and F25 respectively

t_FE <F24>       ^[[O
t_FF <F25>       ^[[I

@Morley93
Copy link
Author

Morley93 commented Apr 9, 2015

I can confirm that on my setup, the output of both of those commands is as you described.

setcmds

@jasonbcox
Copy link

I also tried the same procedure as @Morley93 and I couldn't get the focus events to fire. I'm also using tmux 1.9a, but I'm on OSX using Terminal.app.

@bruno-
Copy link
Member

bruno- commented May 19, 2015

Hey guys,
sorry to see this is still not working for some..
Here are debugging steps to use within tmux:

  1. run $ tmux show -s, output should contain focus-events on

  2. in vim run:

    :set <F24>
    :set <F25>
    

    the output should look like this:

    t_FE <F24>       ^[[O
    t_FF <F25>       ^[[I
    
  3. if the above 2 steps are both ok, then run this in vim's command line:

    au FocusGained * echo 'foo'
    

    This will setup a simple "trigger" for focus gained event. Now move to another tmux window and focus the window with vim again. You should now see foo message in vim.

  4. If step 3 ran ok, everything is fine. But to verify file autoread is working fine, you can do these steps:

    • make sure you have set autoread in your .vimrc
    • pick a random file and in tmux window 1 open vim <file>
    • in tmux window 2 open another instance of vim with the same file vim <file>
    • in vim in tmux window 2 make a small change to the file, for example add an empty line somewhere
    • now move back to tmux window 1 where the first vim instance is running. You should see the file change automatically without any prompts from vim.

Hopefully the above steps help, let me know if you get stuck at any point.

@Morley93
Copy link
Author

Thanks for the input @bruno-, I can confirm that all of the steps you provided are working as described when I have autoread set. I can see that the focus event fires whenever the tmux pane containing vim gains focus (when you switch to that pane either from a different pane or a different tmux window).

In my initial testing, I was expecting the event to fire when changing focus between different windows in my window manager. For instance:

  1. Open foo.txt in terminal/tmux/vim.
  2. Open foo.txt in Sublime, make a change and save.
  3. Refocus the terminal.
  4. The change in the file is detected by vim (no need to switch tmux pane/window).

Is this functionality not supported?

@bruno-
Copy link
Member

bruno- commented May 21, 2015

Hi @Morley93,
thanks for confirming!

About the question "I was expecting the event to fire when changing focus between different windows in my window manager": yea, I see how that would be very useful. I think this might be dependent on the terminal application you're using. I just tested this on OSX and here's some quick results:

  • it's *working* for iTerm when tmux is running inside the window
  • not working for iTerm running plain bash + vim inside (no tmux)
  • not working for Terminal.app (with or without tmux)

From what I know iTerm has a very good integration with Tmux so I think that's why the first case is woking.

So, if I'm not wrong, it's up to terminal applications to implement "focus gained", "focus lost" functionality. Please correct me if someone has more knowledge about this..

@expipiplus1
Copy link

I've opened a pull request to add support for focus events in neovim (neovim/neovim#3488). I'd be grateful to anyone willing to give this a test :)
It's working very well for me at the moment.

@SchDen
Copy link

SchDen commented Nov 14, 2015

@expipiplus1 i use neovim. Thanks you very much

@bruno-
Copy link
Member

bruno- commented Nov 14, 2015

Hi @expipiplus1,
thanks, I've added a note about your PR in the readme so people can upvote the feature. Hope it's merged soon.

@ghost
Copy link

ghost commented Nov 19, 2015

Hi @bruno-,
neovim/neovim#3488 was just merged and your plugin now works for me, so perhaps the README should be updated. I didn't submit a PR to update the README as I'm not sure if focus events are working for others as well.

@SchDen
Copy link

SchDen commented Nov 27, 2015

@pyrohh within terminal you use?

@SchDen
Copy link

SchDen commented Nov 27, 2015

This work for me, but i not see this message (after focus):

@ghost
Copy link

ghost commented Nov 27, 2015

@SchDen

I'm pretty sure that message is to be expected, as long as it happens immediately after FocusGained.

@bruno-
Copy link
Member

bruno- commented Nov 29, 2015

@pyrohh, please open a PR for the readme update.

@ghost
Copy link

ghost commented Nov 29, 2015

@bruno-, sure thing, I just opened one.

@justinmk
Copy link

justinmk commented Mar 6, 2016

Can the readme be updated to either remove the line or just change it to say "not needed with Neovim" instead of "not working"?

@P4Cu
Copy link

P4Cu commented Jul 29, 2016

It also does not work for switching native windows in gnome-terminal but xterm handles it perfectly.

@ericboehs
Copy link

ericboehs commented Sep 24, 2016

I'm getting stuck at Step 3, au FocusGained * echo 'foo'.

It doesn't output anything. <F24> is set and tmux show -s shows focus-events on.

I'm on Sierra with Terminal 2.7.1 (380). I've also tried iTerm 2 (3.0.10). I'm using tmux 2.2. Vim 8.0 2016 Sep 12; patches 1-3 included. I also had tried this on a recent version of Vim 7.4 and saw the same problem.

@ericboehs
Copy link

ericboehs commented Sep 27, 2016

Okay so this is weird. If I:

  1. Open vim
  2. Run :au FocusGained * echo 'foo'
  3. Switch to a different tmux pane and then back again

There's no output of 'foo'.

But... if before step 3 I run :!, I do get the output of 'foo' and then everything starts working as expected. It seems calling any external command will fix it (e.g. running K to look up a word in the man page).

@ericboehs
Copy link

ericboehs commented Sep 27, 2016

Figured it out!

I started commenting out everything in my vimrc and it started working.

Turns out I was calling silent !stty -ixon > /dev/null 2>/dev/null and for some reason that broke it. I was calling it so that I could use Ctrl-S and Ctrl-Q as keybindings, but that no longer seems necessary (in zsh 5.2/ mac OS Sierra).

Edit: stty -ixon is still necessary. Moving it to my .zshrc instead of .vimrc is the fix.

@alexpopov
Copy link

Sorry to necro.

re: Step 2 , I do not have <F25> and <F24> set in neovim.

I'm using vim-plug to install the plugin. I have tried uninstalling and reinstalling. Is the plugin supposed to set those bindings?

Setup:
Tmux 2.8
Nvim 0.5.0
CentOS 7

@ericboehs
Copy link

ericboehs commented Dec 5, 2019

Yes. It looks like vim-tmux-focus-events sets bindings for F24/F25.

I don't know how to help you specifically but I can point you to my dotfiles which work out of the box on a new Mac (hopefully it'll help you with CentOS).

The commit where I added this plugin is f463e37b4. I think that includes everything needed; and most of it is just tweaks for enable/disbling my relative number stuff which you can ignore. (I'm also using vim-diminactive which dims vim on focus lost.)

Tmux 2.9a
Nvim 0.4.3
macOS 10.15.1

@alexpopov
Copy link

@ericboehs Thank you for the speedy response! I'll take a look :)

@justinmk
Copy link

justinmk commented Dec 6, 2019

Focus events work by default in Neovim, so I'm not sure why one would use this plugin there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants