Skip to content

Commit

Permalink
[vim] Use Vim 8 terminal when appropriate
Browse files Browse the repository at this point in the history
Close #1055
  • Loading branch information
junegunn committed Sep 28, 2017
1 parent ee40212 commit 077ae51
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 16 deletions.
6 changes: 3 additions & 3 deletions README-VIM.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ Note that the environment variables `FZF_DEFAULT_COMMAND` and
- `g:fzf_action`
- Customizable extra key bindings for opening selected files in different ways
- `g:fzf_layout`
- Determines the size and position of fzf window (tmux pane or Neovim split)
- Determines the size and position of fzf window
- `g:fzf_colors`
- Customizes fzf colors to match the current color scheme
- `g:fzf_history_dir`
Expand Down Expand Up @@ -72,7 +72,7 @@ let g:fzf_action = {
" - down / up / left / right
let g:fzf_layout = { 'down': '~40%' }
" In Neovim, you can set up fzf window using a Vim command
" You can set up fzf window using a Vim command (Neovim or latest Vim 8 required)
let g:fzf_layout = { 'window': 'enew' }
let g:fzf_layout = { 'window': '-tabnew' }
let g:fzf_layout = { 'window': '10split enew' }
Expand Down Expand Up @@ -116,7 +116,7 @@ following options.
| `options` | string/list | Options to fzf |
| `dir` | string | Working directory |
| `up`/`down`/`left`/`right` | number/string | Use tmux pane with the given size (e.g. `20`, `50%`) |
| `window` (*Neovim only*) | string | Command to open fzf window (e.g. `vertical aboveleft 30new`) |
| `window` (Vim 8 / Neovim) | string | Command to open fzf window (e.g. `vertical aboveleft 30new`) |
| `launcher` | string | External terminal emulator to start fzf with (GVim only) |
| `launcher` | funcref | Function for generating `launcher` string (GVim only) |

Expand Down
18 changes: 12 additions & 6 deletions doc/fzf.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
fzf.txt fzf Last change: August 14 2017
fzf.txt fzf Last change: September 29 2017
FZF - TABLE OF CONTENTS *fzf* *fzf-toc*
==============================================================================

Expand Down Expand Up @@ -61,7 +61,7 @@ Note that the environment variables `FZF_DEFAULT_COMMAND` and
- Customizable extra key bindings for opening selected files in different
ways
- `g:fzf_layout`
- Determines the size and position of fzf window (tmux pane or Neovim split)
- Determines the size and position of fzf window
- `g:fzf_colors`
- Customizes fzf colors to match the current color scheme
- `g:fzf_history_dir`
Expand Down Expand Up @@ -97,7 +97,7 @@ Examples~
" - down / up / left / right
let g:fzf_layout = { 'down': '~40%' }
" In Neovim, you can set up fzf window using a Vim command
" You can set up fzf window using a Vim command (Neovim or latest Vim 8 required)
let g:fzf_layout = { 'window': 'enew' }
let g:fzf_layout = { 'window': '-tabnew' }
let g:fzf_layout = { 'window': '10split enew' }
Expand All @@ -111,6 +111,7 @@ Examples~
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'],
Expand Down Expand Up @@ -141,7 +142,7 @@ following options.
`options` | string/list | Options to fzf
`dir` | string | Working directory
`up` / `down` / `left` / `right` | number/string | Use tmux pane with the given size (e.g. `20` , `50%` )
`window` (Neovim only) | string | Command to open fzf window (e.g. `verticalaboveleft30new` )
`window` (Vim 8 / Neovim) | string | Command to open fzf window (e.g. `verticalaboveleft30new` )
`launcher` | string | External terminal emulator to start fzf with (GVim only)
`launcher` | funcref | Function for generating `launcher` string (GVim only)
---------------------------+---------------+--------------------------------------------------------------
Expand Down Expand Up @@ -169,8 +170,13 @@ function that decorates the options dictionary so that it understands
GVIM *fzf-gvim*
==============================================================================

In GVim, you need an external terminal emulator to start fzf with. `xterm`
command is used by default, but you can customize it with `g:fzf_launcher`.
With the latest version of GVim, fzf will start inside the builtin terminal
emulator of Vim. Please note that this terminal feature of Vim is still young
and unstable and you may run into some issues.

If you have an older version of GVim, you need an external terminal emulator
to start fzf with. `xterm` command is used by default, but you can customize
it with `g:fzf_launcher`.
>
" This is the default. %s is replaced with fzf command
let g:fzf_launcher = 'xterm -e bash -ic %s'
Expand Down
16 changes: 9 additions & 7 deletions plugin/fzf.vim
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,11 @@ try
endif

let prefer_tmux = get(g:, 'fzf_prefer_tmux', 0)
let use_height = has_key(dict, 'down') &&
\ !(has('nvim') || s:is_win || has('win32unix') || s:present(dict, 'up', 'left', 'right')) &&
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 use_term = has('nvim-0.2.1') || (has('nvim') && !s:is_win) || (has('terminal') && has('patch-8.0.995') && (has('gui_running') || s:is_win))
let has_term = has('nvim-0.2.1') || has('nvim') && !s:is_win || has('terminal') && has('patch-8.0.995')
let use_term = has_term && (has('gui_running') || s:is_win || !use_height && 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_tmux && use_tmux
let use_height = 0
Expand All @@ -400,9 +401,6 @@ try
let optstr .= ' --height='.height
elseif use_term
let optstr .= ' --no-height'
if !has('nvim') && !s:is_win
let optstr .= ' --bind ctrl-j:accept'
endif
endif
let command = prefix.(use_tmux ? s:fzf_tmux(dict) : fzf_exec).' '.optstr.' > '.temps.result

Expand Down Expand Up @@ -699,7 +697,11 @@ function! s:execute_term(dict, command, temps) abort
if has('nvim')
call termopen(command, fzf)
else
call term_start([&shell, &shellcmdflag, command], {'curwin': fzf.buf, 'exit_cb': function(fzf.on_exit)})
let t = term_start([&shell, &shellcmdflag, command], {'curwin': fzf.buf, 'exit_cb': function(fzf.on_exit)})
" FIXME: https://github.com/vim/vim/issues/1998
if !has('nvim') && !s:is_win
call term_wait(t, 20)
endif
endif
finally
if s:present(a:dict, 'dir')
Expand Down

0 comments on commit 077ae51

Please sign in to comment.