about summary refs log tree commit diff stats
path: root/modules/home/conf/zsh/config/custom_cursor.zsh
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-05-23 13:31:11 +0200
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2024-05-23 13:33:40 +0200
commitfd9b0ecef4142a62b45404700ba1cff488f84a73 (patch)
treeef6c1f74f05a2220a41ccff4b0890c39229f32f7 /modules/home/conf/zsh/config/custom_cursor.zsh
parentrefactor(pkgs): Categorize into `by-name` shards (diff)
downloadnixos-config-fd9b0ecef4142a62b45404700ba1cff488f84a73.tar.gz
nixos-config-fd9b0ecef4142a62b45404700ba1cff488f84a73.zip
refactor(modules/home): Setup as "normal" NixOS module
Diffstat (limited to 'modules/home/conf/zsh/config/custom_cursor.zsh')
-rw-r--r--modules/home/conf/zsh/config/custom_cursor.zsh42
1 files changed, 42 insertions, 0 deletions
diff --git a/modules/home/conf/zsh/config/custom_cursor.zsh b/modules/home/conf/zsh/config/custom_cursor.zsh
new file mode 100644
index 00000000..37390c1c
--- /dev/null
+++ b/modules/home/conf/zsh/config/custom_cursor.zsh
@@ -0,0 +1,42 @@
+#!/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
+
+# 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
+
+# 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
+
+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"
+}
+zle -N zle-line-init
+
+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.