zsh-workers
 help / color / Atom feed
* Make `Ctrl + W` and `Ctrl + Shift + H` in zsh behave the same as in bash
@ 2020-03-21 19:29 Rik
  2020-03-21 20:06 ` Daniel Shahaf
  0 siblings, 1 reply; 3+ messages in thread
From: Rik @ 2020-03-21 19:29 UTC (permalink / raw)
  To: zsh-workers

[-- Attachment #1: Type: text/plain, Size: 1095 bytes --]

Hi everyone,

I've recently started using zsh and I like it. However, coming from 
bash, some little things I miss.


*The problem:*

In bash behavior is like this:

  * Ctrl + W deletes the word behind the cursor up to the next space
  * Ctrl + Shift + H deletes the word behind the cursor up to the next
    seperation charcater like ., ,, -, / etc.

In zsh both Ctrl + W an Ctrl + Shift + H behave like the latter one in 
bash. I would like the same behavior as in bash.



*This is what I've tried:*

    SPACE_WORDCHARS='~!#$%^&*(){}[]<>?.+;-_/\|=@`'
    backward-delete-word() WORDCHARS=$SPACE_WORDCHARS zle .$WIDGET
    zle -N backward-delete-word
    bindkey "^W" backward-delete-word

This works, however, it breaks the functionality that deleting a word 
puts the word on the paste buffer, so I can't then paste this word with 
Ctrl + Y. This is quite important functionality for me. To be honest I'm 
not completely sure how this zle function works and what .$WIDGET does. 
Would anyone know a way how I can make this work while retaining the 
cut/paste behavior?


Many thanks,
Rik


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Make `Ctrl + W` and `Ctrl + Shift + H` in zsh behave the same as in bash
  2020-03-21 19:29 Make `Ctrl + W` and `Ctrl + Shift + H` in zsh behave the same as in bash Rik
@ 2020-03-21 20:06 ` Daniel Shahaf
  2020-03-21 20:12   ` Rik
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Shahaf @ 2020-03-21 20:06 UTC (permalink / raw)
  To: Rik; +Cc: zsh-workers

Rik wrote on Sat, 21 Mar 2020 14:29 -0500:
> I've recently started using zsh and I like it. However, coming from 
> bash, some little things I miss.
> 

Welcome!

> *The problem:*
> 
> In bash behavior is like this:
> 
>   * Ctrl + W deletes the word behind the cursor up to the next space
>   * Ctrl + Shift + H deletes the word behind the cursor up to the next
>     seperation charcater like ., ,, -, / etc.
> 
> In zsh both Ctrl + W an Ctrl + Shift + H behave like the latter one in 
> bash. I would like the same behavior as in bash.
> 
> 
> 
> *This is what I've tried:*
> 
>     SPACE_WORDCHARS='~!#$%^&*(){}[]<>?.+;-_/\|=@`'  
>     backward-delete-word() WORDCHARS=$SPACE_WORDCHARS zle .$WIDGET
>     zle -N backward-delete-word
>     bindkey "^W" backward-delete-word
> 
> This works, however, it breaks the functionality that deleting a word 
> puts the word on the paste buffer, so I can't then paste this word with 
> Ctrl + Y. This is quite important functionality for me. To be honest I'm 
> not completely sure how this zle function works and what .$WIDGET does. 
> Would anyone know a way how I can make this work while retaining the 
> cut/paste behavior?

Deleting those four lines and adding just «WORDCHARS='~!#$%^&*(){}[]<>?.+;-_/\|=@`'»
instead seems to do what you want.

(I also tried calling «zle -f kill» in the wrapper but it didn't have
the desired effect.)

Regarding $WIDGET, it's a parameter that gets predefined by zle when
widget functions are invoked.  In the example, its value will be
"backward-delete-char".  Thus, net effect of «zle .$WIDGET» will be to
call the builtin "backward-delete-char" widget.  For a simpler example,
consider:

mywidget() { LBUFFER+="x" }
zle -N mywidget
bindkey "y" mywidget

With this, every time you press "y", you'll get an "x" inserted.  (You
can just paste this example at the prompt to try it.)

Cheers,

Daniel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Make `Ctrl + W` and `Ctrl + Shift + H` in zsh behave the same as in bash
  2020-03-21 20:06 ` Daniel Shahaf
@ 2020-03-21 20:12   ` Rik
  0 siblings, 0 replies; 3+ messages in thread
From: Rik @ 2020-03-21 20:12 UTC (permalink / raw)
  To: Daniel Shahaf; +Cc: zsh-workers

Hey Daniel,

Thanks for your explanation!

Yes just using WORDCHARS will work, but that will also change the 
behavior of Ctrl + Alt + H. I want that to keep deleting *partial* words.

Greets,
Rik

On 21-03-2020 15:06, Daniel Shahaf wrote:
> Rik wrote on Sat, 21 Mar 2020 14:29 -0500:
>> I've recently started using zsh and I like it. However, coming from
>> bash, some little things I miss.
>>
> Welcome!
>
>> *The problem:*
>>
>> In bash behavior is like this:
>>
>>    * Ctrl + W deletes the word behind the cursor up to the next space
>>    * Ctrl + Shift + H deletes the word behind the cursor up to the next
>>      seperation charcater like ., ,, -, / etc.
>>
>> In zsh both Ctrl + W an Ctrl + Shift + H behave like the latter one in
>> bash. I would like the same behavior as in bash.
>>
>>
>>
>> *This is what I've tried:*
>>
>>      SPACE_WORDCHARS='~!#$%^&*(){}[]<>?.+;-_/\|=@`'
>>      backward-delete-word() WORDCHARS=$SPACE_WORDCHARS zle .$WIDGET
>>      zle -N backward-delete-word
>>      bindkey "^W" backward-delete-word
>>
>> This works, however, it breaks the functionality that deleting a word
>> puts the word on the paste buffer, so I can't then paste this word with
>> Ctrl + Y. This is quite important functionality for me. To be honest I'm
>> not completely sure how this zle function works and what .$WIDGET does.
>> Would anyone know a way how I can make this work while retaining the
>> cut/paste behavior?
> Deleting those four lines and adding just «WORDCHARS='~!#$%^&*(){}[]<>?.+;-_/\|=@`'»
> instead seems to do what you want.
>
> (I also tried calling «zle -f kill» in the wrapper but it didn't have
> the desired effect.)
>
> Regarding $WIDGET, it's a parameter that gets predefined by zle when
> widget functions are invoked.  In the example, its value will be
> "backward-delete-char".  Thus, net effect of «zle .$WIDGET» will be to
> call the builtin "backward-delete-char" widget.  For a simpler example,
> consider:
>
> mywidget() { LBUFFER+="x" }
> zle -N mywidget
> bindkey "y" mywidget
>
> With this, every time you press "y", you'll get an "x" inserted.  (You
> can just paste this example at the prompt to try it.)
>
> Cheers,
>
> Daniel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-21 19:29 Make `Ctrl + W` and `Ctrl + Shift + H` in zsh behave the same as in bash Rik
2020-03-21 20:06 ` Daniel Shahaf
2020-03-21 20:12   ` Rik

zsh-workers

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-workers

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.workers


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git