about summary refs log tree commit diff
path: root/Functions/Zle/up-line-or-beginning-search
diff options
context:
space:
mode:
Diffstat (limited to 'Functions/Zle/up-line-or-beginning-search')
-rw-r--r--Functions/Zle/up-line-or-beginning-search20
1 files changed, 20 insertions, 0 deletions
diff --git a/Functions/Zle/up-line-or-beginning-search b/Functions/Zle/up-line-or-beginning-search
new file mode 100644
index 000000000..5348e7ad3
--- /dev/null
+++ b/Functions/Zle/up-line-or-beginning-search
@@ -0,0 +1,20 @@
+# Like up-line-or-search, but uses the whole line prefix up to the
+# cursor position for searching backwards.
+
+emulate -L zsh
+
+if [[ $LBUFFER == *$'\n'* ]]; then
+  zle .up-line-or-history
+  __searching=''
+elif [[ -n $PREBUFFER ]] && 
+    zstyle -t ':zle:up-line-or-beginning-search' edit-buffer
+then
+  zle .push-line-or-edit
+else
+  [[ $LASTWIDGET = $__searching ]] && CURSOR=$__savecursor
+  __savecursor=$CURSOR
+  __searching=$WIDGET
+  zle .history-beginning-search-backward
+  zstyle -T ':zle:up-line-or-beginning-search' leave-cursor &&
+      zle .end-of-line
+fi