[Vim] Allow vertical split of tmux window
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent ded184d · Browse files · 2 files·+34 added−19 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+34 added−19 removed
- other:+34 added−19 removed
Provenance
- Commit
16031b0- Tree
5589d8e- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
ded184d
2 files changed+34 added−19 removed
modified:plugin/fzf.vim+21 added-7 removed
19 unmodified lines20 " LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION21 " OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION22 " WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.23 24+let s:min_tmux_width = 1025 let s:min_tmux_height = 326 let s:default_tmux_height = '40%'27 28 let s:cpo_save = &cpo59 unmodified lines88 let prefix = ''89 endif90 let command = prefix.s:exec.' '.optstr.' > '.temps.result91 91- if s:tmux_enabled() && has_key(dict, 'tmux') &&92- \ dict.tmux > 0 && winheight(0) >= s:min_tmux_height92+ if s:tmux_enabled() && s:tmux_splittable(dict)93 return s:execute_tmux(dict, command, temps)94 else95 return s:execute(dict, command, temps)96 endif97 endfunction98 99+function! s:tmux_splittable(dict)100+ return101+ \ min([&columns, get(a:dict, 'tmux_width', 0)]) >= s:min_tmux_width ||102+ \ min([&lines, get(a:dict, 'tmux_height', get(a:dict, 'tmux', 0))]) >= s:min_tmux_height103+endfunction104+105 function! s:pushd(dict)106 if has_key(a:dict, 'dir')107 let a:dict.prev_dir = getcwd()108 execute 'chdir '.s:escape(a:dict.dir)24 unmodified lines133 else134 let command = a:command135 endif136 131- if type(a:dict.tmux) == 1 && a:dict.tmux =~ '%$'132- let height = '-p '.a:dict.tmux[0:-2]137+ let splitopt = '-v'138+ if has_key(a:dict, 'tmux_width')139+ let splitopt = '-h'140+ let size = a:dict.tmux_width141 else134- let height = '-l '.a:dict.tmux142+ let size = get(a:dict, 'tmux_height', get(a:dict, 'tmux'))143 endif144 145+ if type(size) == 1 && size =~ '%$'146+ let sizeopt = '-p '.size[0:-2]147+ else148+ let sizeopt = '-l '.size149+ endif150+151 let s:pane = substitute(152 \ system(153 \ printf(140- \ 'tmux split-window %s -P -F "#{pane_id}" %s',141- \ height, s:shellesc(command))), '\n', '', 'g')154+ \ 'tmux split-window %s %s -P -F "#{pane_id}" %s',155+ \ splitopt, sizeopt, s:shellesc(command))), '\n', '', 'g')156 let s:dict = a:dict157 let s:temps = a:temps158 159 augroup fzf_tmux62 unmodified linesmodified:README.md+13 added-12 removed
330 unmodified lines331 of the selected items.332 333 `fzf#run()` may take an options-dictionary:334 335-| Option name | Type | Description |336-| ----------- | ------------- | ------------------------------------------------------------------- |337-| `source` | string | External command to generate input to fzf (e.g. `find .`) |338-| `source` | list | Vim list as input to fzf |339-| `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) |340-| `sink` | funcref | Reference to function to process each selected item |341-| `options` | string | Options to fzf |342-| `dir` | string | Working directory |343-| `tmux` | number/string | Use tmux split if possible with the given height (e.g. `20`, `50%`) |335+| Option name | Type | Description |336+| ------------- | ------------- | ------------------------------------------------------------------ |337+| `source` | string | External command to generate input to fzf (e.g. `find .`) |338+| `source` | list | Vim list as input to fzf |339+| `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) |340+| `sink` | funcref | Reference to function to process each selected item |341+| `options` | string | Options to fzf |342+| `dir` | string | Working directory |343+| `tmux_width` | number/string | Use tmux vertical split with the given height (e.g. `20`, `50%`) |344+| `tmux_height` | number/string | Use tmux horizontal split with the given height (e.g. `20`, `50%`) |345 346 #### Examples347 348 If `sink` option is not given, `fzf#run` will simply return the list.17 unmodified lines366 nnoremap <silent> <Leader>C :call fzf#run({367 \ 'source':368 \ map(split(globpath(&rtp, "colors/*.vim"), "\n"),369 \ "substitute(fnamemodify(v:val, ':t'), '\\..\\{-}$', '', '')"),369-\ 'sink': 'colo',370-\ 'options': '+m',371-\ 'tmux': 15370+\ 'sink': 'colo',371+\ 'options': '+m',372+\ 'tmux_width': 20373 \ })<CR>374 ```375 376 `sink` option can be a function reference. The following example creates a89 unmodified lines