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

Add Nvim terminal emulator key mappings #172

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Add Nvim terminal emulator key mappings #172

wants to merge 1 commit into from

Conversation

ghost
Copy link

@ghost ghost commented Apr 10, 2017

No description provided.

@christoomey
Copy link
Owner

This looks fine to me, but I'm not an Nvim user. @blueyed @geoffharcourt are either of you Nvim users / willing to test this out and verify that all is well?

@blueyed
Copy link
Collaborator

blueyed commented Apr 10, 2017

It was added and reverted already: #129.

@geoffharcourt
Copy link
Collaborator

Selfishly I'd rather have FZF work than terminal mode in nvim work.

@blueyed
Copy link
Collaborator

blueyed commented Apr 10, 2017

Of course.
It might be possible to detect it though?!

@christoomey
Copy link
Owner

If there is a fundamental incompatibility here between fzf.vim and nvim terminal mode mappings, we'll need to stick with not including these mappings. That said, we can always add a section to the readme with notes on this. It's getting big enough that it might be time to pull all non-install non-usage content out into a separate document.

@geoffharcourt
Copy link
Collaborator

I think it might be hard to detect FZF, since people may use FZF without the author's Vim plugin.

@blueyed
Copy link
Collaborator

blueyed commented Apr 12, 2017

It should be detectable as the program running in the term window.. and "fzf" shows up both when using :FZF, or fzf itself in a :term window for me.

@blueyed
Copy link
Collaborator

blueyed commented Apr 19, 2017

fzf gets detected in the custom key bindings mentioned in https://blog.bugsnag.com/tmux-and-vim/.

@ssh352
Copy link

ssh352 commented Jun 11, 2019

so I press esc to get from terminal mode to normal mode, then use ctrl-j,k,l to move around, is that what you do as the workaround?

@Nelyah
Copy link

Nelyah commented Nov 20, 2019

@ssh352 I might come late to the party, but these mapping work for me in neovim 0.4.2:

tnoremap <silent> <m-h> <C-\><C-n>:TmuxNavigateLeft<cr>
tnoremap <silent> <m-j> <C-\><C-n>:TmuxNavigateDown<cr>
tnoremap <silent> <m-k> <C-\><C-n>:TmuxNavigateUp<cr>
tnoremap <silent> <m-l> <C-\><C-n>:TmuxNavigateRight<cr>

@kdheepak
Copy link

kdheepak commented Apr 10, 2020

It would be useful to have this feature. For fzf and other tools in a neovim terminal buffer, the convention seems to be to set filetype accordingly. Is it not possible to add the tnoremap per <buffer> depending on some predicate? If it is possible we can use a autocmd when opening term://* and make sure that filetype= before adding the above tnoremaps.

@kdheepak
Copy link

kdheepak commented Apr 10, 2020

It turns out fzf does not set a filetype. neoranger.vim and lazygit.vim set filetype to the name of the application that is being run.

If not for the above caveat, the following would work.

function s:AddTerminalNavigation()

    if &filetype ==# ''
        tnoremap <buffer> <silent> <c-h> <c-\><c-n>:TmuxNavigateLeft<cr>
        tnoremap <buffer> <silent> <c-j> <c-\><c-n>:TmuxNavigateDown<cr>
        tnoremap <buffer> <silent> <c-k> <c-\><c-n>:TmuxNavigateUp<cr>
        tnoremap <buffer> <silent> <c-l> <c-\><c-n>:TmuxNavigateRight<cr>
    endif

endfunction

augroup TerminalNavigation
    autocmd!
    autocmd TermOpen * call s:AddTerminalNavigation()
augroup END

Anyone see any problem with doing it this way?

@patrickdepinguin
Copy link
Contributor

I bumped into this issue because I could not use my regular mappings to navigate from a :terminal to a vim pane, while navigation from a vim pane is set up to use :TmuxNavigateX. Note that I'm not actually inside tmux here. Neither do I use fzf.

In my .vimrc I had custom key bindings as described in https://github.com/christoomey/vim-tmux-navigator/#custom-key-bindings , and it took me a while to realize that my problem was caused because these instructions use 'nnoremap' and as such only work in normal mode. If I duplicate them as 'tnoremap' and add '' before each binding replacement, then I can navigate from a :terminal to another vim pane as I want.

So in total I now have:

"Cycle between tmux/vim seamlessly
let g:tmux_navigator_no_mappings = 1
nnoremap <silent> <A-Left>  :TmuxNavigateLeft<cr>
nnoremap <silent> <A-Down>  :TmuxNavigateDown<cr>
nnoremap <silent> <A-Up>    :TmuxNavigateUp<cr>
nnoremap <silent> <A-Right> :TmuxNavigateRight<cr>
nnoremap <silent> <A-z>     :TmuxNavigatePrevious<cr>
nnoremap <silent> <A-h>     :TmuxNavigateLeft<cr>
nnoremap <silent> <A-j>     :TmuxNavigateDown<cr>
nnoremap <silent> <A-k>     :TmuxNavigateUp<cr>
nnoremap <silent> <A-l>     :TmuxNavigateRight<cr>
"additional mappings to support urxvt
nnoremap <silent> <Esc><Left>  :TmuxNavigateLeft<cr>
nnoremap <silent> <Esc><Down>  :TmuxNavigateDown<cr>
nnoremap <silent> <Esc><Up>    :TmuxNavigateUp<cr>
nnoremap <silent> <Esc><Right> :TmuxNavigateRight<cr>
nnoremap <silent> <Esc>z       :TmuxNavigatePrevious<cr>
nnoremap <silent> <Esc>h       :TmuxNavigateLeft<cr>
nnoremap <silent> <Esc>j       :TmuxNavigateDown<cr>
nnoremap <silent> <Esc>k       :TmuxNavigateUp<cr>
nnoremap <silent> <Esc>l       :TmuxNavigateRight<cr>

"terminal mode
tnoremap <silent> <A-Left>  <C-W>:TmuxNavigateLeft<cr>
tnoremap <silent> <A-Down>  <C-W>:TmuxNavigateDown<cr>
tnoremap <silent> <A-Up>    <C-W>:TmuxNavigateUp<cr>
tnoremap <silent> <A-Right> <C-W>:TmuxNavigateRight<cr>
tnoremap <silent> <A-z>     <C-W>:TmuxNavigatePrevious<cr>
tnoremap <silent> <A-h>     <C-W>:TmuxNavigateLeft<cr>
tnoremap <silent> <A-j>     <C-W>:TmuxNavigateDown<cr>
tnoremap <silent> <A-k>     <C-W>:TmuxNavigateUp<cr>
tnoremap <silent> <A-l>     <C-W>:TmuxNavigateRight<cr>
"additional mappings to support urxvt
tnoremap <silent> <Esc><Left>  <C-W>:TmuxNavigateLeft<cr>
tnoremap <silent> <Esc><Down>  <C-W>:TmuxNavigateDown<cr>
tnoremap <silent> <Esc><Up>    <C-W>:TmuxNavigateUp<cr>
tnoremap <silent> <Esc><Right> <C-W>:TmuxNavigateRight<cr>
tnoremap <silent> <Esc>z       <C-W>:TmuxNavigatePrevious<cr>
tnoremap <silent> <Esc>h       <C-W>:TmuxNavigateLeft<cr>
tnoremap <silent> <Esc>j       <C-W>:TmuxNavigateDown<cr>
tnoremap <silent> <Esc>k       <C-W>:TmuxNavigateUp<cr>
tnoremap <silent> <Esc>l       <C-W>:TmuxNavigateRight<cr>

This may be obvious to some, but since it took me a while I guess there are other people that may find this helpful :-)

frasercrmck added a commit to frasercrmck/dotfiles that referenced this pull request May 15, 2024
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 this pull request may close these issues.

7 participants