From f22d158f0261a750262ccb805c55c94e76d0445c Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 9 Oct 2016 04:13:38 +0900 Subject: [PATCH] Created Configuring shell key bindings (markdown) --- Configuring-shell-key-bindings.md | 61 +++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 Configuring-shell-key-bindings.md diff --git a/Configuring-shell-key-bindings.md b/Configuring-shell-key-bindings.md new file mode 100644 index 0000000..adfdd9a --- /dev/null +++ b/Configuring-shell-key-bindings.md @@ -0,0 +1,61 @@ +## `CTRL-T` + +### Preview + +You can preview the content of the file under the cursor by setting `--preview` option. + +```sh +# Using highlight (http://www.andre-simon.de/doku/highlight/en/highlight.html) +export FZF_CTRL_T_OPTS="--preview '(highlight -O ansi -l {} 2> /dev/null || cat {} || tree -C {}) 2> /dev/null | head -200'" +``` + +## `CTRL-R` + +### Sorting and exact matching + +Sort is disabled by default to respect chronological ordering. You dynamically toggle sorting by pressing `CTRL-R` again, but if you like to enable sorting by default you can add `--sort` to `FZF_CTRL_R_OPTS`. Also, if you prefer to use exact matching, add `--exact`. + +```sh +export FZF_CTRL_R_OPTS='--sort --exact' +``` + +### Preview + +Commands that are too long are not fully visible on screen. You can use `--preview` option to see the full command on the preview window. In the following example, we bind `?` key to toggle preview window. + +```sh +export FZF_CTRL_R_OPTS="--preview 'echo {}' --preview-window down:3:hidden --bind '?:toggle-preview'" +``` + +### Directly executing the command (CTRL-X CTRL-R) + +#### zsh + +```sh +fzf-history-widget-accept() { + fzf-history-widget + zle accept-line +} +zle -N fzf-history-widget-accept +bindkey '^X^R' fzf-history-widget-accept +``` + +#### bash + +```sh +bind "$(bind -s | grep '^"\\C-r"' | sed 's/"/"\\C-x/' | sed 's/"$/\\C-m"/')" +``` + +### Dynamically choose to execute or edit + +There is an open issue for this; [#477](https://github.com/junegunn/fzf/issues/477). We have a solution for zsh, but not for bash. + +## `ALT-C` + +### Preview + +Use `tree` command to show the content of the directory on the preview window. + +```sh +export FZF_ALT_C_OPTS="--preview 'tree -C {} | head -200'" +``` \ No newline at end of file