Allow setting tmux split height in %
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 995d380 · Browse files · 3 files·+42 added−18 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
3 files+42 added−18 removed
- other:+42 added−18 removed
Provenance
- Commit
cf8dbf8- Tree
172c966- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
995d380
3 files changed+42 added−18 removed
modified:plugin/fzf.vim+12 added-2 removed
20 unmodified lines21 " 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_height = 325-let s:default_tmux_height = 1525+let s:default_tmux_height = '40%'26 27 let s:cpo_save = &cpo28 set cpo&vim29 83 unmodified lines113 let command = 'cd '.s:escape(a:dict.dir).' && '.a:command114 else115 let command = a:command116 endif117+118+ if type(a:dict.tmux) == 1119+ if a:dict.tmux =~ '%$'120+ let height = screenrow() * str2nr(a:dict.tmux[0:-2]) / 100121+ else122+ let height = str2nr(a:dict.tmux)123+ endif124+ else117- let height = a:dict.tmux125+ let height = a:dict.tmux126+ endif127+128 let s:pane = substitute(129 \ system(130 \ printf(131 \ 'tmux split-window -l %d -P -F "#{pane_id}" %s',67 unmodified linesmodified:install+18 added-4 removed
113 unmodified lines114 eval "$__fsel"115 }116 117 __fsel_tmux() {118+ local height lines119+ height=${FZF_TMUX_HEIGHT:-40%}120+ lines=${LINES:-40}121+ if [[ $height =~ %$ ]]; then122+ height=${height:0:${#height}-1}123+ height=$(( height * lines / 100 ))124+ fi118- tmux split-window -l ${FZF_TMUX_HEIGHT:-15} "tmux send-keys -t $TMUX_PANE \"\$($__fsel)\""125+ tmux split-window -l $height "tmux send-keys -t $TMUX_PANE \"\$($__fsel)\""126 }127 128 __fcd() {129 local dir130 dir=$(find ${1:-*} -path '*/\.*' -prune -o -type d -print 2> /dev/null | fzf +m) && printf 'cd %q' "$dir"131 }132 133 __use_tmux=0127-[ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-30} -gt 15 ] && __use_tmux=1134+[ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-40} -gt 15 ] && __use_tmux=1135 136 if [ -z "$(set -o | grep '^vi.*on')" ]; then137 # Required to refresh the prompt after fzf138 bind '"\er": redraw-current-line'47 unmodified lines186 done187 echo188 EOF189 183-if [ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-30} -gt 15 ]; then190+if [ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-40} -gt 15 ]; then191 fzf-file-widget() {192+ local height lines193+ height=${FZF_TMUX_HEIGHT:-40%}194+ lines=${LINES:-40}195+ if [[ $height =~ %$ ]]; then196+ height=${height:0:${#height}-1}197+ height=$(( height * lines / 100 ))198+ fi185- tmux split-window -l ${FZF_TMUX_HEIGHT:-15} "tmux send-keys -t $TMUX_PANE \"\$($__fsel)\""199+ tmux split-window -l $height "tmux send-keys -t $TMUX_PANE \"\$($__fsel)\""200 }201 else202 fzf-file-widget() {203 LBUFFER="${LBUFFER%% #}$(eval "$__fsel")"54 unmodified linesmodified:README.md+12 added-12 removed
212 unmodified lines213 - `ALT-C` - cd into the selected directory214 215 If you're on a tmux session, `CTRL-T` will launch fzf in a new split-window. You216 may disable this tmux integration by setting `FZF_TMUX` to 0, or change the217-height of the window with `FZF_TMUX_HEIGHT`.217+height of the window with `FZF_TMUX_HEIGHT` (e.g. `20`, `50%`).218 219 The source code can be found in `~/.fzf.bash` and in `~/.fzf.zsh`.220 221 Auto-completion92 unmodified lines314 Note that the environment variables `FZF_DEFAULT_COMMAND` and `FZF_DEFAULT_OPTS`315 also apply here.316 317 If you're on a tmux session, `:FZF` will launch fzf in a new split-window whose318-height can be adjusted with `g:fzf_tmux_height` (default: 15). However, the bang319-version (`:FZF!`) will always start in fullscreen.318+height can be adjusted with `g:fzf_tmux_height` (default: '40%'). However, the319+bang version (`:FZF!`) will always start in fullscreen.320 321 ### `fzf#run([options])`322 323 For more advanced uses, you can call `fzf#run()` function which returns the list324 of the selected items.325 326 `fzf#run()` may take an options-dictionary:327 328-| Option name | Type | Description |329-| ----------- | ------- | ---------------------------------------------------------- |330-| `source` | string | External command to generate input to fzf (e.g. `find .`) |331-| `source` | list | Vim list as input to fzf |332-| `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) |333-| `sink` | funcref | Reference to function to process each selected item |334-| `options` | string | Options to fzf |335-| `dir` | string | Working directory |336-| `tmux` | number | Use tmux split if possible with the given height |328+| Option name | Type | Description |329+| ----------- | ------------- | ------------------------------------------------------------------- |330+| `source` | string | External command to generate input to fzf (e.g. `find .`) |331+| `source` | list | Vim list as input to fzf |332+| `sink` | string | Vim command to handle the selected item (e.g. `e`, `tabe`) |333+| `sink` | funcref | Reference to function to process each selected item |334+| `options` | string | Options to fzf |335+| `dir` | string | Working directory |336+| `tmux` | number/string | Use tmux split if possible with the given height (e.g. `20`, `50%`) |337 338 #### Examples339 340 If `sink` option is not given, `fzf#run` will simply return the list.93 unmodified lines