VforVitamin
VforVitamin

Reputation: 966

Disable cursor(current) line highlight for vim + tmux

I'm using tmux + vim. Unlike vim split window, whenever I move focus to a different pane in tmux, the line highlight does not turn off like the following picture.

Vim in two panes have line highlight The red lines are the cursor lines and I moved the focus to the bottom tmux pane but the top pane vim cursor line still has highlight.

I would like to turn off the cursor line highlight when I leave the pane in tmux and only have highlight line for the current tmux pane. Does anyone know how to do that?

My vim setting for the line highlight is

""""""""""""""""""""""""""""""""""""
" Cursor line highlight
hi CursorLine   cterm=NONE ctermbg=darkred guibg=darkred 
hi CursorColumn cterm=NONE ctermbg=darkred guibg=darkred 
" hlight current line current window only
augroup CursorLine
    au!
    au VimEnter,WinEnter,BufWinEnter * setlocal cursorline
    au WinLeave * setlocal nocursorline
augroup END
""""""""""""""""""""""""""""""""""""

====== EDIT 1 ======

au VimEnter,WinEnter,BufWinEnter,FocusGained,CmdwinEnter * setlocal cursorline
au WinLeave,FocusLost,CmdwinLeave * setlocal nocursorline

Also doesn't work.

====================

Upvotes: 2

Views: 3214

Answers (1)

Marth
Marth

Reputation: 24812

If you're using iTerm2 you can use sjl/vitality.vim plugin which should work(ie restore FocusLost/FocusGained functionality) out of the box (according to the README, I can't try it out).

The akracun/vitality.vim fork provides the functionality for other terminals (xterm/uxterm according to the commit logs, though it works flawlessly on gnome-term for me).

Starting from tmux 1.9a you'll need to :

  • add set -g focus-events on to your .tmux.conf
  • add let g:vitality_tmux_can_focus = 1 to your .vimrc

Then

au VimEnter,WinEnter,BufWinEnter,FocusGained,CmdwinEnter * setlocal cursorline
au WinLeave,FocusLost,CmdwinLeave * setlocal nocursorline

should work as expected

Upvotes: 2

Related Questions