GithubHelp home page GithubHelp logo

vim-term-focus's Introduction

vim-term-focus

Report focus events in Vim for supported terminal emulators.

Focus change events are reported in gvim but not in terminal vim by default. This plugin used the Focus Reporting feature available in some terminal emulators to capture focus change events that can be used by vim autocmd.

For example you could create an autocmd to save all files when focus changes:

autocmd FocusLost * :wa

or perhaps redraw the screen on focus gained:

autocmd FocusGained * :redraw!

Installation and Usage

Use you favourite plugin manager to install e.g.:

Plug 'pnetherwood/vim-term-focus'

Supported Terminals

Focus Reporting events are (sadly) not reported on all terminals. To test if Focus Reporting is available on your favourite terminal emulator run this command in your shell:

echo -e "Focus Reporting \033[?1004hcheck ..." && read -N 3 -s -t 10; if [ "${REPLY:1:2}" == "[O" ] || [ "${REPLY:1:2}" == "[I" ]; then echo "Focus reporting supported"; else echo "No focus reporting"; fi; echo -ne '\e[?1004l' 

You may need to switch focus for the terminal to report the change. You'll either get a message the "Focus reporting supported" or after 10 seconds of waiting that there is "No focus reporting".

vim-term-focus has been tested and is working on the following terminal emulators:

  • Windows (i.e. Cygwin/MSYS2 and WSL):
    • Mintty
    • WSLtty
  • Linux:
    • Gnome
    • xterm
  • OS X:
    • iterm2

It does not work in the following terminals:

  • Windows:
    • Cmd
    • Cmder 1.3.14
    • ConEmu 19.10.12.0
    • Windows Terminal 0.10.781.0
    • MobaXTerm 20.1.0
    • Terminus 1.0.105
    • Alacritty 0.4.1
    • Fluent Terminal 0.6.1.0

Let me know of you find any others that it works in.

Tmux

It also works in Tmux. For tmux to work focus events need to be turned on using

set -g focus-events on

in your .tmux.conf. Don't forget to restart the session for it to take effect.

Other Plugins

There are a few other plugins that do a similar job such as Vitality, vim-tmux-focus-events and Terminus. However they tend to do other things or be based on a single terminal. This plugin aims to do just one job which is just handling terminal events. The other plugins may work better for you. The code was shamelessly ripped off from Steve Losh's Vitality plugin so thanks Steve.

License

MIT/X11

vim-term-focus's People

Contributors

pnetherwood avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.