[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:
|
`fzf#run()` may take an options-dictionary:
|
||||||
|
|
||||||
| Option name | Type | Description |
|
| Option name | Type | Description |
|
||||||
| ----------- | ------------- | ------------------------------------------------------------------- |
|
| ------------- | ------------- | ------------------------------------------------------------------ |
|
||||||
| `source` | string | External command to generate input to fzf (e.g. `find .`) |
|
| `source` | string | External command to generate input to fzf (e.g. `find .`) |
|
||||||
| `source` | list | Vim list as input to fzf |
|
| `source` | list | Vim list as input to fzf |
|
||||||
| `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) |
|
| `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) |
|
||||||
| `sink` | funcref | Reference to function to process each selected item |
|
| `sink` | funcref | Reference to function to process each selected item |
|
||||||
| `options` | string | Options to fzf |
|
| `options` | string | Options to fzf |
|
||||||
| `dir` | string | Working directory |
|
| `dir` | string | Working directory |
|
||||||
| `tmux` | number/string | Use tmux split if possible 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%`) |
|
||||||
|
|
||||||
#### Examples
|
#### Examples
|
||||||
|
|
||||||
@ -366,9 +367,9 @@ 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': 15
|
\ 'tmux_width': 20
|
||||||
\ })<CR>
|
\ })<CR>
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
" OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
" OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||||
" WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
" 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:min_tmux_height = 3
|
||||||
let s:default_tmux_height = '40%'
|
let s:default_tmux_height = '40%'
|
||||||
|
|
||||||
@ -88,14 +89,19 @@ function! fzf#run(...) abort
|
|||||||
endif
|
endif
|
||||||
let command = prefix.s:exec.' '.optstr.' > '.temps.result
|
let command = prefix.s:exec.' '.optstr.' > '.temps.result
|
||||||
|
|
||||||
if s:tmux_enabled() && has_key(dict, 'tmux') &&
|
if s:tmux_enabled() && s:tmux_splittable(dict)
|
||||||
\ dict.tmux > 0 && winheight(0) >= s:min_tmux_height
|
|
||||||
return s:execute_tmux(dict, command, temps)
|
return s:execute_tmux(dict, command, temps)
|
||||||
else
|
else
|
||||||
return s:execute(dict, command, temps)
|
return s:execute(dict, command, temps)
|
||||||
endif
|
endif
|
||||||
endfunction
|
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)
|
function! s:pushd(dict)
|
||||||
if has_key(a:dict, 'dir')
|
if has_key(a:dict, 'dir')
|
||||||
let a:dict.prev_dir = getcwd()
|
let a:dict.prev_dir = getcwd()
|
||||||
@ -128,17 +134,25 @@ function! s:execute_tmux(dict, command, temps)
|
|||||||
let command = a:command
|
let command = a:command
|
||||||
endif
|
endif
|
||||||
|
|
||||||
if type(a:dict.tmux) == 1 && a:dict.tmux =~ '%$'
|
let splitopt = '-v'
|
||||||
let height = '-p '.a:dict.tmux[0:-2]
|
if has_key(a:dict, 'tmux_width')
|
||||||
|
let splitopt = '-h'
|
||||||
|
let size = a:dict.tmux_width
|
||||||
else
|
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
|
endif
|
||||||
|
|
||||||
let s:pane = substitute(
|
let s:pane = substitute(
|
||||||
\ system(
|
\ system(
|
||||||
\ printf(
|
\ printf(
|
||||||
\ 'tmux split-window %s -P -F "#{pane_id}" %s',
|
\ 'tmux split-window %s %s -P -F "#{pane_id}" %s',
|
||||||
\ height, s:shellesc(command))), '\n', '', 'g')
|
\ splitopt, sizeopt, s:shellesc(command))), '\n', '', 'g')
|
||||||
let s:dict = a:dict
|
let s:dict = a:dict
|
||||||
let s:temps = a:temps
|
let s:temps = a:temps
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user