mirrored from git://git.code.sf.net/p/zsh/code
-
Notifications
You must be signed in to change notification settings - Fork 440
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
38770: vi upper/lowercase widgets and shell widget example that reads…
… a vi movement
- Loading branch information
Oliver Kiddle
committed
Jun 29, 2016
1 parent
5ea32ce
commit a73ae70
Showing
7 changed files
with
112 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
# Example of a widget that takes a vi motion | ||
|
||
# Filter part of buffer corresponding to a vi motion through an external | ||
# program. | ||
|
||
# To enable with vi compatible bindings use: | ||
# autoload -Uz vi-pipe | ||
# bindkey -a '!' vi-pipe | ||
|
||
autoload -Uz read-from-minibuffer | ||
local _save_cut="$CUTBUFFER" REPLY | ||
|
||
# Use the standard vi-delete to accept a vi motion. | ||
zle .vi-delete || return | ||
read-from-minibuffer "!" | ||
local _save_cur=$CURSOR | ||
|
||
# cut buffer contains the deleted text and can be modified | ||
CUTBUFFER="$(eval $REPLY <<<$CUTBUFFER)" | ||
|
||
# put the modified text back in position. | ||
if [[ CURSOR -eq 0 || $BUFFER[CURSOR] = $'\n' ]]; then | ||
# at the beginning of a line, vi-delete won't have moved the cursor | ||
# back to a previous line | ||
zle .vi-put-before -n 1 | ||
else | ||
zle .vi-put-after -n 1 | ||
fi | ||
|
||
# restore cut buffer and cursor to the start of the range | ||
CUTBUFFER="$_save_cut" CURSOR="$_save_cur" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters