Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatic line number toggle does not work inside tmux #45

Closed
jdhao opened this issue Jan 10, 2019 · 9 comments · Fixed by #47
Closed

Automatic line number toggle does not work inside tmux #45

jdhao opened this issue Jan 10, 2019 · 9 comments · Fixed by #47

Comments

@jdhao
Copy link

jdhao commented Jan 10, 2019

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
Copy link
Owner

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 cfaecb9. 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
Copy link
Author

jdhao commented Jan 10, 2019

I have installed this plugin. It does not work.

@jeffkreeftmeijer
Copy link
Owner

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
Copy link
Author

jdhao commented Jan 11, 2019

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
Copy link
Author

jdhao commented Jan 11, 2019

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

@jdhao jdhao closed this as completed Jan 11, 2019
@NilsIrl
Copy link
Contributor

NilsIrl commented Jan 19, 2020

I think this should be mentioned in the README

@MahdiNazemi
Copy link

MahdiNazemi commented Jul 12, 2022

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
Copy link

2knarf commented Apr 10, 2024

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

tmux 3.3a
nvim 0.9.5

@MahdiNazemi
Copy link

MahdiNazemi commented May 5, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants