[bash] Populate emacs and vi keymaps (#1815)
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Enables the right bindings when switching between editing modes.
authored by Jack Bates · committed by Junegunn Choi · parent e21b001 · Browse files · 2 files·+43 added−49 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+43 added−49 removed
- other:+43 added−49 removed
Provenance
- Commit
82bf8c1- Tree
26ba3ae- Author
Jack Bates <jack@nottheoilrig.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
e21b001
2 files changed+43 added−49 removed
modified:shell/key-bindings.bash+43 added-45 removed
63 unmodified lines646566676869707168697071737475767778798081828384858672737475767788899091929394957879809798998182831011021031041051061071081091108485861121131148788899091929394951161171189697989910010110210310410510610710810911011111211311411511611711811963 unmodified lines sed 's/^ *\([0-9]*\)\** *//' <<< "$line" fi)
if [[ ! -o vi ]]; then # Required to refresh the prompt after fzf bind '"\er": redraw-current-line' bind '"\e^": history-expand-line'# Required to refresh the prompt after fzfbind -m emacs-standard '"\er": redraw-current-line'bind -m emacs-standard '"\e^": history-expand-line'
# CTRL-T - Paste the selected file path into the command line if [ $BASH_VERSINFO -gt 3 ]; then bind -x '"\C-t": "fzf-file-widget"' elif __fzf_use_tmux__; then bind '"\C-t": " \C-u \C-a\C-k`__fzf_select_tmux__`\e\C-e\C-y\C-a\C-d\C-y\ey\C-h"' else bind '"\C-t": " \C-u \C-a\C-k`__fzf_select__`\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er \C-h"' fi
# CTRL-R - Paste the selected command from history into the command line bind '"\C-r": " \C-e\C-u\C-y\ey\C-u`__fzf_history__`\e\C-e\er\e^"'
# ALT-C - cd into the selected directory bind '"\ec": " \C-e\C-u`__fzf_cd__`\e\C-e\er\C-m"'# CTRL-T - Paste the selected file path into the command lineif [ $BASH_VERSINFO -gt 3 ]; then bind -m emacs-standard -x '"\C-t": "fzf-file-widget"'elif __fzf_use_tmux__; then bind -m emacs-standard '"\C-t": " \C-u \C-a\C-k`__fzf_select_tmux__`\e\C-e\C-y\C-a\C-d\C-y\ey\C-h"'else # We'd usually use "\e" to enter vi-movement-mode so we can do our magic, # but this incurs a very noticeable delay of a half second or so, # because many other commands start with "\e". # Instead, we bind an unused key, "\C-x\C-a", # to also enter vi-movement-mode, # and then use that thereafter. # (We imagine that "\C-x\C-a" is relatively unlikely to be in use.) bind '"\C-x\C-a": vi-movement-mode' bind -m emacs-standard '"\C-t": " \C-u \C-a\C-k`__fzf_select__`\e\C-e\C-y\C-a\C-y\ey\C-h\C-e\er \C-h"'fi
bind '"\C-x\C-e": shell-expand-line' bind '"\C-x\C-r": redraw-current-line' bind '"\C-x^": history-expand-line'# CTRL-R - Paste the selected command from history into the command linebind -m emacs-standard '"\C-r": " \C-e\C-u\C-y\ey\C-u`__fzf_history__`\e\C-e\er\e^"'
# CTRL-T - Paste the selected file path into the command line # - FIXME: Selected items are attached to the end regardless of cursor position if [ $BASH_VERSINFO -gt 3 ]; then bind -x '"\C-t": "fzf-file-widget"' elif __fzf_use_tmux__; then bind '"\C-t": "\C-x\C-a$a \C-x\C-addi`__fzf_select_tmux__`\C-x\C-e\C-x\C-a0P$xa"' else bind '"\C-t": "\C-x\C-a$a \C-x\C-addi`__fzf_select__`\C-x\C-e\C-x\C-a0Px$a \C-x\C-r\C-x\C-axa "' fi bind -m vi-command '"\C-t": "i\C-t"'# ALT-C - cd into the selected directorybind -m emacs-standard '"\ec": " \C-e\C-u`__fzf_cd__`\e\C-e\er\C-m"'
# CTRL-R - Paste the selected command from history into the command line bind '"\C-r": "\C-x\C-addi`__fzf_history__`\C-x\C-e\C-x\C-r\C-x^\C-x\C-a$a"' bind -m vi-command '"\C-r": "i\C-r"'# We'd usually use "\e" to enter vi-movement-mode so we can do our magic,# but this incurs a very noticeable delay of a half second or so,# because many other commands start with "\e".# Instead, we bind an unused key, "\C-x\C-a",# to also enter vi-movement-mode,# and then use that thereafter.# (We imagine that "\C-x\C-a" is relatively unlikely to be in use.)bind -m vi-insert '"\C-x\C-a": vi-movement-mode'
# ALT-C - cd into the selected directory bind '"\ec": "\C-x\C-addi`__fzf_cd__`\C-x\C-e\C-x\C-r\C-m"' bind -m vi-command '"\ec": "ddi`__fzf_cd__`\C-x\C-e\C-x\C-r\C-m"'bind -m vi-insert '"\C-x\C-e": shell-expand-line'bind -m vi-insert '"\C-x\C-r": redraw-current-line'bind -m vi-insert '"\C-x^": history-expand-line'
# CTRL-T - Paste the selected file path into the command line# - FIXME: Selected items are attached to the end regardless of cursor positionif [ $BASH_VERSINFO -gt 3 ]; then bind -m vi-insert -x '"\C-t": "fzf-file-widget"'elif __fzf_use_tmux__; then bind -m vi-insert '"\C-t": "\C-x\C-a$a \C-x\C-addi`__fzf_select_tmux__`\C-x\C-e\C-x\C-a0P$xa"'else bind -m vi-insert '"\C-t": "\C-x\C-a$a \C-x\C-addi`__fzf_select__`\C-x\C-e\C-x\C-a0Px$a \C-x\C-r\C-x\C-axa "'fibind -m vi-command '"\C-t": "i\C-t"'
# CTRL-R - Paste the selected command from history into the command linebind -m vi-insert '"\C-r": "\C-x\C-addi`__fzf_history__`\C-x\C-e\C-x\C-r\C-x^\C-x\C-a$a"'bind -m vi-command '"\C-r": "i\C-r"'
# ALT-C - cd into the selected directorybind -m vi-insert '"\ec": "\C-x\C-addi`__fzf_cd__`\C-x\C-e\C-x\C-r\C-m"'bind -m vi-command '"\ec": "ddi`__fzf_cd__`\C-x\C-e\C-x\C-r\C-m"'
fimodified:README.md-4 removed
338 unmodified lines339 If you're on a tmux session, you can start fzf in a split pane by setting340 `FZF_TMUX` to 1, and change the height of the pane with `FZF_TMUX_HEIGHT`341 (e.g. `20`, `50%`).342 343-If you use vi mode on bash, you need to add `set -o vi` *before* `source344-~/.fzf.bash` in your .bashrc, so that it correctly sets up key bindings for vi345-mode.346-343 More tips can be found on [the wiki page](https://github.com/junegunn/fzf/wiki/Configuring-shell-key-bindings).344 345 Fuzzy completion for bash and zsh346 ---------------------------------258 unmodified lines