about summary refs log tree commit diff stats
path: root/modules/by-name/zs/zsh/config
diff options
context:
space:
mode:
Diffstat (limited to 'modules/by-name/zs/zsh/config')
-rw-r--r--modules/by-name/zs/zsh/config/command_not_found/command_not_found.sh (renamed from modules/by-name/zs/zsh/config/command_not_found.sh)0
-rw-r--r--modules/by-name/zs/zsh/config/command_not_found/command_not_found_insult.sh (renamed from modules/by-name/zs/zsh/config/command_not_found_insult.sh)0
-rw-r--r--modules/by-name/zs/zsh/config/custom_cursor.zsh81
-rw-r--r--modules/by-name/zs/zsh/config/edit_command_line.zsh25
-rw-r--r--modules/by-name/zs/zsh/config/keymaps/.safe.zsh5
-rw-r--r--modules/by-name/zs/zsh/config/keymaps/command.zsh6
-rw-r--r--modules/by-name/zs/zsh/config/keymaps/emacs.zsh119
-rw-r--r--modules/by-name/zs/zsh/config/keymaps/isearch.zsh2
-rw-r--r--modules/by-name/zs/zsh/config/keymaps/vicmd.zsh156
-rw-r--r--modules/by-name/zs/zsh/config/keymaps/viins.zsh55
-rw-r--r--modules/by-name/zs/zsh/config/keymaps/viopp.zsh45
-rw-r--r--modules/by-name/zs/zsh/config/keymaps/visual.zsh53
-rw-r--r--modules/by-name/zs/zsh/config/keymaps_end.zsh2
-rw-r--r--modules/by-name/zs/zsh/config/keymaps_start.zsh16
-rw-r--r--modules/by-name/zs/zsh/config/zsh-init.zsh37
15 files changed, 532 insertions, 70 deletions
diff --git a/modules/by-name/zs/zsh/config/command_not_found.sh b/modules/by-name/zs/zsh/config/command_not_found/command_not_found.sh
index fb21b676..fb21b676 100644
--- a/modules/by-name/zs/zsh/config/command_not_found.sh
+++ b/modules/by-name/zs/zsh/config/command_not_found/command_not_found.sh
diff --git a/modules/by-name/zs/zsh/config/command_not_found_insult.sh b/modules/by-name/zs/zsh/config/command_not_found/command_not_found_insult.sh
index 5126845a..5126845a 100644
--- a/modules/by-name/zs/zsh/config/command_not_found_insult.sh
+++ b/modules/by-name/zs/zsh/config/command_not_found/command_not_found_insult.sh
diff --git a/modules/by-name/zs/zsh/config/custom_cursor.zsh b/modules/by-name/zs/zsh/config/custom_cursor.zsh
index 37390c1c..071bb5fe 100644
--- a/modules/by-name/zs/zsh/config/custom_cursor.zsh
+++ b/modules/by-name/zs/zsh/config/custom_cursor.zsh
@@ -1,42 +1,53 @@
 #!/usr/bin/env zsh
 
-# Change cursor shape for different vi modes.
-function zle-keymap-select {
-  if [[ ${KEYMAP} == vicmd ]] ||
-     [[ $1 = 'block' ]]; then
-    echo -ne '\e[1 q'
-  elif [[ ${KEYMAP} == main ]] ||
-       [[ ${KEYMAP} == viins ]] ||
-       [[ ${KEYMAP} = '' ]] ||
-       [[ $1 = 'beam' ]]; then
-    echo -ne '\e[5 q'
-  fi
-}
-zle -N zle-keymap-select
+autoload -U add-zsh-hook
+autoload -U add-zle-hook-widget
+
+_cursor_beam()  { echo -ne "\\033[5 q" }
+_cursor_block() { echo -ne "\\033[1 q" }
 
-# ci", ci', ci`, di", etc
-autoload -U select-quoted
-zle -N select-quoted
-for m in visual viopp; do
-  for c in {a,i}{\',\",\`}; do
-    bindkey -M "$m" "$c" select-quoted
-  done
-done
+# Change cursor shape for different vi modes.
+# From `ZSHZLE (1)`:
+# > Executed every time the keymap changes, i.e. the special parameter KEYMAP is set to a different value,
+# > while the line editor is active.  Initialising the keymap when the line  editor  starts  does
+# > not cause the widget to be called.
+# >
+# > The value $KEYMAP within the function reflects the new keymap.  The old keymap is passed as the sole argument.
+# >
+# > This can be used for detecting switches between the vi command (vicmd) and insert (usually main) keymaps.
+_cursor_zle-keymap-select() {
+    : keymap select
 
-# ci{, ci(, ci<, di{, etc
-autoload -U select-bracketed
-zle -N select-bracketed
-for m in visual viopp; do
-  for c in {a,i}${(s..)^:-'()[]{}<>bB'}; do
-    bindkey -M $m $c select-bracketed
-  done
-done
+    case "$KEYMAP" in
+    "vicmd" | "block")
+        _cursor_block
+        ;;
+    "main" | "viins" | "" | "beam")
+        _cursor_beam
+        ;;
+    esac
+}
+add-zle-hook-widget keymap-select _cursor_zle-keymap-select
 
-zle-line-init() {
-    zle -K viins # initiate `vi insert` as keymap (can be removed if `bindkey -V` has been set elsewhere)
-    echo -ne "\e[5 q"
+# From `ZSHZLE(1)`:
+# > Executed every time the line editor is started to read a new line of input.
+# > The following example puts the line editor into vi command mode when it starts up.
+# >
+# >        zle-line-init() { zle -K vicmd; }
+# >        zle -N zle-line-init
+# >
+# > (The command inside the function sets the keymap directly; it is equivalent to zle vi-cmd-mode.)
+_cursor_zle-line-init() {
+    : zle line init
+    _cursor_beam
+}
+# > This is similar to zle-line-init but is executed every time the line editor has finished reading a line of input.
+_cursor_zle-line-finish() {
+    : zle line finish
+    _cursor_block
 }
-zle -N zle-line-init
+add-zle-hook-widget line-init _cursor_zle-line-init
+add-zle-hook-widget line-finish _cursor_zle-line-finish
 
-echo -ne '\e[5 q' # Use beam shape cursor on startup.
-precmd() { echo -ne '\e[5 q' ;} # Use beam shape cursor for each new prompt.
+# Use beam shape cursor on startup.
+_cursor_beam
diff --git a/modules/by-name/zs/zsh/config/edit_command_line.zsh b/modules/by-name/zs/zsh/config/edit_command_line.zsh
new file mode 100644
index 00000000..1d51a4e8
--- /dev/null
+++ b/modules/by-name/zs/zsh/config/edit_command_line.zsh
@@ -0,0 +1,25 @@
+#! /usr/bin/env zsh
+
+autoload -Uz edit-command-line
+
+wrapped_edit-command-line() {
+    # This overrides a print implementation in my shell lib
+    print() {
+        # FIXME: `print` is called in the following way from `edit-command-line`
+        # (from: https://raw.githubusercontent.com/zsh-users/zsh/refs/heads/master/Functions/Zle/edit-command-line):
+        #   ```
+        #   (( $+zle_bracketed_paste )) && print -r -n - $zle_bracketed_paste[1]
+        #   ```
+        # This results in the error, that the `-r|-n` arguments are mutually exclusive with
+        # the `-` arg. I'm sure, that this is not a bug (as it's been in there for quite
+        # some time now), and ignoring it just seems to work.
+        # But I should either really fix this or find a explanation *why* they are doing
+        # it. <2024-10-21>
+        builtin print "$*" 2>/dev/null
+    }
+
+    # Execute the original `edit-command-line`
+    edit-command-line
+}
+
+zle -N edit-command-line wrapped_edit-command-line
diff --git a/modules/by-name/zs/zsh/config/keymaps/.safe.zsh b/modules/by-name/zs/zsh/config/keymaps/.safe.zsh
new file mode 100644
index 00000000..ee3bfa32
--- /dev/null
+++ b/modules/by-name/zs/zsh/config/keymaps/.safe.zsh
@@ -0,0 +1,5 @@
+bindkey -M .safe "^J" .accept-line
+bindkey -M .safe "^M" .accept-line
+bindkey -R -M .safe "^@"-"^I" .self-insert
+bindkey -R -M .safe "^K"-"^L" .self-insert
+bindkey -R -M .safe "^N"-"\M-^?" .self-insert
diff --git a/modules/by-name/zs/zsh/config/keymaps/command.zsh b/modules/by-name/zs/zsh/config/keymaps/command.zsh
new file mode 100644
index 00000000..81ae6dda
--- /dev/null
+++ b/modules/by-name/zs/zsh/config/keymaps/command.zsh
@@ -0,0 +1,6 @@
+# Keymap used in the vicmd `execute-named-cmd` mode
+bindkey -N command
+
+bindkey -M command "^J" accept-line
+bindkey -M command "^M" accept-line
+bindkey -M command "^G" send-break
diff --git a/modules/by-name/zs/zsh/config/keymaps/emacs.zsh b/modules/by-name/zs/zsh/config/keymaps/emacs.zsh
new file mode 100644
index 00000000..b789faf5
--- /dev/null
+++ b/modules/by-name/zs/zsh/config/keymaps/emacs.zsh
@@ -0,0 +1,119 @@
+bindkey -N emacs
+
+bindkey -M emacs "^[A" accept-and-hold
+bindkey -M emacs "^[a" accept-and-hold
+bindkey -M emacs "^J" accept-line
+bindkey -M emacs "^M" accept-line
+bindkey -M emacs "^O" accept-line-and-down-history
+bindkey -M emacs "^R" atuin-search
+bindkey -M emacs "^[OA" atuin-up-search
+bindkey -M emacs "^[[A" atuin-up-search
+bindkey -M emacs "^B" backward-char
+bindkey -M emacs "^[OD" backward-char
+bindkey -M emacs "^[[D" backward-char
+bindkey -M emacs "^?" backward-delete-char
+bindkey -M emacs "^H" backward-delete-char
+bindkey -M emacs "^W" backward-kill-word
+bindkey -M emacs "^[^?" backward-kill-word
+bindkey -M emacs "^[^H" backward-kill-word
+bindkey -M emacs "^[B" backward-word
+bindkey -M emacs "^[b" backward-word
+bindkey -M emacs "^[<" beginning-of-buffer-or-history
+bindkey -M emacs "^A" beginning-of-line
+bindkey -M emacs "^[[200~" bracketed-paste
+bindkey -M emacs "^[C" capitalize-word
+bindkey -M emacs "^L" clear-screen
+bindkey -M emacs "^[^L" clear-screen
+bindkey -M emacs "^[^_" copy-prev-word
+bindkey -M emacs "^[W" copy-region-as-kill
+bindkey -M emacs "^[w" copy-region-as-kill
+bindkey -M emacs "^D" delete-char-or-list
+bindkey -M emacs "^[0" digit-argument
+bindkey -M emacs "^[1" digit-argument
+bindkey -M emacs "^[2" digit-argument
+bindkey -M emacs "^[3" digit-argument
+bindkey -M emacs "^[4" digit-argument
+bindkey -M emacs "^[5" digit-argument
+bindkey -M emacs "^[6" digit-argument
+bindkey -M emacs "^[7" digit-argument
+bindkey -M emacs "^[8" digit-argument
+bindkey -M emacs "^[9" digit-argument
+bindkey -M emacs "^[L" down-case-word
+bindkey -M emacs "^[l" down-case-word
+bindkey -M emacs "^N" down-line-or-history
+bindkey -M emacs "^[OB" down-line-or-history
+bindkey -M emacs "^[[B" down-line-or-history
+bindkey -M emacs "^[>" end-of-buffer-or-history
+bindkey -M emacs "^E" end-of-line
+bindkey -M emacs "^X^X" exchange-point-and-mark
+bindkey -M emacs "^[z" execute-last-named-cmd
+bindkey -M emacs "^[x" execute-named-cmd
+bindkey -M emacs "^[ " expand-history
+bindkey -M emacs "^[!" expand-history
+bindkey -M emacs "^I" expand-or-complete
+bindkey -M emacs "^X*" expand-word
+bindkey -M emacs "^F" forward-char
+bindkey -M emacs "^[OC" forward-char
+bindkey -M emacs "^[[C" forward-char
+bindkey -M emacs "^[F" forward-word
+bindkey -M emacs "^[f" forward-word
+bindkey -M emacs "^[c" fzf-cd-widget
+bindkey -M emacs "^T" fzf-file-widget
+bindkey -M emacs "^[G" get-line
+bindkey -M emacs "^[g" get-line
+bindkey -M emacs "^Xr" history-incremental-search-backward
+bindkey -M emacs "^S" history-incremental-search-forward
+bindkey -M emacs "^Xs" history-incremental-search-forward
+bindkey -M emacs "^[P" history-search-backward
+bindkey -M emacs "^[p" history-search-backward
+bindkey -M emacs "^[N" history-search-forward
+bindkey -M emacs "^[n" history-search-forward
+bindkey -M emacs "^X^N" infer-next-history
+bindkey -M emacs "^[." insert-last-word
+bindkey -M emacs "^[_" insert-last-word
+bindkey -M emacs "^X^K" kill-buffer
+bindkey -M emacs "^K" kill-line
+bindkey -M emacs "^U" kill-whole-line
+bindkey -M emacs "^[D" kill-word
+bindkey -M emacs "^[d" kill-word
+bindkey -M emacs "^[^D" list-choices
+bindkey -M emacs "^XG" list-expand
+bindkey -M emacs "^Xg" list-expand
+bindkey -M emacs "^[-" neg-argument
+bindkey -M emacs "^X^O" overwrite-mode
+bindkey -M emacs "^Q" push-line
+bindkey -M emacs "^[Q" push-line
+bindkey -M emacs "^[q" push-line
+bindkey -M emacs "^['" quote-line
+bindkey -M emacs "^[\"" quote-region
+bindkey -M emacs "^V" quoted-insert
+bindkey -M emacs "^[H" run-help
+bindkey -M emacs "^[h" run-help
+bindkey -R -M emacs " "-"~" self-insert
+bindkey -R -M emacs "\M-^@"-"\M-^?" self-insert
+bindkey -M emacs "^[^I" self-insert-unmeta
+bindkey -M emacs "^[^J" self-insert-unmeta
+bindkey -M emacs "^[^M" self-insert-unmeta
+bindkey -M emacs "^G" send-break
+bindkey -M emacs "^[^G" send-break
+bindkey -M emacs "^@" set-mark-command
+bindkey -M emacs "^[S" spell-word
+bindkey -M emacs "^[\$" spell-word
+bindkey -M emacs "^[s" spell-word
+bindkey -M emacs "^[T" transpose-words
+bindkey -M emacs "^[t" transpose-words
+bindkey -M emacs "^X^U" undo
+bindkey -M emacs "^Xu" undo
+bindkey -M emacs "^_" undo
+bindkey -M emacs "^[U" up-case-word
+bindkey -M emacs "^[u" up-case-word
+bindkey -M emacs "^P" up-line-or-history
+bindkey -M emacs "^X^V" vi-cmd-mode
+bindkey -M emacs "^X^F" vi-find-next-char
+bindkey -M emacs "^[|" vi-goto-column
+bindkey -M emacs "^X^J" vi-join
+bindkey -M emacs "^X^B" vi-match-bracket
+bindkey -M emacs "^X=" what-cursor-position
+bindkey -M emacs "^[?" which-command
+bindkey -M emacs "^Y" yank
+bindkey -M emacs "^[y" yank-pop
diff --git a/modules/by-name/zs/zsh/config/keymaps/isearch.zsh b/modules/by-name/zs/zsh/config/keymaps/isearch.zsh
new file mode 100644
index 00000000..db80bae8
--- /dev/null
+++ b/modules/by-name/zs/zsh/config/keymaps/isearch.zsh
@@ -0,0 +1,2 @@
+# Nothing?
+bindkey -N isearch
diff --git a/modules/by-name/zs/zsh/config/keymaps/vicmd.zsh b/modules/by-name/zs/zsh/config/keymaps/vicmd.zsh
new file mode 100644
index 00000000..ceb4f348
--- /dev/null
+++ b/modules/by-name/zs/zsh/config/keymaps/vicmd.zsh
@@ -0,0 +1,156 @@
+bindkey -N vicmd
+
+# Bind in string to out string
+bindkey -s -M vicmd "gUU" "gUgU"
+bindkey -s -M vicmd "guu" "gugu"
+bindkey -s -M vicmd "g~~" "g~g~"
+
+# Movement
+bindkey -M vicmd "h" vi-backward-char
+bindkey -M vicmd "t" history-substring-search-down
+bindkey -M vicmd "n" history-substring-search-up
+bindkey -M vicmd "s" vi-forward-char
+
+# Search history
+bindkey -M vicmd "/" atuin-up-search-vicmd
+bindkey -M vicmd "?" atuin-down-search-vicmd
+bindkey -M vicmd "l" vi-repeat-search
+bindkey -M vicmd "L" vi-rev-repeat-search
+
+bindkey -M vicmd "f" vi-find-next-char
+bindkey -M vicmd "F" vi-find-prev-char
+
+# Tell the user that more ESC is not possible
+bindkey -M vicmd "^[" beep
+
+
+# > Fetch the history line specified by the numeric argument.
+# > This defaults to the current history line (i.e. the one that isn't history yet).
+bindkey -M vicmd "G" vi-fetch-history
+bindkey -M vicmd "gg" beginning-of-buffer-or-history
+
+bindkey -M vicmd -R "1"-"9" digit-argument
+
+bindkey -M vicmd "^L" clear-screen
+
+bindkey -M vicmd ":" execute-named-cmd
+
+bindkey -M vicmd "=" list-choices
+
+bindkey -M vicmd "^V" vi-quoted-insert
+
+bindkey -M vicmd "#" vi-pound-insert
+bindkey -M vicmd "u" undo
+
+
+bindkey -M vicmd "A" vi-add-eol
+bindkey -M vicmd "i" vi-insert
+bindkey -M vicmd "a" vi-add-next
+bindkey -M vicmd "I" vi-insert-bol
+bindkey -M vicmd "O" vi-open-line-above
+bindkey -M vicmd "o" vi-open-line-below
+
+bindkey -M vicmd "c" vi-change
+bindkey -M vicmd "C" vi-change-eol
+bindkey -M vicmd "S" vi-change-whole-line
+
+
+bindkey -M vicmd "b" vi-backward-word
+bindkey -M vicmd "ge" vi-backward-word-end
+bindkey -M vicmd "B" vi-backward-blank-word
+bindkey -M vicmd "gE" vi-backward-blank-word-end
+
+bindkey -M vicmd "w" vi-forward-word
+bindkey -M vicmd "e" vi-forward-word-end
+bindkey -M vicmd "W" vi-forward-blank-word
+bindkey -M vicmd "E" vi-forward-blank-word-end
+
+
+bindkey -M vicmd "x" vi-delete-char
+bindkey -M vicmd "X" vi-backward-delete-char
+bindkey -M vicmd "d" vi-delete
+bindkey -M vicmd "D" vi-kill-eol
+
+bindkey -M vicmd "y" vi-yank
+bindkey -M vicmd "Y" vi-yank-whole-line
+bindkey -M vicmd "p" vi-put-after
+bindkey -M vicmd "P" vi-put-before
+
+
+bindkey -M vicmd "~" vi-swap-case
+bindkey -M vicmd "g~" vi-oper-swap-case
+bindkey -M vicmd "gU" vi-up-case
+bindkey -M vicmd "gu" vi-down-case
+
+
+bindkey -M vicmd "\^" vi-first-non-blank
+bindkey -M vicmd "\$" vi-end-of-line
+bindkey -M vicmd "0" vi-digit-or-beginning-of-line
+
+bindkey -M vicmd "|" vi-goto-column
+bindkey -M vicmd "\`" vi-goto-mark
+bindkey -M vicmd "'" vi-goto-mark-line
+
+
+bindkey -M vicmd ">" vi-indent
+bindkey -M vicmd "<" vi-unindent
+
+
+bindkey -M vicmd "%" vi-match-bracket
+
+
+bindkey -M vicmd "." vi-repeat-change
+bindkey -M vicmd ";" vi-repeat-find
+bindkey -M vicmd "," vi-rev-repeat-find
+
+
+bindkey -M vicmd "R" vi-replace
+bindkey -M vicmd "r" vi-replace-chars
+# bindkey -M vicmd "s" vi-substitute
+
+
+bindkey -M vicmd "\"" vi-set-buffer
+bindkey -M vicmd "m" vi-set-mark
+
+
+bindkey -M vicmd "ga" what-cursor-position
+
+bindkey -M vicmd "V" visual-line-mode
+bindkey -M vicmd "v" visual-mode
+
+# Selection
+bindkey -M vicmd "aW" select-a-blank-word
+bindkey -M vicmd "aa" select-a-shell-word
+bindkey -M vicmd "aw" select-a-word
+bindkey -M vicmd "iW" select-in-blank-word
+bindkey -M vicmd "ia" select-in-shell-word
+bindkey -M vicmd "iw" select-in-word
+bindkey -M vicmd "a(" select-bracketed
+bindkey -M vicmd "a)" select-bracketed
+bindkey -M vicmd "a<" select-bracketed
+bindkey -M vicmd "a>" select-bracketed
+bindkey -M vicmd "aB" select-bracketed
+bindkey -M vicmd "a[" select-bracketed
+bindkey -M vicmd "a]" select-bracketed
+bindkey -M vicmd "ab" select-bracketed
+bindkey -M vicmd "a{" select-bracketed
+bindkey -M vicmd "a}" select-bracketed
+bindkey -M vicmd "i(" select-bracketed
+bindkey -M vicmd "i)" select-bracketed
+bindkey -M vicmd "i<" select-bracketed
+bindkey -M vicmd "i>" select-bracketed
+bindkey -M vicmd "iB" select-bracketed
+bindkey -M vicmd "i[" select-bracketed
+bindkey -M vicmd "i]" select-bracketed
+bindkey -M vicmd "ib" select-bracketed
+bindkey -M vicmd "i{" select-bracketed
+bindkey -M vicmd "i}" select-bracketed
+bindkey -M vicmd "a'" select-quoted
+bindkey -M vicmd "a\"" select-quoted
+bindkey -M vicmd "a\`" select-quoted
+bindkey -M vicmd "i'" select-quoted
+bindkey -M vicmd "i\"" select-quoted
+bindkey -M vicmd "i\`" select-quoted
+
+# Support pasted text
+bindkey -M vicmd "^[[200~" bracketed-paste
diff --git a/modules/by-name/zs/zsh/config/keymaps/viins.zsh b/modules/by-name/zs/zsh/config/keymaps/viins.zsh
new file mode 100644
index 00000000..4e76cdec
--- /dev/null
+++ b/modules/by-name/zs/zsh/config/keymaps/viins.zsh
@@ -0,0 +1,55 @@
+bindkey -N viins
+
+# Completion Debugging
+bindkey -M viins "^[~" _bash_complete-word
+bindkey -M viins "^X~" _bash_list-choices
+bindkey -M viins "^X?" _complete_debug
+bindkey -M viins "^Xh" _complete_help
+bindkey -M viins "^Xt" _complete_tag
+bindkey -M viins "^XC" _correct_filename
+bindkey -M viins "^Xc" _correct_word
+bindkey -M viins "^Xa" _expand_alias
+bindkey -M viins "^Xe" _expand_word
+bindkey -M viins "^Xd" _list_expansions
+bindkey -M viins "^Xm" _most_recent_file
+bindkey -M viins "^Xn" _next_tags
+bindkey -M viins "^X^R" _read_comp
+bindkey -M viins "^[," _history-complete-newer
+bindkey -M viins "^[/" _history-complete-older
+
+bindkey -M viins "^J" accept-line
+bindkey -M viins "^M" accept-line
+bindkey -M viins "^L" clear-screen
+
+bindkey -M viins "^R" atuin-search-viins
+bindkey -M viins "^V" edit-command-line
+
+bindkey -M viins "^[[A" history-substring-search-up   # UP ARROW
+bindkey -M viins "^[OA" history-substring-search-up   # UP ARROW
+bindkey -M viins "^[[B" history-substring-search-down # DOWN ARROW
+bindkey -M viins "^[OB" history-substring-search-down # DOWN ARROW
+
+bindkey -M viins "^[[C" beep # RIGHT ARROW
+bindkey -M viins "^[OC" beep # RIGHT ARROW
+bindkey -M viins "^[[D" beep # LEFT ARROW
+bindkey -M viins "^[OD" beep # LEFT ARROW
+
+# Self inserts
+bindkey -M viins "^K" self-insert
+bindkey -M viins "^S" self-insert
+bindkey -R -M viins "\M-^@"-"\M-^?" self-insert
+bindkey -R -M viins "^A"-"^C" self-insert
+bindkey -R -M viins "^E"-"^F" self-insert
+bindkey -R -M viins "^N"-"^P" self-insert
+bindkey -R -M viins "^Y"-"^Z" self-insert
+bindkey -R -M viins "^\\\\"-"~" self-insert
+
+bindkey -M viins "^[" vi-cmd-mode # ESC
+
+# Support pasted text (and other terminal stuff)
+bindkey -M viins "^[[200~" bracketed-paste
+bindkey -M viins "^[[2~" overwrite-mode
+bindkey -M viins "^[[3~" delete-char
+bindkey -M viins "^?" vi-backward-delete-char
+bindkey -M viins "^[[5~" beginning-of-buffer-or-history
+bindkey -M viins "^[[6~" end-of-buffer-or-history
diff --git a/modules/by-name/zs/zsh/config/keymaps/viopp.zsh b/modules/by-name/zs/zsh/config/keymaps/viopp.zsh
new file mode 100644
index 00000000..8b291d00
--- /dev/null
+++ b/modules/by-name/zs/zsh/config/keymaps/viopp.zsh
@@ -0,0 +1,45 @@
+bindkey -N viopp
+
+bindkey -M viopp "t" down-line
+bindkey -M viopp "n" up-line
+
+bindkey -M viopp "^[" vi-cmd-mode
+
+
+bindkey -M viopp "aW" select-a-blank-word
+bindkey -M viopp "aa" select-a-shell-word
+bindkey -M viopp "aw" select-a-word
+
+bindkey -M viopp "iW" select-in-blank-word
+bindkey -M viopp "ia" select-in-shell-word
+bindkey -M viopp "iw" select-in-word
+
+
+bindkey -M viopp "a(" select-bracketed
+bindkey -M viopp "a)" select-bracketed
+bindkey -M viopp "a<" select-bracketed
+bindkey -M viopp "a>" select-bracketed
+bindkey -M viopp "aB" select-bracketed
+bindkey -M viopp "a[" select-bracketed
+bindkey -M viopp "a]" select-bracketed
+bindkey -M viopp "ab" select-bracketed
+bindkey -M viopp "a{" select-bracketed
+bindkey -M viopp "a}" select-bracketed
+bindkey -M viopp "i(" select-bracketed
+bindkey -M viopp "i)" select-bracketed
+bindkey -M viopp "i<" select-bracketed
+bindkey -M viopp "i>" select-bracketed
+bindkey -M viopp "iB" select-bracketed
+bindkey -M viopp "i[" select-bracketed
+bindkey -M viopp "i]" select-bracketed
+bindkey -M viopp "ib" select-bracketed
+bindkey -M viopp "i{" select-bracketed
+bindkey -M viopp "i}" select-bracketed
+
+bindkey -M viopp "a'" select-quoted
+bindkey -M viopp "a\"" select-quoted
+bindkey -M viopp "a\`" select-quoted
+bindkey -M viopp "i'" select-quoted
+bindkey -M viopp "i\"" select-quoted
+bindkey -M viopp "i\`" select-quoted
+
diff --git a/modules/by-name/zs/zsh/config/keymaps/visual.zsh b/modules/by-name/zs/zsh/config/keymaps/visual.zsh
new file mode 100644
index 00000000..c09cd578
--- /dev/null
+++ b/modules/by-name/zs/zsh/config/keymaps/visual.zsh
@@ -0,0 +1,53 @@
+bindkey -N visual
+
+bindkey -M visual "^[" deactivate-region
+
+bindkey -M visual "t" down-line
+bindkey -M visual "n" up-line
+
+bindkey -M visual "o" exchange-point-and-mark
+bindkey -M visual "p" put-replace-selection
+
+
+bindkey -M visual "x" vi-delete
+bindkey -M visual "u" vi-down-case
+bindkey -M visual "~" vi-oper-swap-case
+bindkey -M visual "U" vi-up-case
+
+
+bindkey -M visual "aW" select-a-blank-word
+bindkey -M visual "aa" select-a-shell-word
+bindkey -M visual "aw" select-a-word
+
+bindkey -M visual "iW" select-in-blank-word
+bindkey -M visual "ia" select-in-shell-word
+bindkey -M visual "iw" select-in-word
+
+
+bindkey -M visual "a(" select-bracketed
+bindkey -M visual "a)" select-bracketed
+bindkey -M visual "a<" select-bracketed
+bindkey -M visual "a>" select-bracketed
+bindkey -M visual "aB" select-bracketed
+bindkey -M visual "a[" select-bracketed
+bindkey -M visual "a]" select-bracketed
+bindkey -M visual "ab" select-bracketed
+bindkey -M visual "a{" select-bracketed
+bindkey -M visual "a}" select-bracketed
+bindkey -M visual "i(" select-bracketed
+bindkey -M visual "i)" select-bracketed
+bindkey -M visual "i<" select-bracketed
+bindkey -M visual "i>" select-bracketed
+bindkey -M visual "iB" select-bracketed
+bindkey -M visual "i[" select-bracketed
+bindkey -M visual "i]" select-bracketed
+bindkey -M visual "ib" select-bracketed
+bindkey -M visual "i{" select-bracketed
+bindkey -M visual "i}" select-bracketed
+
+bindkey -M visual "a'" select-quoted
+bindkey -M visual "a\"" select-quoted
+bindkey -M visual "a\`" select-quoted
+bindkey -M visual "i'" select-quoted
+bindkey -M visual "i\"" select-quoted
+bindkey -M visual "i\`" select-quoted
diff --git a/modules/by-name/zs/zsh/config/keymaps_end.zsh b/modules/by-name/zs/zsh/config/keymaps_end.zsh
new file mode 100644
index 00000000..2e973de4
--- /dev/null
+++ b/modules/by-name/zs/zsh/config/keymaps_end.zsh
@@ -0,0 +1,2 @@
+# Use the vi imitation keymap as default
+bindkey -A viins main
diff --git a/modules/by-name/zs/zsh/config/keymaps_start.zsh b/modules/by-name/zs/zsh/config/keymaps_start.zsh
new file mode 100644
index 00000000..2504e799
--- /dev/null
+++ b/modules/by-name/zs/zsh/config/keymaps_start.zsh
@@ -0,0 +1,16 @@
+# Delete all default keymaps (with the exception of .safe)
+bindkey -D command emacs isearch main vicmd viins viopp visual
+
+# See https://en.wikipedia.org/wiki/ANSI_escape_code for a explanation of the control
+# sequences used in these mappings.
+#
+# Re-create them with my modifications
+# (This is sourced by nix)
+# source ./.safe.zsh
+# source ./command.zsh
+# source ./emacs.zsh
+# source ./isearch.zsh
+# source ./vicmd.zsh
+# source ./viins.zsh
+# source ./viopp.zsh
+# source ./visual.zsh
diff --git a/modules/by-name/zs/zsh/config/zsh-init.zsh b/modules/by-name/zs/zsh/config/zsh-init.zsh
index cd8d34a9..aac344dc 100644
--- a/modules/by-name/zs/zsh/config/zsh-init.zsh
+++ b/modules/by-name/zs/zsh/config/zsh-init.zsh
@@ -1,42 +1,9 @@
 #!/usr/bin/env zsh
-# If not running interactively, don't do anything
-[[ $- != *i* ]] && return
 
-# Flex on the ubuntu users
-#[ "$NVIM" ] || hyfetch
-[ "$NVIM" ] || task next
-#loginctl show-session $XDG_SESSION_ID
-
-## Enable colors and change prompt:
-#autoload -Uz colors && colors
-#autoload -Uz compinit && compinit -u
-## Edit line in vim buffer ctrl-v
-autoload -Uz edit-command-line
-zle -N edit-command-line
-## Enter vim buffer from normal mode
-#autoload -Uz edit-command-line && zle -N edit-command-line
-bindkey "^V" edit-command-line
+# Display current tasks
+[ -z "$NVIM" ] && task next
 
 ## zstyles
 #zstyle ':completion:*' menu select
 ## Auto complete with case insensitivity
 #zstyle ':completion:*' matcher-list '' 'm:{a-zA-Z}={A-Za-z}' 'r:|[._-]=* r:|=*' 'l:|=* r:|=*'
-
-#zmodload zsh/complist
-#fpath+=/home/dt/.config/zsh/comp
-#compinit
-#_comp_options+=(globdots)		# Include hidden files.
-#
-## Source configs
-#source "${ZDOTDIR}/ali.sh"
-#source "${ZDOTDIR}/prompt.sh"
-#source "${ZDOTDIR}/hotkeys.sh"
-#source "./${path_custom_cursor}"
-#source ~/.local/lib/shell/lib
-#
-## Load zsh-syntax-highlighting
-#source /usr/share/zsh/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
-## Suggest aliases for commands
-#source /usr/share/zsh/plugins/zsh-you-should-use/you-should-use.plugin.zsh
-#
-##eval "$(lua ~/scripts/z.lua --init zsh enhanced)"