更改 bash 中的单词分隔符

发布于 2024-08-03 08:40:04 字数 351 浏览 5 评论 0原文

我想更改 bash (或 readline)用于分隔单词的分隔符。具体来说,我想让 '-' 不分隔单词,这样,如果我有文本

ls some-file

并且按 Alt-Backspace ,它会删除整个 some-file< /code> 文本,而不仅仅是 '-' 字符。这也将导致更快、更轻松地删除诸如 --group-directories-first 之类的长标志,只需按一次键即可。

我相信这就是 zsh 的行为方式,我想让 bash 也有同样的行为方式。

I want to change the delimiters bash (or readline) uses to separate words. Specifically I want to make '-' not delimit words, so that if I have the text

ls some-file

and I press Alt-Backspace it deletes the entire some-file text and not just up to the '-' char. This will also cause deletions of long flags like --group-directories-first faster and easier, needing only one key-press.

I believe that this is how zsh behaves and I'd like to make bash behave in the same way.

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

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

发布评论

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

评论(3

坏尐絯 2024-08-10 08:40:04

ctrl-w 正是你想要的。

ctrl-w does exactly what you want.

梦明 2024-08-10 08:40:04

要记住的一件事是,如果您将 stty werase 设置分配给 ctrl-W,则 ctrl-W 的 bash 键映射将不起作用。如果你运行“stty -a”并且看到“werase = ^W”,它将优先并使用 tty 的单词边界概念。
tty 的单词边界概念通常是空格,而 bash 的向后终止单词功能还包括 - 和 /。

如果您想让 Alt-Backspace 执行与 werase 设置相同的操作,您可以这样做:
绑定 '"\M-\Ch": unix-word-rubout'
bind '"\M-\C-?": unix-word-rubout'

另外,如果你真的想让 ctrl-W 做 Alt-Backspace 所做的事情,你会这样做:
stty werase undef # 除非你这样做,bash 会忽略下面的绑定命令
绑定'“\ Cw”:向后杀字'

One thing to keep in mind is that the bash key mapping for ctrl-W will not work if you have the stty werase setting assigned to ctrl-W. If you run "stty -a" and you see "werase = ^W" that will take precedence and use the tty idea of what a word boundary is.
The tty's idea of a word boundary is usually whitespace, whereas bash's backward-kill-word function also includes - and /.

If you want to make Alt-Backspace do the same thing as the werase setting, you can do this:
bind '"\M-\C-h": unix-word-rubout'
bind '"\M-\C-?": unix-word-rubout'

Also, if you actually wanted to make ctrl-W do what Alt-Backspace does, you would do:
stty werase undef # unless you do this, bash ignores the follow bind command
bind '"\C-w": backwards-kill-word'

暖阳 2024-08-10 08:40:04

这可能很有用:Ctrl-r 将启动反向搜索(针对历史记录和当前行),因此您只需按空格键并转义,它就会回到您想要的位置,或者再次按 ctrl-r(在按第一个空格)如果你想再返回一个参数。然后你可以选择杀死该行的其余部分。

如果您正在处理长路径参数(例如在 cp 或 diff 中),并且需要修改第一个参数的末尾,则特别有用。

试图让 \Mb 来执行此操作,但它在斜杠处停止。

This might be useful: Ctrl-r will initiate a reverse-i-search (for history AND the current line), so you can just hit space and escape and it's back where you want it, or ctrl-r again (after hitting the first space) if you want to go back one more arg. Then you can optionally kill the rest of the line.

Especially useful if you're dealing with long path arguments (e.g. in cp or diff), and need to modify the end of the first arg.

Tried to get \M-b to do this, but it stops at slashes.

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