mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-12-23 11:29:01 +00:00
[vim] External terminal emulator for GVim
This commit is contained in:
parent
f58a53a001
commit
4a3a5ee70d
22
README.md
22
README.md
@ -287,7 +287,7 @@ TODO :smiley:
|
|||||||
Usage as Vim plugin
|
Usage as Vim plugin
|
||||||
-------------------
|
-------------------
|
||||||
|
|
||||||
(Note: To use fzf in GVim, bash and xterm are required.)
|
(Note: To use fzf in GVim, an external terminal emulator is required.)
|
||||||
|
|
||||||
### `:FZF[!]`
|
### `:FZF[!]`
|
||||||
|
|
||||||
@ -311,11 +311,15 @@ If you're on a tmux session, `:FZF` will launch fzf in a new split-window whose
|
|||||||
height can be adjusted with `g:fzf_tmux_height` (default: '40%'). However, the
|
height can be adjusted with `g:fzf_tmux_height` (default: '40%'). However, the
|
||||||
bang version (`:FZF!`) will always start in fullscreen.
|
bang version (`:FZF!`) will always start in fullscreen.
|
||||||
|
|
||||||
In GVim, `xterm` command will be used to launch fzf. You can set options to
|
In GVim, you need an external terminal emulator to start fzf with. `xterm`
|
||||||
`xterm` command with `g:fzf_xterm_options`. For example,
|
command is used by default, but you can customize it with `g:fzf_launcher`.
|
||||||
|
|
||||||
```vim
|
```vim
|
||||||
let g:fzf_xterm_options = '-geometry 120x30'
|
" This is the default. %s is replaced with fzf command
|
||||||
|
let g:fzf_launcher = 'xterm -e bash -ic %s'
|
||||||
|
|
||||||
|
" Use urxvt instead
|
||||||
|
let g:fzf_launcher = 'urxvt -geometry 120x30 -e sh -c %s'
|
||||||
```
|
```
|
||||||
|
|
||||||
### `fzf#run([options])`
|
### `fzf#run([options])`
|
||||||
@ -335,7 +339,7 @@ of the selected items.
|
|||||||
| `dir` | string | Working directory |
|
| `dir` | string | Working directory |
|
||||||
| `tmux_width` | number/string | Use tmux vertical split with the given height (e.g. `20`, `50%`) |
|
| `tmux_width` | number/string | Use tmux vertical split with the given height (e.g. `20`, `50%`) |
|
||||||
| `tmux_height` | number/string | Use tmux horizontal split with the given height (e.g. `20`, `50%`) |
|
| `tmux_height` | number/string | Use tmux horizontal split with the given height (e.g. `20`, `50%`) |
|
||||||
| `xterm_options` | string | Options to `xterm` command (Only used in GVim) |
|
| `launcher` | string | External terminal emulator to start fzf with (Only used in GVim) |
|
||||||
|
|
||||||
#### Examples
|
#### Examples
|
||||||
|
|
||||||
@ -361,10 +365,10 @@ nnoremap <silent> <Leader>C :call fzf#run({
|
|||||||
\ 'source':
|
\ 'source':
|
||||||
\ map(split(globpath(&rtp, "colors/*.vim"), "\n"),
|
\ map(split(globpath(&rtp, "colors/*.vim"), "\n"),
|
||||||
\ "substitute(fnamemodify(v:val, ':t'), '\\..\\{-}$', '', '')"),
|
\ "substitute(fnamemodify(v:val, ':t'), '\\..\\{-}$', '', '')"),
|
||||||
\ 'sink': 'colo',
|
\ 'sink': 'colo',
|
||||||
\ 'options': '+m',
|
\ 'options': '+m',
|
||||||
\ 'tmux_width': 20,
|
\ 'tmux_width': 20,
|
||||||
\ 'xterm_options': '-geometry 20x30'
|
\ 'launcher': 'xterm -geometry 20x30 -e bash -ic %s'
|
||||||
\ })<CR>
|
\ })<CR>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
let s:min_tmux_width = 10
|
let s:min_tmux_width = 10
|
||||||
let s:min_tmux_height = 3
|
let s:min_tmux_height = 3
|
||||||
let s:default_tmux_height = '40%'
|
let s:default_tmux_height = '40%'
|
||||||
let s:gui_supported = executable('bash') && executable('xterm')
|
let s:launcher = 'xterm -e bash -ic %s'
|
||||||
|
|
||||||
let s:cpo_save = &cpo
|
let s:cpo_save = &cpo
|
||||||
set cpo&vim
|
set cpo&vim
|
||||||
@ -68,12 +68,6 @@ function! s:escape(path)
|
|||||||
endfunction
|
endfunction
|
||||||
|
|
||||||
function! fzf#run(...) abort
|
function! fzf#run(...) abort
|
||||||
if has('gui_running') && !s:gui_supported
|
|
||||||
echohl Error
|
|
||||||
echo 'bash and xterm required to run fzf in GVim'
|
|
||||||
return []
|
|
||||||
endif
|
|
||||||
|
|
||||||
let dict = exists('a:1') ? a:1 : {}
|
let dict = exists('a:1') ? a:1 : {}
|
||||||
let temps = { 'result': tempname() }
|
let temps = { 'result': tempname() }
|
||||||
let optstr = get(dict, 'options', '')
|
let optstr = get(dict, 'options', '')
|
||||||
@ -125,14 +119,16 @@ function! s:execute(dict, command, temps)
|
|||||||
call s:pushd(a:dict)
|
call s:pushd(a:dict)
|
||||||
silent !clear
|
silent !clear
|
||||||
if has('gui_running')
|
if has('gui_running')
|
||||||
let xterm_options = get(a:dict, 'xterm_options', get(g:, 'fzf_xterm_options', ''))
|
let launcher = get(a:dict, 'launcher', get(g:, 'fzf_launcher', s:launcher))
|
||||||
execute "silent !xterm ".xterm_options.
|
let command = printf(launcher, "'".substitute(a:command, "'", "'\"'\"'", 'g')."'")
|
||||||
\ " -e bash -ic '".substitute(a:command, "'", "'\"'\"'", 'g')."'"
|
|
||||||
else
|
else
|
||||||
execute 'silent !'.a:command
|
let command = a:command
|
||||||
endif
|
endif
|
||||||
|
execute 'silent !'.command
|
||||||
redraw!
|
redraw!
|
||||||
if v:shell_error
|
if v:shell_error
|
||||||
|
echohl Error
|
||||||
|
echo 'Error running ' . command
|
||||||
return []
|
return []
|
||||||
else
|
else
|
||||||
return s:callback(a:dict, a:temps, 0)
|
return s:callback(a:dict, a:temps, 0)
|
||||||
|
Loading…
Reference in New Issue
Block a user