sjl / vitality.vim

Make Vim play nicely with iTerm 2 and tmux.
http://github.com/sjl/vitality.vim
MIT License
320 stars 30 forks source link

^[[O and ^[[I being sent to active tmux window, even if not the one with vim running #2

Open mydimension opened 12 years ago

mydimension commented 12 years ago

Say I have 2 tmux windows (0:0 and 0:1) and vim is running in one of them (0:0). I have focused the window that does not have vim running (0:1). If i leave iterm2 the escape sequence ^[[O is sent to window 0:1 and causes a newline to appear after the prompt and rings a bell in iterm2. returning focus to iterm2 also sends the escape sequence ^[[I but no visual disturbance occurs.

sjl commented 12 years ago

You're right. I noticed this myself.

The problem is that we're telling iTerm2 to report focus when we start Vim, but we really only want it to report focus when that window is the active one.

I'm not sure what the best way to fix this is.

We really need a way for Vim to get notified when its tmux pane is activated or deactivated.

Anyone have any ideas?

aaronjensen commented 12 years ago

This isn't the solution as there are still problems with it, but you can always ignore those with your inputrc:

'\e[O': ''
'\e[I': ''

The real solution would require tmux to notify the pane when it gained or lost focus: https://sourceforge.net/tracker/index.php?func=detail&aid=3558288&group_id=200378&atid=973265

sjl commented 12 years ago

@aaronjensen is correct. If you use Fish like me, you'll need to use bind to bind those sequences to a noop instead:

bind \e\[O true
bind \e\[I true

I'll leave this open in case tmux ever implements the notifications.

sjl commented 12 years ago

Note that this only fixes things in the shell. Once control passes to another program you'll still get the stray characters. The real solution is, as @aaronjensen mentioned, for tmux to allow notification to panes.

rstacruz commented 11 years ago

One workaround is to use:

let g:vitality_fix_focus=0

You'll lose the FocusLost/FocusGained functionality, however.

akracun commented 11 years ago

I have a version of tmux that handles this issue. https://github.com/akracun/tmux

You'll need to bundle it with my version of vitality.

aaronjensen commented 11 years ago

@akracun awesome. Any chance of this making it into tmux mainline?

aaronjensen commented 11 years ago

@akracun I'm not seeing focus-filter in tmux show-options -g, should i? Is there some other way to find it? I'd like to be able to check for it.

aaronjensen commented 11 years ago

I'm using this for now:

[ -n "$TMUX" ] && tmux set-option -g focus-filter on > /dev/null 2>&1 && export TMUX_CAN_FOCUS=1
akracun commented 11 years ago

@aaronjensen focus-filter is a window option, use tmux show-options -wg focus-filter to inspect its value.

I'll add this option check in to my vitality.vim repository.

As for adding this feature to tmux mainline, I'll look into it.

bruno- commented 9 years ago

Good news everyone, it seems the tmux issue/request referenced in this post is now implemented in tmux!