christoomey / vim-tmux-navigator

Seamless navigation between tmux panes and vim splits
MIT License
5.07k stars 319 forks source link

Mappins overriden by terminal #373

Closed u-steen closed 5 months ago

u-steen commented 5 months ago

Update:

Copying the config file from README solves the problem. Even if the tutorials from yt dont do it, it doesn't work otherwise for me.

Original Issue:

Hello. After I installed the plugin I noticed that the default mappings for the plugin (Ctrl + {h, j, k, l}) are overwritten. I came to this conclusion giving the fact that when my cursor is in neovim i can go to another pane which has a new terminal in it but i cant go backwards. Also if i have 2 panes, both with neovim opened I can go between the two with no issues. When i run the mappings of the plugin in terminal i get the terminal commands:

Am I doing something wrong? is there a way of tell the terminal to use the vim-tmux-navigator keymaps instead of its defaults?

I am running Linux Mint with the default terminal, nothing fancy that could mess with the settings.

.tmux.conf

set -g default-terminal "screen-256color"

unbind-key C-b
set -g prefix 'C-a'
bind-key 'C-a' send-prefix

unbind r
bind r source-file ~/.tmux.conf

# vim-like commands for resizing windows
bind -r j resize-pane -D 5
bind -r k resize-pane -U 5
bind -r l resize-pane -R 5
bind -r h resize-pane -L 5

bind -r m resize-pane -Z

set -g mouse on

# opening new panes
unbind %
bind | split-window -h
unbind '"'
bind - split-window -v

# tpm 
set -g @tpm 'tmux-plugins/tpm'
# List of plugins
set -g @tpm 'christoomey/vim-tmux-navigator'

# init tpm - ALWAYS has to be the last line
run -b '~/.tmux/plugins/tpm/tpm'
audishos commented 5 months ago

I'm running into the same issue. The bindings work when neovim is active, but don't when a regular terminal is active. I haven't added any custom configuration. I'm using both the vim and tmux plugin defaults.

audishos commented 5 months ago

@u-steen were you able to resolve this?

u-steen commented 5 months ago

@u-steen were you able to resolve this?

I just added the lines from the README in the config

# Smart pane switching with awareness of Vim splits.
# See: https://github.com/christoomey/vim-tmux-navigator
is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|l?n?vim?x?|fzf)(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 -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

even if the tutorials i watch don't do this step, for me it doesn't work without these lines