emulate -L zsh setopt extendedglob local curcontext=:zle:delete-whole-word local -a matched_words # Start and end of range of characters to remove. integer pos1 pos2 match-words-by-style if [[ -n "${matched_words[3]}" ]]; then # There's whitespace before the cursor, so the word we are deleting # starts at the cursor position. pos1=$CURSOR else # No whitespace before us, so delete any wordcharacters there. pos1="${#matched_words[1]}" fi if [[ -n "${matched_words[4]}" ]]; then # There's whitespace at the cursor position, so only delete # up to the cursor position. pos2=$CURSOR else # No whitespace at the cursor position, so delete the # current character and any following wordcharacters. (( pos2 = CURSOR + ${#matched_words[5]} + 1 )) fi # Move the cursor and delete the block in one go for the # purpose of yanking. (( CURSOR = pos1 )) BUFFER="${BUFFER[1,pos1]}${BUFFER[pos2,-1]}"