Skip to content
Myr

Merge pull request #30 from junegunn/keybinding-tmux-split

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Make CTRL-T use tmux split when possible

authored by Junegunn Choi · committed by Junegunn Choi · parents 2b34665, ae86cdf · Browse files · 2 files+51 added−20 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+51 added−20 removed

  • other:+51 added−20 removed

2 files+51 added−20 removed

modified:install+46 added-19 removed
93 unmodified lines
94EOF9596 if [ $key_bindings -eq 0 ]; then97 if [ $shell = bash ]; then98 cat >> $src << "EOF"98 cat >> $src << "EOFZF"99# Key bindings100# ------------101if [[ $- =~ i ]]; then102103__fsel() {103read -r -d '' __fsel <<'EOF'104 find * -path '*/\.*' -prune \105 -o -type f -print \106 -o -type d -print \107 -o -type l -print 2> /dev/null | fzf -m | while read item; do108 printf '%q ' "$item"109 done110 echo111EOF112113__fsel() {114 eval "$__fsel"115}116117__fsel_tmux() {118 tmux split-window -l ${FZF_TMUX_HEIGHT:-15} "tmux send-keys -t $TMUX_PANE \"\$($__fsel)\""119}120121__fcd() {122 local dir123 dir=$(find ${1:-*} -path '*/\.*' -prune -o -type d -print 2> /dev/null | fzf +m) && printf 'cd %q' "$dir"124}125126__use_tmux=0127[ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-30} -gt 15 ] && __use_tmux=1128129if [ -z "$(set -o | grep '^vi.*on')" ]; then130 # Required to refresh the prompt after fzf131 bind '"\er": redraw-current-line'132133 # CTRL-T - Paste the selected file path into the command line134 if [ $__use_tmux -eq 1 ]; then135 bind '"\C-t": " \C-u \C-a\C-k$(__fsel_tmux)\e\C-e\C-y\C-a\C-d\C-y\ey\C-h"'136 else123 bind '"\C-t": " \C-u \C-a\C-k$(__fsel)\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er"'137 bind '"\C-t": " \C-u \C-a\C-k$(__fsel)\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er"'138 fi139140 # CTRL-R - Paste the selected command from history into the command line141 bind '"\C-r": " \C-e\C-u$(HISTTIMEFORMAT= history | fzf +s | sed \"s/ *[0-9]* *//\")\e\C-e\er"'142
4 unmodified lines
147 bind '"\C-x\C-r": redraw-current-line'148149 # CTRL-T - Paste the selected file path into the command line150 # - FIXME: Selected items are attached to the end regardless of cursor position136 bind '"\C-t": "\eddi$(__fsel)\C-x\C-e\e0P$a \C-x\C-r"'151 if [ $__use_tmux -eq 1 ]; then152 bind '"\C-t": "\e$a \eddi$(__fsel_tmux)\C-x\C-e\e0P$xa"'153 else154 bind '"\C-t": "\e$a \eddi$(__fsel)\C-x\C-e\e0Px$a \C-x\C-r"'155 fi156157 # CTRL-R - Paste the selected command from history into the command line158 bind '"\C-r": "\eddi$(HISTTIMEFORMAT= history | fzf +s | sed \"s/ *[0-9]* *//\")\C-x\C-e\e$a\C-x\C-r"'159160 # ALT-C - cd into the selected directory161 bind '"\ec": "\eddi$(__fcd)\C-x\C-e\C-x\C-r\C-m"'162fi163164unset __use_tmux165166fi146EOF167EOFZF168 else148 cat >> $src << "EOF"169 cat >> $src << "EOFZF"170# Key bindings171# ------------172# CTRL-T - Paste the selected file path(s) into the command line152fzf-file-widget() {153 local FILES154 local IFS="155"156 FILES=($(157 find * -path '*/\.*' -prune \173read -r -d '' __fsel <<'EOF'174 find * -path '*/\.*' -prune \175 -o -type f -print \176 -o -type d -print \160 -o -type l -print 2> /dev/null | fzf -m))161 unset IFS162 FILES=$FILES:q163 LBUFFER="${LBUFFER%% #} $FILES"164 zle redisplay165}177 -o -type l -print 2> /dev/null | fzf -m | while read item; do178 printf '%q ' "$item"179 done180 echo181EOF182183if [ -n "$TMUX_PANE" -a ${FZF_TMUX:-1} -ne 0 -a ${LINES:-30} -gt 15 ]; then184 fzf-file-widget() {185 tmux split-window -l ${FZF_TMUX_HEIGHT:-15} "tmux send-keys -t $TMUX_PANE \"\$($__fsel)\""186 }187else188 fzf-file-widget() {189 LBUFFER="${LBUFFER%% #}$(eval "$__fsel")"190 zle redisplay191 }192fi193zle -N fzf-file-widget194bindkey '^T' fzf-file-widget195196# ALT-C - cd into the selected directory
12 unmodified lines
209}210zle -N fzf-history-widget211bindkey '^R' fzf-history-widget212186EOF213EOFZF214 fi215 fi216217 echo "OK"
26 unmodified lines
modified:README.md+5 added-1 removed
210 unmodified lines
211- `CTRL-T` - Paste the selected file path(s) into the command line212- `CTRL-R` - Paste the selected command from history into the command line213- `ALT-C` - cd into the selected directory214215If you're on a tmux session, `CTRL-T` will launch fzf in a new split-window. You216may disable this tmux integration by setting `FZF_TMUX` to 0, or change the217height of the window with `FZF_TMUX_HEIGHT`.218219The source code can be found in `~/.fzf.bash` and in `~/.fzf.zsh`.220221Auto-completion222---------------
90 unmodified lines
313314Note that the environment variables `FZF_DEFAULT_COMMAND` and `FZF_DEFAULT_OPTS`315also apply here.316313If you're on a tmux session, `:FZF`, will launch fzf in a new split-window whose317If you're on a tmux session, `:FZF` will launch fzf in a new split-window whose318height can be adjusted with `g:fzf_tmux_height` (default: 15). However, the bang319version (`:FZF!`) will always start in fullscreen.320321### `fzf#run([options])`
112 unmodified lines