mirror of
https://github.com/Llewellynvdm/fzf.git
synced 2024-11-22 04:45:14 +00:00
[Vim] Allow vertical split of tmux window
This commit is contained in:
parent
ded184daaf
commit
16031b0d54
25
README.md
25
README.md
@ -332,15 +332,16 @@ of the selected items.
|
||||
|
||||
`fzf#run()` may take an options-dictionary:
|
||||
|
||||
| Option name | Type | Description |
|
||||
| ----------- | ------------- | ------------------------------------------------------------------- |
|
||||
| `source` | string | External command to generate input to fzf (e.g. `find .`) |
|
||||
| `source` | list | Vim list as input to fzf |
|
||||
| `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) |
|
||||
| `sink` | funcref | Reference to function to process each selected item |
|
||||
| `options` | string | Options to fzf |
|
||||
| `dir` | string | Working directory |
|
||||
| `tmux` | number/string | Use tmux split if possible with the given height (e.g. `20`, `50%`) |
|
||||
| Option name | Type | Description |
|
||||
| ------------- | ------------- | ------------------------------------------------------------------ |
|
||||
| `source` | string | External command to generate input to fzf (e.g. `find .`) |
|
||||
| `source` | list | Vim list as input to fzf |
|
||||
| `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) |
|
||||
| `sink` | funcref | Reference to function to process each selected item |
|
||||
| `options` | string | Options to fzf |
|
||||
| `dir` | string | Working directory |
|
||||
| `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%`) |
|
||||
|
||||
#### Examples
|
||||
|
||||
@ -366,9 +367,9 @@ nnoremap <silent> <Leader>C :call fzf#run({
|
||||
\ 'source':
|
||||
\ map(split(globpath(&rtp, "colors/*.vim"), "\n"),
|
||||
\ "substitute(fnamemodify(v:val, ':t'), '\\..\\{-}$', '', '')"),
|
||||
\ 'sink': 'colo',
|
||||
\ 'options': '+m',
|
||||
\ 'tmux': 15
|
||||
\ 'sink': 'colo',
|
||||
\ 'options': '+m',
|
||||
\ 'tmux_width': 20
|
||||
\ })<CR>
|
||||
```
|
||||
|
||||
|
@ -21,6 +21,7 @@
|
||||
" OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
" WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
let s:min_tmux_width = 10
|
||||
let s:min_tmux_height = 3
|
||||
let s:default_tmux_height = '40%'
|
||||
|
||||
@ -88,14 +89,19 @@ function! fzf#run(...) abort
|
||||
endif
|
||||
let command = prefix.s:exec.' '.optstr.' > '.temps.result
|
||||
|
||||
if s:tmux_enabled() && has_key(dict, 'tmux') &&
|
||||
\ dict.tmux > 0 && winheight(0) >= s:min_tmux_height
|
||||
if s:tmux_enabled() && s:tmux_splittable(dict)
|
||||
return s:execute_tmux(dict, command, temps)
|
||||
else
|
||||
return s:execute(dict, command, temps)
|
||||
endif
|
||||
endfunction
|
||||
|
||||
function! s:tmux_splittable(dict)
|
||||
return
|
||||
\ min([&columns, get(a:dict, 'tmux_width', 0)]) >= s:min_tmux_width ||
|
||||
\ min([&lines, get(a:dict, 'tmux_height', get(a:dict, 'tmux', 0))]) >= s:min_tmux_height
|
||||
endfunction
|
||||
|
||||
function! s:pushd(dict)
|
||||
if has_key(a:dict, 'dir')
|
||||
let a:dict.prev_dir = getcwd()
|
||||
@ -128,17 +134,25 @@ function! s:execute_tmux(dict, command, temps)
|
||||
let command = a:command
|
||||
endif
|
||||
|
||||
if type(a:dict.tmux) == 1 && a:dict.tmux =~ '%$'
|
||||
let height = '-p '.a:dict.tmux[0:-2]
|
||||
let splitopt = '-v'
|
||||
if has_key(a:dict, 'tmux_width')
|
||||
let splitopt = '-h'
|
||||
let size = a:dict.tmux_width
|
||||
else
|
||||
let height = '-l '.a:dict.tmux
|
||||
let size = get(a:dict, 'tmux_height', get(a:dict, 'tmux'))
|
||||
endif
|
||||
|
||||
if type(size) == 1 && size =~ '%$'
|
||||
let sizeopt = '-p '.size[0:-2]
|
||||
else
|
||||
let sizeopt = '-l '.size
|
||||
endif
|
||||
|
||||
let s:pane = substitute(
|
||||
\ system(
|
||||
\ printf(
|
||||
\ 'tmux split-window %s -P -F "#{pane_id}" %s',
|
||||
\ height, s:shellesc(command))), '\n', '', 'g')
|
||||
\ 'tmux split-window %s %s -P -F "#{pane_id}" %s',
|
||||
\ splitopt, sizeopt, s:shellesc(command))), '\n', '', 'g')
|
||||
let s:dict = a:dict
|
||||
let s:temps = a:temps
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user