I did some testing and doing yank-pop does _not_ cycle $killring. Here’s what actually happens: - yank inserts $CUTBUFFER - Each successive invocation of yank-pop replaces the active yank with the next non-zero entry of $killring, until it runs out of these, at which point it inserts $CUTBUFFER and starts over. If we implement reverse-yank-pop by modifying $CUTBUFFER and $killring, this will _not_ work correctly, because these changes will affect the next yank. For example, given the following implementation: reverse-rotate-killring() { killring=( "$CUTBUFFER" "$killring[@]" ) CUTBUFFER=$killring[-1] shift -p killring } reverse-yank-pop() { zle -f yankbefore reverse-rotate-killring reverse-rotate-killring zle .yank-pop } zle -N reverse-yank-pop bindkey '^[Y' reverse-yank-pop The problem with this approach is that changes to $CUTBUFFER and $killring are permanent: Whenever you use this particular reverse-yank-pop widget, you don’t only change what you yank now, you also change what you will yank _next time._ For example, given the above implementation and CUTBUFFER=a killring=( b c ): - If I yank -> yank-pop -> yank, the command line changes a -> b -> ba - If I yank -> reverse-yank-pop -> yank, the command line changes a -> c -> cc One would expect each yank above to insert a, but for the last yank this is no longer true, because our clipboard has changed to CUTBUFFER=c killring=( c a ) Instead, this appears to be the only way to get reverse-yank-pop to work correctly: reverse-yank-pop() { zle -f yankbefore local nonzero=( $CUTBUFFER $killring ) repeat $(( $#nonzero - 1 )); do zle .yank-pop; done } zle -N reverse-yank-pop bindkey '^[Y' reverse-yank-pop Being able to do something like (( YANK_INDEX-- )) or zle yank-pop -- -1 would be a lot cleaner, but at least this implementation is simple and short. |