zsh:在目录分隔符上停止向后杀字

发布于 2024-07-12 11:42:11 字数 294 浏览 5 评论 0原文

zsh 中,如何设置行编辑器以便 backward-kill-word 停在目录分隔符上? 目前在我的 bash 设置中,如果我输入

cd ~/devel/sandbox

然后点击 Cw 点将位于 devel/ 之后。 在我的 zsh 设置中,点将位于 cd 之后。 我想设置 zsh,使其行为与 bash 类似。

In zsh, how can I set up the line editor such that backward-kill-word stops on a directory separator? Currently in my bash setup, if I type

cd ~/devel/sandbox

and then hit C-w point will be right after devel/. In my zsh setup, point would be after cd. I'd like to set up zsh so it behaves similarly to bash.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

长伴 2024-07-19 11:42:11

对于 zsh 的最新版本,您只需将: 添加

autoload -U select-word-style
select-word-style bash

到您的 zshrc 中,如 中所述zsh 手册(也称为 man zshcontrib)。

For recent versions of zsh, you can simply add:

autoload -U select-word-style
select-word-style bash

to your zshrc as described in the zsh manual (also man zshcontrib).

挽袖吟 2024-07-19 11:42:11

另一种选择是将 WORDCHARS(视为单词一部分的非字母数字字符)设置为不包含 / 的内容。

如果您希望 ^w 在点、下划线等处中断,您也可以调整此设置。在 ~/.zshrc 中,我有:

WORDCHARS='*?_-.[]~=&;!#$%^(){}<>'

Another option is to set WORDCHARS (non-alphanumeric chars treated as part of a word) to something that doesn't include /.

You can also tweak this if you'd prefer ^w to break on dot, underscore, etc. In ~/.zshrc I have:

WORDCHARS='*?_-.[]~=&;!#$%^(){}<>'
戈亓 2024-07-19 11:42:11

这对我有用。 需要 unspecified word-style,否则 zsh 似乎不尊重 WORDCHARS在此处输入代码

WORDCHARS=' *?_-.[]~=&;!#$%^(){}<>/'
autoload -Uz select-word-style
select-word-style normal
zstyle ':zle:*' word-style unspecified

以下是有关其工作原理的更多信息。

Here's what worked for me. unspecified word-style was required otherwise zsh didn't seem to respect the WORDCHARS.enter code here

WORDCHARS=' *?_-.[]~=&;!#$%^(){}<>/'
autoload -Uz select-word-style
select-word-style normal
zstyle ':zle:*' word-style unspecified

Here's more info on why this works.

明明#如月 2024-07-19 11:42:11

快速谷歌显示:

向后终止

或者,也许是更好的解决方案:

Bash 风格向后杀

A quick google reveals:

Backward Kill

Or, perhaps a better fix:

Bash Style Backward Kill

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文