summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2022-04-04 22:54:41 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2022-04-04 22:59:26 +0900
commit3c868d7961bb533b65cee9516cc55f49f852678a (patch)
treeb17f3ba115bd4f0a55901b8c94ad8f1feaf8ec47
parent707f4f58161b84852b33a7f09ea6c0134e5e3035 (diff)
ADVANCED.md: Add rebind example
-rw-r--r--ADVANCED.md35
1 files changed, 35 insertions, 0 deletions
diff --git a/ADVANCED.md b/ADVANCED.md
index 111a1ae5..ed18c61c 100644
--- a/ADVANCED.md
+++ b/ADVANCED.md
@@ -17,6 +17,7 @@ Advanced fzf examples
* [Using fzf as the secondary filter](#using-fzf-as-the-secondary-filter)
* [Using fzf as interative Ripgrep launcher](#using-fzf-as-interative-ripgrep-launcher)
* [Switching to fzf-only search mode](#switching-to-fzf-only-search-mode)
+ * [Switching between Ripgrep mode and fzf mode](#switching-between-ripgrep-mode-and-fzf-mode)
* [Log tailing](#log-tailing)
* [Key bindings for git objects](#key-bindings-for-git-objects)
* [Files listed in `git status`](#files-listed-in-git-status)
@@ -405,6 +406,40 @@ IFS=: read -ra selected < <(
- We reverted `--color` option for customizing how the matching chunks are
displayed in the second phase
+### Switching between Ripgrep mode and fzf mode
+
+*(Requires fzf 0.30.0 or above)*
+
+fzf 0.30.0 added `rebind` action so we can "rebind" the bindings that were
+previously "unbound" via `unbind`.
+
+This is an improved version of the previous example that allows us to switch
+between Ripgrep launcher mode and fzf-only filtering mode via CTRL-R and
+CTRL-F.
+
+```sh
+#!/usr/bin/env bash
+
+# Switch between Ripgrep launcher mode (CTRL-R) and fzf filtering mode (CTRL-F)
+RG_PREFIX="rg --column --line-number --no-heading --color=always --smart-case "
+INITIAL_QUERY="${*:-}"
+IFS=: read -ra selected < <(
+ FZF_DEFAULT_COMMAND="$RG_PREFIX $(printf %q "$INITIAL_QUERY")" \
+ fzf --ansi \
+ --color "hl:-1:underline,hl+:-1:underline:reverse" \
+ --disabled --query "$INITIAL_QUERY" \
+ --bind "change:reload:sleep 0.1; $RG_PREFIX {q} || true" \
+ --bind "ctrl-f:unbind(change,ctrl-f)+change-prompt(2. fzf> )+enable-search+clear-query+rebind(ctrl-r)" \
+ --bind "ctrl-r:unbind(ctrl-r)+change-prompt(1. ripgrep> )+disable-search+reload($RG_PREFIX {q} || true)+rebind(change,ctrl-f)" \
+ --prompt '1. Ripgrep> ' \
+ --delimiter : \
+ --header '╱ CTRL-R (Ripgrep mode) ╱ CTRL-F (fzf mode) ╱' \
+ --preview 'bat --color=always {1} --highlight-line {2}' \
+ --preview-window 'up,60%,border-bottom,+{2}+3/3,~3'
+)
+[ -n "${selected[0]}" ] && vim "${selected[0]}" "+${selected[1]}"
+```
+
Log tailing
-----------