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

Re: [vi-mode] widgets for case manipulation: `gU` and `U` in visual mode



Filipe Silva wrote:
>
> I reckon there's already a widget for the `g~` action in zle.

Yes, vi-oper-swap-case

> I read the zshzle manual and did not find a widget that would give me the
> behaviour of `gU` (capitalize action)

I use the following custom widgets.
Perhaps these should be included somehow - any thoughts? It might be
easiest in C because with included widgets you still need zle -N and
bindkeys in your .zshrc.

> Is this a matter of writing a custom widget, or would one have to submit a
> patch upstream with c code changes? I'm asking this because 5.0.8
> introduced text objects and that was done via c code changes and not via
> widgets. And writing custom widgets seems to be less difficult.

Some of the text objects were done via shell widgets - select-quoted and
select-bracketed which select text between delimiters. This does mean
you have to enable them yourself. At first, I had hoped they would serve
as examples of how to do text object widgets but they ended up being
quite complex once vim compatibility for odd cases was considered. So
maybe they should be converted to C?

Oliver

vi-lowercase() {
  local save_cut="$CUTBUFFER" save_cur="$CURSOR"
  zle .vi-change || return
  zle .vi-cmd-mode
  CUTBUFFER="${CUTBUFFER:l}"
  zle .vi-put-after -n 1
  CUTBUFFER="$save_cut" CURSOR="$save_cur"
}

vi-uppercase() {
  local save_cut="$CUTBUFFER" save_cur="$CURSOR"
  zle .vi-change || return
  zle .vi-cmd-mode
  CUTBUFFER="${CUTBUFFER:u}"
  zle .vi-put-after -n 1
  CUTBUFFER="$save_cut" CURSOR="$save_cur"
}

zle -N vi-lowercase
zle -N vi-uppercase

bindkey -a 'gU' vi-uppercase
bindkey -a 'gu' vi-lowercase
bindkey -M visual 'u' vi-lowercase
bindkey -M visual 'U' vi-uppercase



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