jeffkreeftmeijer / vim-numbertoggle

Toggles between hybrid and absolute line numbers automatically
https://jeffkreeftmeijer.com/vim-number/#automatic-toggling-between-line-number-modes
MIT License
682 stars 49 forks source link

Automatic line number toggle does not work inside tmux #45

Closed jdhao closed 5 years ago

jdhao commented 5 years ago

I read your post here and the automatic number toggle works great. The settings I use:

augroup numbertoggle
  autocmd!
  autocmd BufEnter,FocusGained,InsertLeave * set relativenumber
  autocmd BufLeave,FocusLost,InsertEnter   * set norelativenumber
augroup END

But it seems that this setting does not work inside tmux. If I open two tmux panes side by side and open a file with Neovim in one pane and then switch to another tmux pane, the relative line number in Neovim does not change to absolute number. How to fix this issue?

Besides, I use set -g mouse on inside ~/.tmux.conf so that I can use mouse to change tmux panes, if that information is relevant.

jeffkreeftmeijer commented 5 years ago

That article includes a simplified version of the number toggling. This plugin is a little smarter, and it includes support for things like this since https://github.com/jeffkreeftmeijer/vim-numbertoggle/commit/cfaecb9e22b45373bb4940010ce63a89073f6d8b. Could you try installing the plugin, to see if that solves your issue? I'll make sure to add a note about this to the article.

jdhao commented 5 years ago

I have installed this plugin. It does not work.

jeffkreeftmeijer commented 5 years ago

I’m afraid I can’t reproduce this myself. I have set -g mouse on in my .tmux.conf, and toggling seems to work both when switching with the keyboard, and clicking the other pane with the mouse.

Could you make sure you have the most recent version of vim-numbertoggle installed, and have removed the code snippet from the article from your Vim configuration files?

jdhao commented 5 years ago

Yes, I am using the latest version of vim-numbertoggle and have removed the the simpler code snippet. You can in the following image, line number does not change when I switch to another tmux pane. video_2019-01-11_143945

jdhao commented 5 years ago

I have filed an issue on Neovim repo and got the right answer.

We need to turn on the focus-events for tmux. Edit the tmux config file ~/.tmux.conf and add the following setting:

set -g focus-events on
NilsIrl commented 4 years ago

I think this should be mentioned in the README

MahdiNazemi commented 2 years ago

Does adding set-option -g focus-events on still work? I have a Mac and a Linux machine, but I couldn't get the plugin to work correctly on either machine.

Running tmux 3.3a and Vim 9.0 on one machine and tmux 3.0a and Vim 8.1 on the other.

2knarf commented 6 months ago

Looks like this issue is back, the mentioned fix does not work.

tmux 3.3a nvim 0.9.5

MahdiNazemi commented 5 months ago

What worked for me was to install the 'tmux-plugins/vim-tmux-focus-events'Vim plugin.

Although the plugin's README mentions that newer versions of Vim have native support for reporting focus events and, therefore, one should not need to install the plugin, installing it helped resolve the issue on all my machines.