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

Option / Meta key not working in Tmux #308

Open
matthewmturner opened this issue Oct 29, 2021 · 9 comments
Open

Option / Meta key not working in Tmux #308

matthewmturner opened this issue Oct 29, 2021 · 9 comments

Comments

@matthewmturner
Copy link

I am using neovim and tmux (with tmuxinator) on my M1 Macbook with iTerm2 or Warp (https://www.warp.dev/) as my terminal (i had been using Warp primarily until this issue and saw lots of references to iTerm2 which i tried but still had issues with).

I have mapped my left option key to be my meta key in my terminal. I would like to use <M-h/j/k/l> in order to navigate between neovim splits and tmux panes. Mapping my left option key to meta and using it with h/j/k/l works as expected in neovim (including neovim in tmux - i.e. i can navigate neovim splits and go from neovim to a tmux terminal pane). However, in a tmux terminal pane it either does nothing in iTerm2 or brings up alternate text (˙∆˚¬ for hjkl to be specific) in Warp instead of switching panes or switching into nvim.

Below are my configurations which were from https://github.com/christoomey/vim-tmux-navigator and i just updated them to use meta instead of ctrl:

init.vim

let g:tmux_navigator_no_mappings = 1

nnoremap <silent> <M-h> :TmuxNavigateLeft<cr>
nnoremap <silent> <M-j> :TmuxNavigateDown<cr>
nnoremap <silent> <M-k> :TmuxNavigateUp<cr>
nnoremap <silent> <M-l> :TmuxNavigateRight<cr>
nnoremap <silent> <M-\> :TmuxNavigatePrevious<cr>

.tmux.conf

unbind M-h
unbind M-j
unbind M-k
unbind M-l

is_vim="ps -o state= -o comm= -t '#{pane_tty}' \
    | grep -iqE '^[^TXZ ]+ +(\\S+\\/)?g?(view|n?vim?x?)(diff)?$'"
bind-key -n 'M-h' if-shell "$is_vim" 'send-keys M-h'  'select-pane -L'
bind-key -n 'M-j' if-shell "$is_vim" 'send-keys M-j'  'select-pane -D'
bind-key -n 'M-k' if-shell "$is_vim" 'send-keys M-k'  'select-pane -U'
bind-key -n 'M-l' if-shell "$is_vim" 'send-keys M-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 'M-\\' if-shell \"$is_vim\" 'send-keys M-\\'  'select-pane -l'"
if-shell -b '[ "$(echo "$tmux_version >= 3.0" | bc)" = 1 ]' \
    "bind-key -n 'M-\\' if-shell \"$is_vim\" 'send-keys M-\\\\'  'select-pane -l'"

bind-key -T copy-mode-vi 'M-h' select-pane -L
bind-key -T copy-mode-vi 'M-j' select-pane -D
bind-key -T copy-mode-vi 'M-k' select-pane -U
bind-key -T copy-mode-vi 'M-l' select-pane -R
bind-key -T copy-mode-vi 'M-\' select-pane -l

Do I have the right configurations? If so, any insight on how I can get this working?

@christoomey
Copy link
Owner

Apologies but I don't have much familiarity around using option / meta for these (the few times I've dabbled in those keys for bindings in the past have been rough). I would expect this to work, and I don't see anything obviously wrong with your config, but also know this is a tricky space. Best of luck, and please do share if you sort anything out here (or if you happen to find that the plugin is in fact doing something wrong).

@matthewmturner
Copy link
Author

@christoomey thank you for the quick response :) its at least good info to know that the config is ok. will let you know if i make any progress.

@matthewmturner
Copy link
Author

@christoomey actually one more point. I only ended up using Meta because ctrl didnt work with ctrl-h. When I do that I get a message that says "No more marks available". The other three commands (j/k/l) work. Any idea on that?

@christoomey
Copy link
Owner

Sounds like you've got a conflicting mapping in Vim (the mention of "marks" makes me think it's Vim). You can check with verbose nmap <C-h> which likely will find whatever else might be trying to run for C-h

@leandrochiarini
Copy link

leandrochiarini commented Nov 23, 2021

I have the same problem in Manjaro xfce, however, it seems like it is something bigger than the plugin, even if I try to remap
nnoremap <silent> <M-h> :echo "Hello Word"<CR>
it seems like vim does not trigger it. Even after removing everything from my .vimrc. Is it the same for you @matthewmturner?
By the way, this does not seem to be an issue in the insert mode, for instance.

@leandrochiarini
Copy link

In my case the general solution presented in StackExchange worked.

However, your problem seem to be well known for on OS X, does this answer solve your problem?

@Nugumanov
Copy link

Nugumanov commented Jun 28, 2022

I have the same issue using iTerm2 v3.4.15 using tmux (both v2.8 and v3) on MacOS Catalina 10.15
In iTerm settings I tried to switch between Left Option key as Normal and Meta, no effect
sed -n l shows nothing when pressing Option+key

@ksajan
Copy link

ksajan commented Jan 31, 2023

I have the same issue as @Nugumanov. Any other alternative @leandrochiarini ?

@ksajan
Copy link

ksajan commented Jan 31, 2023

I resolved this by changing the left Option key to Esc+ in preferences. @Nugumanov probably you can also try this if you still haven't found the solution.

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

No branches or pull requests

5 participants