junegunn / fzf

:cherry_blossom: A command-line fuzzy finder
https://junegunn.github.io/fzf/
MIT License
63.72k stars 2.37k forks source link

VIM: add option to use vim8 terminal #1860

Open qhadron opened 4 years ago

qhadron commented 4 years ago

Info

Problem / Steps to reproduce

Similar to #1055, I enjoy using vim8's terminal to use terminal mappings for cycling fzf modes. However, if I have the down key in g:fzf_layout dictionary, fzf will always prefer to use height mode.

Is it possible to add a g:fzf_prefer_term that chooses the vim 8 terminal over height mode? Maybe something like this?

--- a/plugin/fzf.vim
+++ b/plugin/fzf.vim
@@ -406,14 +406,19 @@ try
   endif

   let prefer_tmux = get(g:, 'fzf_prefer_tmux', 0)
+  let prefer_term = get(g:, 'fzf_prefer_term', 0)
   let use_height = has_key(dict, 'down') && !has('gui_running') &&
         \ !(has('nvim') || s:is_win || has('win32unix') || s:present(dict, 'up', 'left', 'right', 'window')) &&
         \ executable('tput') && filereadable('/dev/tty')
   let has_vim8_term = has('terminal') && has('patch-8.0.995')
   let has_nvim_term = has('nvim-0.2.1') || has('nvim') && !s:is_win
   let use_term = has_nvim_term ||
-    \ has_vim8_term && !has('win32unix') && (has('gui_running') || s:is_win || !use_height && s:present(dict, 'down', 'up', 'left', 'right', 'window'))
+    \ has_vim8_term && !has('win32unix') && (has('gui_running') || s:is_win || (!use_height || prefer_term) && s:present(dict, 'down', 'up', 'left', 'right', 'window'))
   let use_tmux = (!use_height && !use_term || prefer_tmux) && !has('win32unix') && s:tmux_enabled() && s:splittable(dict)
+  if prefer_term && use_term
+    let use_height = 0
+    let use_tmux = 0
+  endif
   if prefer_tmux && use_tmux
     let use_height = 0
     let use_term = 0
junegunn commented 4 years ago

Instead of adding a new option, I'm thinking of changing the code to always use the built-in terminal when available as I'd like to iron out the differences between Vim and Neovim and make the code simpler.

The reason I chose --height over terminal in that case was two-fold.

  1. The built-in terminal of Vim 8 was not stable back then. This is no longer true.
  2. Can use more space; FZF can use two more lines at the bottom of the screen (statusline and command line of Vim)
    • But the drawback of using --height is that it pushes the contents upwards while fzf is running

Anyway, until I decide what I'm going to do with it, you can force fzf to use terminal buffer by using window layout.

let g:fzf_layout = { 'window': 'bot'.float2nr(&lines * 0.4).'new' }

If you have a bleeding-edge Vim, you can make fzf run inside a pop-up window so that the existing windows are not affected.

let g:fzf_layout = { 'window': { 'width': 1, 'height': 0.4, 'yoffset': 1, 'border': 'horizontal' } }

(See https://github.com/junegunn/fzf.vim/issues/942)