From e4a745d5fb78fc6ec0a085d4229204658d3fd921 Mon Sep 17 00:00:00 2001 From: surtur Date: Sat, 26 Mar 2022 01:20:55 +0100 Subject: [PATCH] zsh: add jeffreytse/zsh-vi-mode to be -- NORMAL -- add jeffreytse/zsh-vi-mode with sheldon. history substring search bindings are remapped to work with 'viins' and 'vicmd' (NORMAL) modes of the vi prompt, and J and K mappings in 'vicmd' mode are added. fzf loading also had to be reworked using system installation fzf completions are used. bindings for fzf are broken if loaded conventionally, therefore a helper function is offered by zsh-vi-mode to source anything after vi mode is initialized and it is used to source said completions. at this occasion FZF_COMPLETION_OPTS et al. have also been reworked a little to use dracula colorscheme, fd-find instead of find and bat to auto-colour files. --- .config/sheldon/plugins.toml | 3 +++ .zshrc | 23 ++++++++++++++++++++--- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.config/sheldon/plugins.toml b/.config/sheldon/plugins.toml index c8899bb..afbd84d 100644 --- a/.config/sheldon/plugins.toml +++ b/.config/sheldon/plugins.toml @@ -16,3 +16,6 @@ github = 'djui/alias-tips' [plugins.fast-syntax-highlighting] github = 'zdharma-continuum/fast-syntax-highlighting' + +[plugins.zsh-vi-mode] +github = 'jeffreytse/zsh-vi-mode' diff --git a/.zshrc b/.zshrc index bea1348..9bc80d4 100644 --- a/.zshrc +++ b/.zshrc @@ -63,7 +63,7 @@ # Would you like to use another custom folder than $ZSH/custom? # ZSH_CUSTOM=/path/to/new-custom-folder - plugins=(asdf fzf git gitignore golang safe-paste systemd terraform lol) + plugins=(asdf git gitignore golang safe-paste systemd terraform lol) source $ZSH/oh-my-zsh.sh ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor) @@ -78,11 +78,28 @@ # map arrow up/down to control fish-like history substring search and highlighting bindkey '^[[A' history-substring-search-up bindkey '^[[B' history-substring-search-down + # also map the same keys in 'viins' (INSERT) mode... + bindkey -M viins '^[[A' history-substring-search-up + bindkey -M viins '^[[B' history-substring-search-down + # ...and in 'vicmd' (NORMAL) mode... + bindkey -M vicmd '^[[A' history-substring-search-up + bindkey -M vicmd '^[[B' history-substring-search-down + # ...and as well to K, J, instead of arrow up/down, respectively. + # note these are capital letters, original behaviour of j, k is left unchanged + bindkey -M vicmd 'K' history-substring-search-up + bindkey -M vicmd 'J' history-substring-search-down HISTORY_SUBSTRING_SEARCH_FUZZY=" " + export FZF_DEFAULT_COMMAND="fd --type f --hidden --follow --exclude .git --exclude 'node_modules' ." + export FZF_CTRL_T_COMMAND="fd --follow --full-path --base-directory . --exclude '.git' --exclude 'node_modules' ." + export FZF_ALT_C_COMMAND="fd -H -t d ." + export DISABLE_FZF_AUTO_COMPLETION="true" # Options to fzf command - FZF_COMPLETION_OPTS='+c -x' - FZF_DEFAULT_OPTS="--height=60% --inline-info --color=fg:#f8f8f2,bg:#282a36,hl:#bd93f9 --color=fg+:#f8f8f2,bg+:#44475a,hl+:#bd93f9 --color=info:#ffb86c,prompt:#50fa7b,pointer:#ff79c6 --color=marker:#ff79c6,spinner:#ffb86c,header:#6272a4" + export FZF_COMPLETION_OPTS='+c -x' + export FZF_DEFAULT_OPTS="--height=60% --inline-info --color=fg:#f8f8f2,bg:#282a36,hl:#bd93f9 --color=fg+:#f8f8f2,bg+:#44475a,hl+:#bd93f9 --color=info:#ffb86c,prompt:#50fa7b,pointer:#ff79c6 --color=marker:#ff79c6,spinner:#ffb86c,header:#6272a4" + export FZF_CTRL_T_OPTS="--preview 'bat --style=numbers --color=always --line-range :200 {}'" + + zvm_after_init_commands+=('[ -f /usr/share/fzf/shell/key-bindings.zsh ] && source /usr/share/fzf/shell/key-bindings.zsh') # User configuration source ~/.dotenv