zsh-users
 help / color / mirror / code / Atom feed
* Modify Zsh Configuration to Make M-backspace Remove Last Path Component
@ 2017-02-11 15:26 Markus Zeindl
  2017-02-11 16:01 ` Julien Jehannet
  0 siblings, 1 reply; 5+ messages in thread
From: Markus Zeindl @ 2017-02-11 15:26 UTC (permalink / raw)
  To: Zsh Users

Hello Zsh-Community,

I've started using zsh on GNU/Linux recently.
When editing commands on the prompt (assumingly in the zle), I
sometimes want to remove the last path component of an entered path
descriptor, i.e. remove the basename of a path. The following
description considers "M" to be the alt-key (or meta-key as in emacs key
notation)

Intuitively, I type M-backspace. This removes the whole path.
Scenario 1 illustrates this. 

Scenario 1: Target: Change directory to /foo/bar/oof/rab
Step 1: type target incorrectly as "% cd /foo/bar/oof/ran"
Step 2: press M-backspace leading to a command-line of "% cd"
Step 3: type target again completely leading to "% cd /foo/bar/oof/rab"

I'm not familiar with Zsh Key notation at all. So, I'm not sure, what
zle-command (or widget?) will be triggered on M-backspace
using the key mapping in Mapping 1. Is it "backward-kill-word"?

Mapping 1: Output of "% bindkey"
"^@" set-mark-command
"^A" beginning-of-line
"^B" backward-char
"^D" delete-char-or-list
"^E" end-of-line
"^F" forward-char
"^G" send-break
"^H" backward-delete-char
"^I" expand-or-complete
"^J" accept-line
"^K" kill-line
"^L" clear-screen
"^M" accept-line
"^N" down-line-or-history
"^O" accept-line-and-down-history
"^P" up-line-or-history
"^Q" push-line
"^R" history-incremental-search-backward
"^S" history-incremental-search-forward
"^T" transpose-chars
"^U" kill-whole-line
"^V" quoted-insert
"^W" backward-kill-word
"^X^B" vi-match-bracket
"^X^F" vi-find-next-char
"^X^J" vi-join
"^X^K" kill-buffer
"^X^N" infer-next-history
"^X^O" overwrite-mode
"^X^U" undo
"^X^V" vi-cmd-mode
"^X^X" exchange-point-and-mark
"^X*" expand-word
"^X=" what-cursor-position
"^XG" list-expand
"^Xg" list-expand
"^Xr" history-incremental-search-backward
"^Xs" history-incremental-search-forward
"^Xu" undo
"^Y" yank
"^[^D" list-choices
"^[^G" send-break
"^[^H" backward-kill-word
"^[^I" self-insert-unmeta
"^[^J" self-insert-unmeta
"^[^L" clear-screen
"^[^M" self-insert-unmeta
"^[^_" copy-prev-word
"^[ " expand-history
"^[!" expand-history
"^[\"" quote-region
"^[\$" spell-word
"^['" quote-line
"^[-" neg-argument
"^[." insert-last-word
"^[0" digit-argument
"^[1" digit-argument
"^[2" digit-argument
"^[3" digit-argument
"^[4" digit-argument
"^[5" digit-argument
"^[6" digit-argument
"^[7" digit-argument
"^[8" digit-argument
"^[9" digit-argument
"^[<" beginning-of-buffer-or-history
"^[>" end-of-buffer-or-history
"^[?" which-command
"^[A" accept-and-hold
"^[B" backward-word
"^[C" capitalize-word
"^[D" kill-word
"^[F" forward-word
"^[G" get-line
"^[H" run-help
"^[L" down-case-word
"^[N" history-search-forward
"^[OA" up-line-or-history
"^[OB" down-line-or-history
"^[OC" forward-char
"^[OD" backward-char
"^[OF" end-of-line
"^[OH" beginning-of-line
"^[P" history-search-backward
"^[Q" push-line
"^[S" spell-word
"^[T" transpose-words
"^[U" up-case-word
"^[W" copy-region-as-kill
"^[[2~" overwrite-mode
"^[[3~" delete-char
"^[[A" up-line-or-history
"^[[B" down-line-or-history
"^[[C" forward-char
"^[[D" backward-char
"^[_" insert-last-word
"^[a" accept-and-hold
"^[b" backward-word
"^[c" capitalize-word
"^[d" kill-word
"^[f" forward-word
"^[g" get-line
"^[h" run-help
"^[l" down-case-word
"^[n" history-search-forward
"^[p" history-search-backward
"^[q" push-line
"^[s" spell-word
"^[t" transpose-words
"^[u" up-case-word
"^[w" copy-region-as-kill
"^[x" execute-named-cmd
"^[y" yank-pop
"^[z" execute-last-named-cmd
"^[|" vi-goto-column
"^[^?" backward-kill-word
"^_" undo
" " magic-space
"!"-";" self-insert
";5C" emacs-forward-word
";5D" emacs-backward-word
"<"-"~" self-insert
"^?" backward-delete-char
"\M-^@"-"\M-." self-insert
"\M-/" complete-word
"\M-0"-"\M-^?" self-insert

How can I modify my configuration to achieve Scenario 2?

Scenario 2: Target: Change directory to /foo/bar/oof/rab
Step 1: type target incorrectly as "% cd /foo/bar/oof/ran"
Step 2: press M-backspace leading to a command-line of 
"% cd /foo/bar/oof/" 
Step 3: type only last path component "rab" again leading to
"cd /foo/bar/oof/rab"

Thanks a lot for every answer, helping me to improve my Zsh-experience.

All The Best,
Markus


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

* Re: Modify Zsh Configuration to Make M-backspace Remove Last Path Component
  2017-02-11 15:26 Modify Zsh Configuration to Make M-backspace Remove Last Path Component Markus Zeindl
@ 2017-02-11 16:01 ` Julien Jehannet
  2017-02-11 16:20   ` Markus Zeindl
  2017-02-11 21:49   ` Phil Pennock
  0 siblings, 2 replies; 5+ messages in thread
From: Julien Jehannet @ 2017-02-11 16:01 UTC (permalink / raw)
  To: Markus Zeindl; +Cc: Zsh Users

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

You can change the WORDCHARS setting by removing slash character:

WORDCHARS=${WORDCHARS:s@/@}

2017-02-11 16:26 GMT+01:00 Markus Zeindl <su_ld@mailbox.org>:

> Hello Zsh-Community,
>
> I've started using zsh on GNU/Linux recently.
> When editing commands on the prompt (assumingly in the zle), I
> sometimes want to remove the last path component of an entered path
> descriptor, i.e. remove the basename of a path. The following
> description considers "M" to be the alt-key (or meta-key as in emacs key
> notation)
>
> Intuitively, I type M-backspace. This removes the whole path.
> Scenario 1 illustrates this.
>
> Scenario 1: Target: Change directory to /foo/bar/oof/rab
> Step 1: type target incorrectly as "% cd /foo/bar/oof/ran"
> Step 2: press M-backspace leading to a command-line of "% cd"
> Step 3: type target again completely leading to "% cd /foo/bar/oof/rab"
>
> I'm not familiar with Zsh Key notation at all. So, I'm not sure, what
> zle-command (or widget?) will be triggered on M-backspace
> using the key mapping in Mapping 1. Is it "backward-kill-word"?
>
> Mapping 1: Output of "% bindkey"
> "^@" set-mark-command
> "^A" beginning-of-line
> "^B" backward-char
> "^D" delete-char-or-list
> "^E" end-of-line
> "^F" forward-char
> "^G" send-break
> "^H" backward-delete-char
> "^I" expand-or-complete
> "^J" accept-line
> "^K" kill-line
> "^L" clear-screen
> "^M" accept-line
> "^N" down-line-or-history
> "^O" accept-line-and-down-history
> "^P" up-line-or-history
> "^Q" push-line
> "^R" history-incremental-search-backward
> "^S" history-incremental-search-forward
> "^T" transpose-chars
> "^U" kill-whole-line
> "^V" quoted-insert
> "^W" backward-kill-word
> "^X^B" vi-match-bracket
> "^X^F" vi-find-next-char
> "^X^J" vi-join
> "^X^K" kill-buffer
> "^X^N" infer-next-history
> "^X^O" overwrite-mode
> "^X^U" undo
> "^X^V" vi-cmd-mode
> "^X^X" exchange-point-and-mark
> "^X*" expand-word
> "^X=" what-cursor-position
> "^XG" list-expand
> "^Xg" list-expand
> "^Xr" history-incremental-search-backward
> "^Xs" history-incremental-search-forward
> "^Xu" undo
> "^Y" yank
> "^[^D" list-choices
> "^[^G" send-break
> "^[^H" backward-kill-word
> "^[^I" self-insert-unmeta
> "^[^J" self-insert-unmeta
> "^[^L" clear-screen
> "^[^M" self-insert-unmeta
> "^[^_" copy-prev-word
> "^[ " expand-history
> "^[!" expand-history
> "^[\"" quote-region
> "^[\$" spell-word
> "^['" quote-line
> "^[-" neg-argument
> "^[." insert-last-word
> "^[0" digit-argument
> "^[1" digit-argument
> "^[2" digit-argument
> "^[3" digit-argument
> "^[4" digit-argument
> "^[5" digit-argument
> "^[6" digit-argument
> "^[7" digit-argument
> "^[8" digit-argument
> "^[9" digit-argument
> "^[<" beginning-of-buffer-or-history
> "^[>" end-of-buffer-or-history
> "^[?" which-command
> "^[A" accept-and-hold
> "^[B" backward-word
> "^[C" capitalize-word
> "^[D" kill-word
> "^[F" forward-word
> "^[G" get-line
> "^[H" run-help
> "^[L" down-case-word
> "^[N" history-search-forward
> "^[OA" up-line-or-history
> "^[OB" down-line-or-history
> "^[OC" forward-char
> "^[OD" backward-char
> "^[OF" end-of-line
> "^[OH" beginning-of-line
> "^[P" history-search-backward
> "^[Q" push-line
> "^[S" spell-word
> "^[T" transpose-words
> "^[U" up-case-word
> "^[W" copy-region-as-kill
> "^[[2~" overwrite-mode
> "^[[3~" delete-char
> "^[[A" up-line-or-history
> "^[[B" down-line-or-history
> "^[[C" forward-char
> "^[[D" backward-char
> "^[_" insert-last-word
> "^[a" accept-and-hold
> "^[b" backward-word
> "^[c" capitalize-word
> "^[d" kill-word
> "^[f" forward-word
> "^[g" get-line
> "^[h" run-help
> "^[l" down-case-word
> "^[n" history-search-forward
> "^[p" history-search-backward
> "^[q" push-line
> "^[s" spell-word
> "^[t" transpose-words
> "^[u" up-case-word
> "^[w" copy-region-as-kill
> "^[x" execute-named-cmd
> "^[y" yank-pop
> "^[z" execute-last-named-cmd
> "^[|" vi-goto-column
> "^[^?" backward-kill-word
> "^_" undo
> " " magic-space
> "!"-";" self-insert
> ";5C" emacs-forward-word
> ";5D" emacs-backward-word
> "<"-"~" self-insert
> "^?" backward-delete-char
> "\M-^@"-"\M-." self-insert
> "\M-/" complete-word
> "\M-0"-"\M-^?" self-insert
>
> How can I modify my configuration to achieve Scenario 2?
>
> Scenario 2: Target: Change directory to /foo/bar/oof/rab
> Step 1: type target incorrectly as "% cd /foo/bar/oof/ran"
> Step 2: press M-backspace leading to a command-line of
> "% cd /foo/bar/oof/"
> Step 3: type only last path component "rab" again leading to
> "cd /foo/bar/oof/rab"
>
> Thanks a lot for every answer, helping me to improve my Zsh-experience.
>
> All The Best,
> Markus
>



-- 
J u l i e n    J e h a n n e t

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

* Re: Modify Zsh Configuration to Make M-backspace Remove Last Path Component
  2017-02-11 16:01 ` Julien Jehannet
@ 2017-02-11 16:20   ` Markus Zeindl
  2017-02-11 21:49   ` Phil Pennock
  1 sibling, 0 replies; 5+ messages in thread
From: Markus Zeindl @ 2017-02-11 16:20 UTC (permalink / raw)
  To: Zsh Users

Thank you!
This was exactly what I was looking for!

Am Sat, 11 Feb 2017 17:01:31 +0100
schrieb Julien Jehannet <julien@smaf.org>:

> You can change the WORDCHARS setting by removing slash character:
> 
> WORDCHARS=${WORDCHARS:s@/@}
> 
> 2017-02-11 16:26 GMT+01:00 Markus Zeindl <su_ld@mailbox.org>:
> 
> > Hello Zsh-Community,
> >
> > I've started using zsh on GNU/Linux recently.
> > When editing commands on the prompt (assumingly in the zle), I
> > sometimes want to remove the last path component of an entered path
> > descriptor, i.e. remove the basename of a path. The following
> > description considers "M" to be the alt-key (or meta-key as in
> > emacs key notation)
> >
> > Intuitively, I type M-backspace. This removes the whole path.
> > Scenario 1 illustrates this.
> >
> > Scenario 1: Target: Change directory to /foo/bar/oof/rab
> > Step 1: type target incorrectly as "% cd /foo/bar/oof/ran"
> > Step 2: press M-backspace leading to a command-line of "% cd"
> > Step 3: type target again completely leading to "%
> > cd /foo/bar/oof/rab"
> >
> > I'm not familiar with Zsh Key notation at all. So, I'm not sure,
> > what zle-command (or widget?) will be triggered on M-backspace
> > using the key mapping in Mapping 1. Is it "backward-kill-word"?
> >
> > Mapping 1: Output of "% bindkey"
> > "^@" set-mark-command
> > "^A" beginning-of-line
> > "^B" backward-char
> > "^D" delete-char-or-list
> > "^E" end-of-line
> > "^F" forward-char
> > "^G" send-break
> > "^H" backward-delete-char
> > "^I" expand-or-complete
> > "^J" accept-line
> > "^K" kill-line
> > "^L" clear-screen
> > "^M" accept-line
> > "^N" down-line-or-history
> > "^O" accept-line-and-down-history
> > "^P" up-line-or-history
> > "^Q" push-line
> > "^R" history-incremental-search-backward
> > "^S" history-incremental-search-forward
> > "^T" transpose-chars
> > "^U" kill-whole-line
> > "^V" quoted-insert
> > "^W" backward-kill-word
> > "^X^B" vi-match-bracket
> > "^X^F" vi-find-next-char
> > "^X^J" vi-join
> > "^X^K" kill-buffer
> > "^X^N" infer-next-history
> > "^X^O" overwrite-mode
> > "^X^U" undo
> > "^X^V" vi-cmd-mode
> > "^X^X" exchange-point-and-mark
> > "^X*" expand-word
> > "^X=" what-cursor-position
> > "^XG" list-expand
> > "^Xg" list-expand
> > "^Xr" history-incremental-search-backward
> > "^Xs" history-incremental-search-forward
> > "^Xu" undo
> > "^Y" yank
> > "^[^D" list-choices
> > "^[^G" send-break
> > "^[^H" backward-kill-word
> > "^[^I" self-insert-unmeta
> > "^[^J" self-insert-unmeta
> > "^[^L" clear-screen
> > "^[^M" self-insert-unmeta
> > "^[^_" copy-prev-word
> > "^[ " expand-history
> > "^[!" expand-history
> > "^[\"" quote-region
> > "^[\$" spell-word
> > "^['" quote-line
> > "^[-" neg-argument
> > "^[." insert-last-word
> > "^[0" digit-argument
> > "^[1" digit-argument
> > "^[2" digit-argument
> > "^[3" digit-argument
> > "^[4" digit-argument
> > "^[5" digit-argument
> > "^[6" digit-argument
> > "^[7" digit-argument
> > "^[8" digit-argument
> > "^[9" digit-argument
> > "^[<" beginning-of-buffer-or-history
> > "^[>" end-of-buffer-or-history
> > "^[?" which-command
> > "^[A" accept-and-hold
> > "^[B" backward-word
> > "^[C" capitalize-word
> > "^[D" kill-word
> > "^[F" forward-word
> > "^[G" get-line
> > "^[H" run-help
> > "^[L" down-case-word
> > "^[N" history-search-forward
> > "^[OA" up-line-or-history
> > "^[OB" down-line-or-history
> > "^[OC" forward-char
> > "^[OD" backward-char
> > "^[OF" end-of-line
> > "^[OH" beginning-of-line
> > "^[P" history-search-backward
> > "^[Q" push-line
> > "^[S" spell-word
> > "^[T" transpose-words
> > "^[U" up-case-word
> > "^[W" copy-region-as-kill
> > "^[[2~" overwrite-mode
> > "^[[3~" delete-char
> > "^[[A" up-line-or-history
> > "^[[B" down-line-or-history
> > "^[[C" forward-char
> > "^[[D" backward-char
> > "^[_" insert-last-word
> > "^[a" accept-and-hold
> > "^[b" backward-word
> > "^[c" capitalize-word
> > "^[d" kill-word
> > "^[f" forward-word
> > "^[g" get-line
> > "^[h" run-help
> > "^[l" down-case-word
> > "^[n" history-search-forward
> > "^[p" history-search-backward
> > "^[q" push-line
> > "^[s" spell-word
> > "^[t" transpose-words
> > "^[u" up-case-word
> > "^[w" copy-region-as-kill
> > "^[x" execute-named-cmd
> > "^[y" yank-pop
> > "^[z" execute-last-named-cmd
> > "^[|" vi-goto-column
> > "^[^?" backward-kill-word
> > "^_" undo
> > " " magic-space
> > "!"-";" self-insert
> > ";5C" emacs-forward-word
> > ";5D" emacs-backward-word
> > "<"-"~" self-insert
> > "^?" backward-delete-char
> > "\M-^@"-"\M-." self-insert
> > "\M-/" complete-word
> > "\M-0"-"\M-^?" self-insert
> >
> > How can I modify my configuration to achieve Scenario 2?
> >
> > Scenario 2: Target: Change directory to /foo/bar/oof/rab
> > Step 1: type target incorrectly as "% cd /foo/bar/oof/ran"
> > Step 2: press M-backspace leading to a command-line of
> > "% cd /foo/bar/oof/"
> > Step 3: type only last path component "rab" again leading to
> > "cd /foo/bar/oof/rab"
> >
> > Thanks a lot for every answer, helping me to improve my
> > Zsh-experience.
> >
> > All The Best,
> > Markus
> >
> 
> 
> 


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

* Re: Modify Zsh Configuration to Make M-backspace Remove Last Path Component
  2017-02-11 16:01 ` Julien Jehannet
  2017-02-11 16:20   ` Markus Zeindl
@ 2017-02-11 21:49   ` Phil Pennock
  2017-02-12  9:32     ` Markus Zeindl
  1 sibling, 1 reply; 5+ messages in thread
From: Phil Pennock @ 2017-02-11 21:49 UTC (permalink / raw)
  To: Julien Jehannet; +Cc: Markus Zeindl, Zsh Users

On 2017-02-11 at 17:01 +0100, Julien Jehannet wrote:
> You can change the WORDCHARS setting by removing slash character:
> 
> WORDCHARS=${WORDCHARS:s@/@}

In addition to this, I find that I like ^W to keep the normal behaviour,
but M-backspace to be different, so I do this:

    function backward-kill-partial-word {
        local WORDCHARS="${WORDCHARS//[\/.]/}"
        zle backward-kill-word "$@"
    }
    zle -N backward-kill-partial-word
    for x in '^Xw' '^[^?' '^[^H'; do
        bindkey "$x" backward-kill-partial-word
    done; unset x

-Phil


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

* Re: Modify Zsh Configuration to Make M-backspace Remove Last Path Component
  2017-02-11 21:49   ` Phil Pennock
@ 2017-02-12  9:32     ` Markus Zeindl
  0 siblings, 0 replies; 5+ messages in thread
From: Markus Zeindl @ 2017-02-12  9:32 UTC (permalink / raw)
  To: zsh-users

Hi Phil,

that sounds nice, too!

Thanks,
Markus


Am Sat, 11 Feb 2017 21:49:09 +0000
schrieb Phil Pennock <zsh-workers+phil.pennock@spodhuis.org>:

> On 2017-02-11 at 17:01 +0100, Julien Jehannet wrote:
> > You can change the WORDCHARS setting by removing slash character:
> > 
> > WORDCHARS=${WORDCHARS:s@/@}
> 
> In addition to this, I find that I like ^W to keep the normal
> behaviour, but M-backspace to be different, so I do this:
> 
>     function backward-kill-partial-word {
>         local WORDCHARS="${WORDCHARS//[\/.]/}"
>         zle backward-kill-word "$@"
>     }
>     zle -N backward-kill-partial-word
>     for x in '^Xw' '^[^?' '^[^H'; do
>         bindkey "$x" backward-kill-partial-word
>     done; unset x
> 
> -Phil


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

end of thread, other threads:[~2017-02-12  9:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-11 15:26 Modify Zsh Configuration to Make M-backspace Remove Last Path Component Markus Zeindl
2017-02-11 16:01 ` Julien Jehannet
2017-02-11 16:20   ` Markus Zeindl
2017-02-11 21:49   ` Phil Pennock
2017-02-12  9:32     ` Markus Zeindl

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).