diff --git a/config/nix/hm/common.nix b/config/nix/hm/common.nix index 5d54b07..3dacf87 100644 --- a/config/nix/hm/common.nix +++ b/config/nix/hm/common.nix @@ -11,13 +11,8 @@ enableSyntaxHighlighting = true; # syntaxHighlighting.enable = true; # 23.11 syntax historySubstringSearch.enable = true; - initExtra = '' - # powerline-go duration support - zmodload zsh/datetime - function preexec() { - __TIMER=$EPOCHREALTIME - } - ''; + initExtra = builtins.readFile ./zshrc.sh; + defaultKeymap = "viins"; }; powerline-go = { enable = true; @@ -73,6 +68,10 @@ }; fzf.enable = true; # TODO highlight or bat + nix-index = { + enable = true; + enableZshIntegration = true; + }; }; home = { stateVersion = "23.05"; diff --git a/config/nix/hm/zshrc.sh b/config/nix/hm/zshrc.sh new file mode 100644 index 0000000..0e5bda3 --- /dev/null +++ b/config/nix/hm/zshrc.sh @@ -0,0 +1,42 @@ +# powerline-go duration support +zmodload zsh/datetime +function preexec() { + __TIMER=$EPOCHREALTIME +} + +# Cursor based on mode +if [ $TERM = "linux" ]; then + _LINE_CURSOR="\e[?0c" + _BLOCK_CURSOR="\e[?8c" +else + _LINE_CURSOR="\e[6 q" + _BLOCK_CURSOR="\e[2 q" +fi +function zle-keymap-select zle-line-init +{ + case $KEYMAP in + vicmd) print -n -- "$_BLOCK_CURSOR";; + viins|main) print -n -- "$_LINE_CURSOR";; + esac +} +function zle-line-finish +{ + print -n -- "$_BLOCK_CURSOR" +} +zle -N zle-line-init +zle -N zle-line-finish +zle -N zle-keymap-select + +# Also return to normal mode from jk shortcut +bindkey 'jk' vi-cmd-mode + +# Edit command line +autoload edit-command-line +zle -N edit-command-line +bindkey -M vicmd v edit-command-line + +# Additional history-substring-search bindings for vi cmd mode +# TODO Doesn't work, as home-manager loads history-substring at the very end of the file +# bindkey -M vicmd 'k' history-substring-search-up +# bindkey -M vicmd 'j' history-substring-search-down + diff --git a/config/shell/zshrc b/config/shell/zshrc index 96c7e31..faf0f50 100644 --- a/config/shell/zshrc +++ b/config/shell/zshrc @@ -7,61 +7,6 @@ # TODO Learn `setopt extendedglob` -# Cursor based on mode -if [ $TERM = "linux" ]; then - _LINE_CURSOR="\e[?0c" - _BLOCK_CURSOR="\e[?8c" -else - _LINE_CURSOR="\e[6 q" - _BLOCK_CURSOR="\e[2 q" -fi -function zle-keymap-select zle-line-init -{ - case $KEYMAP in - vicmd) print -n -- "$_BLOCK_CURSOR";; - viins|main) print -n -- "$_LINE_CURSOR";; - esac - - # zle reset-prompt - # zle -R -} - -function zle-line-finish -{ - print -n -- "$_BLOCK_CURSOR" -} - -zle -N zle-line-init -zle -N zle-line-finish -zle -N zle-keymap-select - -# Should I really put a comment to explain what this does? -bindkey 'jk' vi-cmd-mode - -# Edit command line -autoload edit-command-line -zle -N edit-command-line -bindkey -M vicmd v edit-command-line - -# History search -# bind UP and DOWN arrow keys -zmodload zsh/terminfo -bindkey "$terminfo[kcuu1]" history-substring-search-up -bindkey "$terminfo[kcud1]" history-substring-search-down - -# bind UP and DOWN arrow keys (compatibility fallback -# for Ubuntu 12.04, Fedora 21, and MacOSX 10.9 users) -bindkey '^[[A' history-substring-search-up -bindkey '^[[B' history-substring-search-down - -# bind P and N for EMACS mode -bindkey -M emacs '^P' history-substring-search-up -bindkey -M emacs '^N' history-substring-search-down - -# bind k and j for VI mode -bindkey -M vicmd 'k' history-substring-search-up -bindkey -M vicmd 'j' history-substring-search-down - # Autocompletion autoload -Uz promptinit promptinit