From 3b2e932c132d6d0be789b65d7eeb5be2a6917a9d Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sat, 6 Jul 2024 14:10:02 +0900 Subject: [PATCH] Bind CTRL-/ and ALT-/ to toggle-wrap by default --- CHANGELOG.md | 14 ++++++++------ README.md | 4 +--- man/man1/fzf.1 | 2 +- shell/key-bindings.bash | 4 ++-- shell/key-bindings.fish | 4 ++-- shell/key-bindings.zsh | 4 ++-- src/terminal.go | 2 ++ 7 files changed, 18 insertions(+), 16 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 31312dd..5189277 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,12 +7,14 @@ CHANGELOG - `--wrap` option enables line wrap - `--wrap-sign` customizes the sign for wrapped lines (default: `↳ `) - `toggle-wrap` action toggles line wrap - ```sh - history | fzf --tac --wrap --bind 'ctrl-/:toggle-wrap' - - # You can press CTRL-/ to toggle line wrap in CTRL-R binding - export FZF_CTRL_R_OPTS=$'--bind ctrl-/:toggle-wrap --wrap-sign "\t↳ "' - ``` + ```sh + history | fzf --tac --wrap --bind 'ctrl-/:toggle-wrap' --wrap-sign $'\t↳ ' + ``` + - fzf by default binds `CTRL-/` and `ALT-/` to `toggle-wrap` +- Updated shell integration scripts to leverage line wrap + - CTRL-R binding includes `--wrap-sign $'\t↳ '` to indent wrapped lines + - `kill **` completion uses `--wrap` to show the whole line by default + instead of showing it in the preview window - Added `--info-command` option for customizing the info line ```sh # Prepend the current cursor position in yellow diff --git a/README.md b/README.md index b106f75..d026ea1 100644 --- a/README.md +++ b/README.md @@ -464,13 +464,11 @@ the following key bindings in bash, zsh, and fish. - `CTRL-R` - Paste the selected command from history onto the command-line - If you want to see the commands in chronological order, press `CTRL-R` again which toggles sorting by relevance + - Press `CTRL-/` or `ALT-/` to toggle line wrapping - Set `FZF_CTRL_R_OPTS` to pass additional options to fzf ```sh - # CTRL-/ to toggle small preview window to see the full command # CTRL-Y to copy the command into clipboard using pbcopy export FZF_CTRL_R_OPTS=" - --preview 'echo {}' --preview-window up:3:hidden:wrap - --bind 'ctrl-/:toggle-preview' --bind 'ctrl-y:execute-silent(echo -n {2..} | pbcopy)+abort' --color header:italic --header 'Press CTRL-Y to copy command into clipboard'" diff --git a/man/man1/fzf.1 b/man/man1/fzf.1 index 1476143..ef77ae8 100644 --- a/man/man1/fzf.1 +++ b/man/man1/fzf.1 @@ -1497,7 +1497,7 @@ A key or an event can be bound to one or more of the following actions. \fBtoggle\-sort\fR \fBtoggle\-track\fR (toggle global tracking option (\fB\-\-track\fR)) \fBtoggle\-track\-current\fR (toggle tracking of the current item) - \fBtoggle\-wrap\fR + \fBtoggle\-wrap\fR \fIctrl\-/\fR \fIalt\-/\fR \fBtoggle+up\fR \fIbtab (shift\-tab)\fR \fBtrack\-current\fR (track the current item; automatically disabled if focus changes) \fBtransform(...)\fR (transform states using the output of an external command) diff --git a/shell/key-bindings.bash b/shell/key-bindings.bash index 5218feb..2da32cb 100644 --- a/shell/key-bindings.bash +++ b/shell/key-bindings.bash @@ -62,7 +62,7 @@ if command -v perl > /dev/null; then set +o pipefail builtin fc -lnr -2147483648 | last_hist=$(HISTTIMEFORMAT='' builtin history 1) command perl -n -l0 -e "$script" | - FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --highlight-line ${FZF_CTRL_R_OPTS-} +m --read0") \ + FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"$'\t'"↳ ' --highlight-line ${FZF_CTRL_R_OPTS-} +m --read0") \ FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) --query "$READLINE_LINE" ) || return READLINE_LINE=$(command perl -pe 's/^\d*\t//' <<< "$output") @@ -91,7 +91,7 @@ else # awk - fallback for POSIX systems set +o pipefail builtin fc -lnr -2147483648 2> /dev/null | # ( $'\t '$'\n' )* ; ::= [^\n]* ( $'\n' )* command $__fzf_awk "$script" | # ( $'\t'$'\000' )* - FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --highlight-line ${FZF_CTRL_R_OPTS-} +m --read0") \ + FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"$'\t'"↳ ' --highlight-line ${FZF_CTRL_R_OPTS-} +m --read0") \ FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd) --query "$READLINE_LINE" ) || return READLINE_LINE=${output#*$'\t'} diff --git a/shell/key-bindings.fish b/shell/key-bindings.fish index 7f14c0d..523203b 100644 --- a/shell/key-bindings.fish +++ b/shell/key-bindings.fish @@ -72,12 +72,12 @@ function fzf_key_bindings # before 2.4.0. if [ "$FISH_MAJOR" -gt 2 -o \( "$FISH_MAJOR" -eq 2 -a "$FISH_MINOR" -ge 4 \) ]; if type -P perl > /dev/null 2>&1 - set -lx FZF_DEFAULT_OPTS (__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --highlight-line $FZF_CTRL_R_OPTS +m") + set -lx FZF_DEFAULT_OPTS (__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"\t"↳ ' --highlight-line $FZF_CTRL_R_OPTS +m") set -lx FZF_DEFAULT_OPTS_FILE '' builtin history -z --reverse | command perl -0 -pe 's/^/$.\t/g; s/\n/\n\t/gm' | eval (__fzfcmd) --tac --read0 --print0 -q '(commandline)' | command perl -pe 's/^\d*\t//' | read -lz result and commandline -- $result else - set -lx FZF_DEFAULT_OPTS (__fzf_defaults "" "--scheme=history --bind=ctrl-r:toggle-sort --highlight-line $FZF_CTRL_R_OPTS +m") + set -lx FZF_DEFAULT_OPTS (__fzf_defaults "" "--scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '"\t"↳ ' --highlight-line $FZF_CTRL_R_OPTS +m") set -lx FZF_DEFAULT_OPTS_FILE '' builtin history -z | eval (__fzfcmd) --read0 --print0 -q '(commandline)' | read -lz result and commandline -- $result diff --git a/shell/key-bindings.zsh b/shell/key-bindings.zsh index eea5189..a4d7055 100644 --- a/shell/key-bindings.zsh +++ b/shell/key-bindings.zsh @@ -113,11 +113,11 @@ fzf-history-widget() { if zmodload -F zsh/parameter p:history 2>/dev/null && (( ${#commands[perl]} )); then selected="$(printf '%s\t%s\000' "${(kv)history[@]}" | perl -0 -ne 'if (!$seen{(/^\s*[0-9]+\**\t(.*)/s, $1)}++) { s/\n/\n\t/g; print; }' | - FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --highlight-line ${FZF_CTRL_R_OPTS-} --query=${(qqq)LBUFFER} +m --read0") \ + FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '\t↳ ' --highlight-line ${FZF_CTRL_R_OPTS-} --query=${(qqq)LBUFFER} +m --read0") \ FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd))" else selected="$(fc -rl 1 | awk '{ cmd=$0; sub(/^[ \t]*[0-9]+\**[ \t]+/, "", cmd); if (!seen[cmd]++) print $0 }' | - FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --highlight-line ${FZF_CTRL_R_OPTS-} --query=${(qqq)LBUFFER} +m") \ + FZF_DEFAULT_OPTS=$(__fzf_defaults "" "-n2..,.. --scheme=history --bind=ctrl-r:toggle-sort --wrap-sign '\t↳ ' --highlight-line ${FZF_CTRL_R_OPTS-} --query=${(qqq)LBUFFER} +m") \ FZF_DEFAULT_OPTS_FILE='' $(__fzfcmd))" fi local ret=$? diff --git a/src/terminal.go b/src/terminal.go index c97445b..4acb041 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -617,6 +617,8 @@ func defaultKeymap() map[tui.Event][]*action { if !util.IsWindows() { add(tui.CtrlZ, actSigStop) } + add(tui.CtrlSlash, actToggleWrap) + addEvent(tui.AltKey('/'), actToggleWrap) addEvent(tui.AltKey('b'), actBackwardWord) add(tui.ShiftLeft, actBackwardWord)