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

Re: vim control-a at the shell



Matthias Kopfermann wrote:
>i love that little feature within vim
>if you have a number say 20 and you press control-a with vim it becomes
>21 while control-x does 19.

This is more commonly on #+ and #-.

>our zsh is such a great shell that i am almost sure i can do that
>at the prompt, too but how should i do it?

A recent zsh beta is required (3.1.2 will do):

function increment-number {
  local n=${(M)LBUFFER%%[0-9]#}${(M)RBUFFER##[0-9]#}
  LBUFFER=${LBUFFER%%[0-9]#}$((n+1))
  RBUFFER=${RBUFFER##[0-9]#}
}
zle -N increment-number
bindkey -a '#+' increment-number     # nvi binding
bindkey -a '^A' increment-number     # vim binding

Similarly for decrement, but change $((n+1)) to $((n-1)) and adjust the
key bindings.  nvi et al also have a ## command, which repeats the last
of #+ and #- to be invoked explicitly.  To do this, add the command

  last_number=increment-number

to the increment-number function, and the corresponding line to
decrement-number, and then do

function last-number {
  [[ -n "$last_number" ]] && zle $last_number
}
zle -N last-number
bindkey -a '##' last-number

-zefram



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