Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: Is there a delete-to-previous-slash key?



Ian Langworth <ian.langworth@xxxxxxxxx> wrote:
> I'd like to have a key that deletes leftwards from the cursor to the
> previous occurrence of '/'. Does anyone have a snippet that does this
> sort of thing, or shall I dig deeper into zle?

The easiest way is temporarily not to allow / to be part of a word and
use backward-delete-word:

backward-delete-to-slash () {
  local WORDCHARS=${WORDCHARS//\//}
  zle .backward-delete-word
}
zle -N backward-delete-to-slash

but if you really want to delete anything else in the way you can
use something like:

backward-delete-to-slash() {
  integer pos=$CURSOR
  while (( pos > 1 )); do
    if [[ $LBUFFER[--pos] = / ]]; then
      LBUFFER=${LBUFFER[1,pos]}
      return 0
    fi
  done
  return 1
}
zle -N backward-delete-to-slash

That doesn't save it on the kill ring; I had hoped there would be some
shorthand for "delete this and put it on the kill ring" but the only ways I
can see are either to set the mark, or do it longhand with CUTBUFFER and
killring, and I couldn't be bothered.

-- 
Peter Stephenson <pws@xxxxxxx>                  Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK                          Tel: +44 (0)1223 692070


This message has been scanned for viruses by BlackSpider MailControl - www.blackspider.com



Messages sorted by: Reverse Date, Date, Thread, Author