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 setlocal filetype=fzf when opening a terminal buffer #982

Closed
4 tasks done
kdheepak opened this issue Apr 13, 2020 · 5 comments
Closed
4 tasks done

Add setlocal filetype=fzf when opening a terminal buffer #982

kdheepak opened this issue Apr 13, 2020 · 5 comments

Comments

@kdheepak
Copy link

kdheepak commented Apr 13, 2020

Right now if I have the following in my .vimrc:

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

then I'm unable to navigate the fzf candidates.

If you add setlocal filetype=fzf when opening a terminal buffer, then users can do something like this:

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

If there's another way to achieve this, please advice. I'd like to use c-<h,j,k,l> to navigate between terminal buffers and vim buffers (and tmux buffers) but I'd also like to use c-<j,k> to move between candidates in a fzf terminal buffer.

See this issue discussion for more context: christoomey/vim-tmux-navigator#172 (comment)

@junegunn
Copy link
Owner

We already do that:

https://github.com/junegunn/fzf/blob/dea206b023a695b75540f642a0b19a3ba1e38eec/plugin/fzf.vim#L764

However, fzf currently does not open in a terminal buffer iff

  1. You use regular Vim rather than Neovim
  2. And you use the default layout (opens at the bottom of the screen)

If you want to force fzf to open in a terminal buffer, set up window layout as described in the following page.

https://github.com/junegunn/fzf/blob/master/README-VIM.md#configuration

@kdheepak
Copy link
Author

Thanks, that is perfect!

@kdheepak
Copy link
Author

Hi @junegunn, I tested this out and it still does not work as intended. I believe this is because setf fzf is called after the terminal is created, and hence if I add a autocommand to TermOpen the filetype is still empty string at that point. Would it be possible to move setf fzf to before calling termopen?

@junegunn
Copy link
Owner

junegunn commented Apr 14, 2020

I'm not sure, changing it will may break some user scripts. You can just set up autocmd FileType fzf that does the same.

@junegunn junegunn reopened this Apr 14, 2020
@kdheepak
Copy link
Author

Thanks for the quick reply. I don't follow your suggestion exactly. I need to add an autocmd for all terminals except fzf, ranger and other tools. How would I do this would autocmd FileType fzf? Are you suggesting adding a autocommand that does a tnoremap <C-j> <nop>?

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

2 participants