alexghergh / nvim-tmux-navigation

Easy Neovim-Tmux navigation, completely written in Lua
MIT License
273 stars 21 forks source link

Prioritize Neovim pane over tmux pane #14

Closed Nicola-Bini closed 12 months ago

Nicola-Bini commented 1 year ago

Hi!

I have 2 neovim splits on the right and 1 tmux pane on the left, and my cursor is on the far left. When I now use "C-l" (shortcut for nvim_tmux_nav.NvimTmuxNavigateRight), I would expect the cursor move to the second neovim split from the left, in the same tmux split. Instead it jumps to the right pane. What am I missing?

Screenshot 2023-06-12 at 10 42 52 AM

My config `local nvim_tmux_nav = require('nvim-tmux-navigation') local keymap = vim.keymap.set local opts = { noremap = true, silent = true}

nvim_tmux_nav.setup{}

keymap('n', "", nvim_tmux_nav.NvimTmuxNavigateLeft) keymap('n', "", nvim_tmux_nav.NvimTmuxNavigateDown) keymap('n', "", nvim_tmux_nav.NvimTmuxNavigateUp) keymap('n', "", nvim_tmux_nav.NvimTmuxNavigateRight) keymap('n', "<C-\>", nvim_tmux_nav.NvimTmuxNavigateLastActive) keymap('n', "", nvim_tmux_nav.NvimTmuxNavigateNext) `

-- tmux use {'alexghergh/nvim-tmux-navigation', disable_when_zoomed = true -- defaults to false }

tmux.conf

set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'tmux-plugins/tmux-resurrect'
# for neovim
set -g @resurrect-strategy-nvim 'session'
set -g @plugin 'catppuccin/tmux'

# Shift Alt vim keys to switch windows
bind -n M-H previous-window
bind -n M-L next-window

is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"

bind-key -n 'C-h' if-shell "$is_vim" 'send-keys C-h' 'select-pane -L'
bind-key -n 'C-j' if-shell "$is_vim" 'send-keys C-j' 'select-pane -D'
bind-key -n 'C-k' if-shell "$is_vim" 'send-keys C-k' 'select-pane -U'
bind-key -n 'C-l' if-shell "$is_vim" 'send-keys C-l' 'select-pane -R'

tmux_version='$(tmux -V | sed -En "s/^tmux ([0-9]+(.[0-9]+)?).*/\1/p")'

if-shell -b '[ "$(echo "$tmux_version < 3.0" | bc)" = 1 ]' \
    "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\'  'select-pane -l'"
if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
    "bind-key -n 'C-\\' if-shell \"$is_vim\" 'send-keys C-\\\\'  'select-pane -l'"

bind-key -n 'C-Space' if-shell "$is_vim" 'send-keys C-Space' 'select-pane -t:.+'

bind-key -T copy-mode-vi 'C-h' select-pane -L
bind-key -T copy-mode-vi 'C-j' select-pane -D
bind-key -T copy-mode-vi 'C-k' select-pane -U
bind-key -T copy-mode-vi 'C-l' select-pane -R
bind-key -T copy-mode-vi 'C-\' select-pane -l
bind-key -T copy-mode-vi 'C-Space' select-pane -t:.+
# enforce 256, if problematic disable
# set -g default-terminal "screen-256color"

# Enable mouse
set -g mouse on 

# Start numbering from 0
set -g base-index 1
set -g pane-base-index 1
set-window-option -g pane-base-index 1 
set-option -g renumber-windows on 

# Change prefix key to CTRL + SPACE
unbind C-b
set -g prefix C-Space 
bind C-Space send-prefix

# 24bit color - if terminal allows
set-option -sa terminal-overrides ",xterm:Tc"

# increase limit
set-option -g history-limit 10000

# renumber windows after closing intermediary ones
set-option -g renumber-windows on

# visual notification of activity in other windows
set-window-option -g monitor-activity on
set-option -g visual-activity on

# set color for status bar
set-option -g status-bg colour234
set-option -g status-fg yellow
set-option -g status-attr dim

# Current window bright red, inactive dim blue
set-window-option -g window-status-current-fg brightred
set-window-option -g window-status-current-bg colour234
set-window-option -g window-status-current-attr bright

set-window-option -g window-status-fg brightblue
set-window-option -g window-status-bg colour234
set-window-option -g window-status-attr dim

# show host name and IP address on left side of status bar
set-option -g status-left-length 70
set-option -g status-left "#[fg=brightgreen]:: #h #[fg=brightcyan]:: #(curl icanhazip.com) #[fg=brightyellow]#(ifconfig en0 | grep 'inet ' | awk '{print \"en0 \" $2}') #(ifconfig en1 | grep 'inet ' | awk '{print \"en1 \" $2}') #[fg=red]#(ifconfig tun0 | grep 'inet ' | awk '{print \"vpn \" $2}') "

# show session name, window & pane number, date and time on right side of
# status bar
set-option -g status-right-length 60
set-option -g status-right "#[fg=white]#S #I #P ::#[fg=yellow] %d %b %Y ::#[fg=green] %H:%M:%S ::"

run '~/.tmux/plugins/tpm/tpm'

PS: Great Plugin, thank you for that!

alexghergh commented 1 year ago

Hello!

Could you please review the text of the issue you submitted? It seems you mixed left and right. If what you meant is "the left tmux pane contains 2 neovim splits, and there's an additional tmux pane on the right", then I cannot seem to figure out what the problem is. To re-iterate (from what I see in the picture and take as correct), your cursor is on the far left neovim split, and you try to move through <C-l> to the right, correct? This should indeed place you on the neovim split on the right, in the same tmux pane. If that is not the case, we could investigate what the problem is, however you might need to run a few things for me, as I cannot re-produce the problem.

Nicola-Bini commented 1 year ago

Hi @alexghergh,

Thank you for responding. You are correct, I update my first comment to make it clearer. The problem is that instead of moving to the second neovim split (in the same tmux pane), like you described, it moves my cursor to the right tmux pane. Effectively removing the possibility to move to the the second neovim split, without using my mouse.

Happy to run whatever test is necessary

alexghergh commented 1 year ago

Alright, let's see. First of all, can you replicate this with all directions of movement, i.e. the same thing happens when you have 2 tmux panes, and the right tmux pane contains 2 neovim splits, and you try to move with the cursor from the rightmost neovim split to the one to the left? Up/down movement too?

It looks like neovim somehow might not register your key presses, and they go directly to tmux. Could you change the keybinds from neovim to something else? For example, keep tmux keybinds Ctrl based, and temporarily assign neovim keybinds to Alt or Shift or something else (any key will do). Then, try the same experiment as above, inside neovim, except with the new keybinds.

Nicola-Bini commented 1 year ago

Hi @alexghergh, Thank you for the suggestion. I changed the keybindings to <C-a> and <C-o>. They work as expected. Here is my nvim config . I know it is still very dirty (I am still experimenting and trying to understand how to set up language servers)

alexghergh commented 1 year ago

Hey,

I just noticed that your <C-h> and <C-l> bindings are reversed (i.e. h should move to the left, and l to the right, if to follow the Vim convention).

If that's the case, then the behaviour described in your initial comment is consistent with how it should work.

Was that the problem, or were they reversed on purpose?

Nicola-Bini commented 1 year ago

Thank you for spotting that! I recently moved to a dvorak layout and I made confusion. I will test it soon, and let you know if that was the only problem

Nicola-Bini commented 12 months ago

Hi @alexghergh, It worked! that was the problem, and I was also missing part of your config in the tmux.conf file. Thank you for the help, and for the plugin!