[vim] Use Vim 8 terminal when appropriate

Close #1055
This commit is contained in:
Junegunn Choi 2017-09-29 00:36:09 +09:00
parent ee40212e97
commit 077ae51f05
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627
3 changed files with 24 additions and 16 deletions

View File

@ -37,7 +37,7 @@ Note that the environment variables `FZF_DEFAULT_COMMAND` and
- `g:fzf_action` - `g:fzf_action`
- Customizable extra key bindings for opening selected files in different ways - Customizable extra key bindings for opening selected files in different ways
- `g:fzf_layout` - `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` - `g:fzf_colors`
- Customizes fzf colors to match the current color scheme - Customizes fzf colors to match the current color scheme
- `g:fzf_history_dir` - `g:fzf_history_dir`
@ -72,7 +72,7 @@ let g:fzf_action = {
" - down / up / left / right " - down / up / left / right
let g:fzf_layout = { 'down': '~40%' } 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': 'enew' }
let g:fzf_layout = { 'window': '-tabnew' } let g:fzf_layout = { 'window': '-tabnew' }
let g:fzf_layout = { 'window': '10split enew' } let g:fzf_layout = { 'window': '10split enew' }
@ -116,7 +116,7 @@ following options.
| `options` | string/list | Options to fzf | | `options` | string/list | Options to fzf |
| `dir` | string | Working directory | | `dir` | string | Working directory |
| `up`/`down`/`left`/`right` | number/string | Use tmux pane with the given size (e.g. `20`, `50%`) | | `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` | string | External terminal emulator to start fzf with (GVim only) |
| `launcher` | funcref | Function for generating `launcher` string (GVim only) | | `launcher` | funcref | Function for generating `launcher` string (GVim only) |

View File

@ -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* FZF - TABLE OF CONTENTS *fzf* *fzf-toc*
============================================================================== ==============================================================================
@ -61,7 +61,7 @@ Note that the environment variables `FZF_DEFAULT_COMMAND` and
- Customizable extra key bindings for opening selected files in different - Customizable extra key bindings for opening selected files in different
ways ways
- `g:fzf_layout` - `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` - `g:fzf_colors`
- Customizes fzf colors to match the current color scheme - Customizes fzf colors to match the current color scheme
- `g:fzf_history_dir` - `g:fzf_history_dir`
@ -97,7 +97,7 @@ Examples~
" - down / up / left / right " - down / up / left / right
let g:fzf_layout = { 'down': '~40%' } 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': 'enew' }
let g:fzf_layout = { 'window': '-tabnew' } let g:fzf_layout = { 'window': '-tabnew' }
let g:fzf_layout = { 'window': '10split enew' } let g:fzf_layout = { 'window': '10split enew' }
@ -111,6 +111,7 @@ Examples~
\ 'bg+': ['bg', 'CursorLine', 'CursorColumn'], \ 'bg+': ['bg', 'CursorLine', 'CursorColumn'],
\ 'hl+': ['fg', 'Statement'], \ 'hl+': ['fg', 'Statement'],
\ 'info': ['fg', 'PreProc'], \ 'info': ['fg', 'PreProc'],
\ 'border': ['fg', 'Ignore'],
\ 'prompt': ['fg', 'Conditional'], \ 'prompt': ['fg', 'Conditional'],
\ 'pointer': ['fg', 'Exception'], \ 'pointer': ['fg', 'Exception'],
\ 'marker': ['fg', 'Keyword'], \ 'marker': ['fg', 'Keyword'],
@ -141,7 +142,7 @@ following options.
`options` | string/list | Options to fzf `options` | string/list | Options to fzf
`dir` | string | Working directory `dir` | string | Working directory
`up` / `down` / `left` / `right` | number/string | Use tmux pane with the given size (e.g. `20` , `50%` ) `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` | string | External terminal emulator to start fzf with (GVim only)
`launcher` | funcref | Function for generating `launcher` string (GVim only) `launcher` | funcref | Function for generating `launcher` string (GVim only)
---------------------------+---------------+-------------------------------------------------------------- ---------------------------+---------------+--------------------------------------------------------------
@ -169,8 +170,13 @@ function that decorates the options dictionary so that it understands
GVIM *fzf-gvim* GVIM *fzf-gvim*
============================================================================== ==============================================================================
In GVim, you need an external terminal emulator to start fzf with. `xterm` With the latest version of GVim, fzf will start inside the builtin terminal
command is used by default, but you can customize it with `g:fzf_launcher`. 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 " This is the default. %s is replaced with fzf command
let g:fzf_launcher = 'xterm -e bash -ic %s' let g:fzf_launcher = 'xterm -e bash -ic %s'

View File

@ -386,10 +386,11 @@ try
endif endif
let prefer_tmux = get(g:, 'fzf_prefer_tmux', 0) let prefer_tmux = get(g:, 'fzf_prefer_tmux', 0)
let use_height = has_key(dict, 'down') && let use_height = has_key(dict, 'down') && !has('gui_running') &&
\ !(has('nvim') || s:is_win || has('win32unix') || s:present(dict, 'up', 'left', 'right')) && \ !(has('nvim') || s:is_win || has('win32unix') || s:present(dict, 'up', 'left', 'right', 'window')) &&
\ executable('tput') && filereadable('/dev/tty') \ 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) let use_tmux = (!use_height && !use_term || prefer_tmux) && !has('win32unix') && s:tmux_enabled() && s:splittable(dict)
if prefer_tmux && use_tmux if prefer_tmux && use_tmux
let use_height = 0 let use_height = 0
@ -400,9 +401,6 @@ try
let optstr .= ' --height='.height let optstr .= ' --height='.height
elseif use_term elseif use_term
let optstr .= ' --no-height' let optstr .= ' --no-height'
if !has('nvim') && !s:is_win
let optstr .= ' --bind ctrl-j:accept'
endif
endif endif
let command = prefix.(use_tmux ? s:fzf_tmux(dict) : fzf_exec).' '.optstr.' > '.temps.result let command = prefix.(use_tmux ? s:fzf_tmux(dict) : fzf_exec).' '.optstr.' > '.temps.result
@ -699,7 +697,11 @@ function! s:execute_term(dict, command, temps) abort
if has('nvim') if has('nvim')
call termopen(command, fzf) call termopen(command, fzf)
else 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 endif
finally finally
if s:present(a:dict, 'dir') if s:present(a:dict, 'dir')