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

Alt or Meta-hjkl work in neovim but not in vim with same config #271

Open
kvngvikram opened this issue Jul 5, 2020 · 4 comments
Open

Alt or Meta-hjkl work in neovim but not in vim with same config #271

kvngvikram opened this issue Jul 5, 2020 · 4 comments

Comments

@kvngvikram
Copy link

kvngvikram commented Jul 5, 2020

I have this in my .tmux.conf file

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'

and in my .vimrc I have

let g:tmux_navigator_no_mappings = 1
nnoremap <M-h> :TmuxNavigateLeft<cr>
nnoremap <M-j> :TmuxNavigateDown<cr>
nnoremap <M-k> :TmuxNavigateUp<cr>
nnoremap <M-l> :TmuxNavigateRight<cr>

This works fine when I am using Neovim but doesn't work with Vim. If I change the alt/meta key with control key then both work. I am trying to have the same configs work with both vim and neovim and want to use alt key since Ctrl-h, j, l do different stuff in bash terminal.
Any suggestions about how to make vim work with alt keys?

@kvngvikram kvngvikram changed the title Alt or Meta-hjkl work with neovim but not with vim with same config Alt or Meta-hjkl work in neovim but not in vim with same config Jul 5, 2020
@christoomey
Copy link
Owner

Hi @kvngvikram, can you clarify what "doesn't work with Vim" means? Are you still able to navigate in tmux, but not vim? Can you move within vim, but not out of vim and back to tmux? Is there any error message in Vim? Does mappy anything else with the meta key in vim, e.g. if you set nnoremap <M-r> :echo "works!"<cr> and then press <M-r> combination, does vim echo "works!"? Similar question for neovim.

@kvngvikram
Copy link
Author

I opened Vim in a terminal and not in tmux and tried nnoremap <M-r> :echo "works!"<cr>. It doesn't work. There are no error messages, no change. Instead of <M-r> if I use <C-r> or <Leader>r it works. So there is a problem with alt mapping in Vim alone and nothing to do with tmux. Whereas Neovim can work with the same <M-r> mapping.

Other than that, tmux works fine without any problem, I can move in to a vim pane. I cannot get out of the Vim pane or move inside the Vim splits when I am using <M- mapping. I don't see any errors.

So I think my issue has noting to do with this plugin.
It would help if anyone can tell me why is <M- mapping not working. Thanks for your reply.

@pkfm
Copy link

pkfm commented Mar 18, 2021

@kvngvikram

Set the maps from an independent vim session (i.e. that isn't nested within a tmux session) and insert the literal control characters using <C-v>. See :h i_CTRL-V if you're unfamiliar. On my setup, this produces <M-h> et. al. from a tmux nested vim session, but ^[h otherwise.

tmux next-3.3
VIM - Vi IMproved 8.2 Huge Included patches: 1-716
NVIM v0.5.0-dev+1105-gfb2adadc9

@kvngvikram
Copy link
Author

@pkfm
Thanks for the suggestion. Now I tried to map using literal character. In terminal outside tmux (byobu) Vim is working with <M-j> and other keys as well. One problem is that the literal character looks like ^[j and the mapping works for <Esc>j as well. Vim looks the both as same similar to <C-j> and <CR>. Anyway when I try switching between splits outside tmux, Alt/Meta keys work as expected and also Esc as well. But when I try in tmux, only Esc mappings work, Meta/Alt mappings do not work.
So no new improvement.

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

3 participants