如何在 zsh bindkey 中反斜杠反斜杠?

发布于 2025-01-15 08:11:43 字数 270 浏览 4 评论 0原文

我想将密钥替换为这样:

bindkey -s ',;' "| grep -A5 \"^\\s{3,}-\"\ei"

在我的 zshrc 中,但是 \\s 部分(对于 PCRE 中的空间应该是 \s ),给出类似这样的内容:

| grep -A5 "^S{3,}-"

所以有一些垃圾而不是\s。那么我怎样才能实现反斜杠呢?

I would like to replace the key as this:

bindkey -s ',;' "| grep -A5 \"^\\s{3,}-\"\ei"

in my zshrc, but the \\s part (which should be \s for space in PCRE), gives something like this:

| grep -A5 "^S{3,}-"

so there is some garbage instead of \s. So how can I achieve the backslash?

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

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

发布评论

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

评论(1

遥远的她 2025-01-22 08:11:43

虽然可能得到正确的引用,但通常最好首先避免这种嵌套引用。首先将 shell 函数添加到您的 .zshrc 文件中:

find_it () {
    grep -A5 '^\s{3,}-'
}

然后让您的小部件插入该函数。

bindkey -s ',;' '| find_it\ei'

While it's possible to get the quoting right, it's usually better to avoid such nested quoting in the first place. Add a shell function to your .zshrc file first:

find_it () {
    grep -A5 '^\s{3,}-'
}

Then have your widget insert the function instead.

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