summaryrefslogtreecommitdiff
path: root/Functions/Misc/zed
diff options
context:
space:
mode:
Diffstat (limited to 'Functions/Misc/zed')
-rw-r--r--Functions/Misc/zed41
1 files changed, 34 insertions, 7 deletions
diff --git a/Functions/Misc/zed b/Functions/Misc/zed
index f571daf5e..9eb4b2d93 100644
--- a/Functions/Misc/zed
+++ b/Functions/Misc/zed
@@ -3,7 +3,7 @@
#
# No other shell could do this.
# Edit small files with the command line editor.
-# Use ^X^W to save, ^C to abort.
+# Use ^X^W to save (or ZZ in vicmd mode), ^C to abort.
# Option -f: edit shell functions. (Also if called as fned.)
setopt localoptions noksharrays
@@ -60,6 +60,11 @@ __zed_pg_down()
done
}
+if ! zle -la __zed_pg_up __zed_pg_down; then
+ zle -N __zed_pg_up
+ zle -N __zed_pg_down
+fi
+
if (( bind )) || ! bindkey -M zed >&/dev/null; then
# Make the zed keymap a copy of the current main.
bindkey -N zed main
@@ -67,6 +72,12 @@ if (( bind )) || ! bindkey -M zed >&/dev/null; then
# zed we may want to set this temporally.
bindkey -A main zed-normal-keymap
+ # Define a widget to use at startup, undo shouldn't clear initial buffer
+ __zed_init() {
+ UNDO_LIMIT_NO=$UNDO_CHANGE_NO
+ }
+ zle -N __zed_init
+
# Assign some default keys.
# Depending on your stty's, you may be able to use ^J as accept-line, else:
@@ -75,10 +86,16 @@ if (( bind )) || ! bindkey -M zed >&/dev/null; then
bindkey -M zed '^x^w' accept-line
bindkey -M zed '^M' self-insert-unmeta
- zle -N __zed_pg_up
- zle -N __zed_pg_down
- [[ ${+terminfo} = 1 && -n "$terminfo[kpp]" ]] && bindkey -M zed "$terminfo[kpp]" __zed_pg_up
- [[ ${+terminfo} = 1 && -n "$terminfo[knp]" ]] && bindkey -M zed "$terminfo[knp]" __zed_pg_down
+ [[ ${+terminfo} = 1 ]] && {
+ [[ -n "$terminfo[kpp]" ]] && bindkey -M zed "$terminfo[kpp]" __zed_pg_up
+ [[ -n "$terminfo[knp]" ]] && bindkey -M zed "$terminfo[knp]" __zed_pg_down
+ [[ -n "$terminfo[khome]" ]] && bindkey -M zed "$terminfo[khome]" beginning-of-line
+ [[ -n "$terminfo[kend]" ]] && bindkey -M zed "$terminfo[kend]" end-of-line
+
+ # Fallback to well known code as terminfo might be wrong (often) sometimes
+ bindkey -M zed "^[[H" beginning-of-line
+ bindkey -M zed "^[[F" end-of-line
+ }
# Make zed-set-file-name available.
# Assume it's in fpath; there's no error at this point if it isn't
@@ -89,6 +106,16 @@ if (( bind )) || ! bindkey -M zed-vicmd >&/dev/null; then
bindkey -N zed-vicmd vicmd
bindkey -M zed-vicmd "ZZ" accept-line
+ [[ ${+terminfo} = 1 ]] && {
+ [[ -n "$terminfo[kpp]" ]] && bindkey -M zed-vicmd "$terminfo[kpp]" __zed_pg_up
+ [[ -n "$terminfo[knp]" ]] && bindkey -M zed-vicmd "$terminfo[knp]" __zed_pg_down
+ [[ -n "$terminfo[khome]" ]] && bindkey -M zed-vicmd "$terminfo[khome]" vi-beginning-of-line
+ [[ -n "$terminfo[kend]" ]] && bindkey -M zed-vicmd "$terminfo[kend]" vi-end-of-line
+
+ # Fallback to well known code as terminfo might be wrong (often) sometimes
+ bindkey -M zed-vicmd "^[[H" vi-beginning-of-line
+ bindkey -M zed-vicmd "^[[F" vi-end-of-line
+ }
fi
(( bind )) && return 0
@@ -105,11 +132,11 @@ if ((fun)) then
var="${(q-)1} () {
}"
fi
- vared -M zed -m zed-vicmd var && eval function "$var"
+ vared -M zed -m zed-vicmd -i __zed_init var && eval function "$var"
else
zed_file_name=$1
[[ -f $1 ]] && var="$(<$1)"
- while vared -M zed -m zed-vicmd var
+ while vared -M zed -m zed-vicmd -i __zed_init var
do
{
print -r -- "$var" >| $zed_file_name