vim-tmux-focus-events


Ⅰ. 插件描述

Make terminal vim and tmux work better together.

Ⅱ. 基本信息

创建日期:  2015-03-20
使用用户:  755
Github星:  256
插件作者:  tmux-plugins

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'tmux-plugins/vim-tmux-focus-events'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'tmux-plugins/vim-tmux-focus-events'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'tmux-plugins/vim-tmux-focus-events'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/tmux-plugins/vim-tmux-focus-events

Ⅳ. 文档说明

# tmux-focus-events.vim

FocusGained and FocusLost autocommand events are not working
in terminal vim. This plugin restores them when using vim inside Tmux.

Here's where that matters:

  • vim-fugitive plugin uses
    FocusGained for refreshing git branch in status line
  • vim-gitgutter uses FocusGained
    for refreshing ... (wait for it) git gutter
  • vim-tmux-clipboard uses
    FocusGained and FocusLost for refreshing clipboard.
  • (get in touch if you know other popular plugins that get improved)

Also, vim-tmux-focus-events makes the
autoread
option work properly for terminal vim. So far, this was only working in a GUI
version.

The autoread feature comes handy when files are changed outside vim, for
example when resolving merge conflicts. When you come back to vim and try saving
a changed file you'll likely be interrupted with
E813:

vim E813

Improved autoread prevents this by automatically reading a file from disk
if it was changed. Works only if autoread option is set (enable it with
set autoread in .vimrc).

Installation & Configuration

Vim plugin installation

  • Vundle<br/>
    Plugin 'tmux-plugins/vim-tmux-focus-events'
  • vim-plug<br/>
    Plug 'tmux-plugins/vim-tmux-focus-events'
  • Pathogen<br/>
    git clone git://github.com/tmux-plugins/vim-tmux-focus-events.git ~/.vim/bundle/vim-tmux-focus-events

Tmux configuration

In order for Tmux to do its magic focus-events option has to be set to on.

Enable that by installing
tmux-sensible plugin, or
by setting this line in tmux.conf:

set -g focus-events on

Testing

Tested and working on:

  • OS X

    • Terminal.app
    • iTerm2
  • Linux

    • GNOME Terminal
    • Terminator
    • XTerm
    • Konsole
    • st

It works both on vim and neovim.

Usage

Once installed, the plugin should "just work".

It will have no effect when running GUI vim or inside plain terminal
(without Tmux).

Other goodies

Credits

Big chunk of code was taken and adapted from
vitality.vim.

Other

In April 2013
a patch was submitted
to vim_dev mailing list that enables this functionality natively in vim.
Once merged, the functionality from the patch will make this plugin obsolete. I
hope that day comes soon.

Licence

MIT

添加新评论