命令行Zsh中的注释

我在Ubuntu上最近从Bash切换到Zsh,对此我感到非常高兴。 但是,我真的很想念,而且我也没有find如何实现同样的目标。

在Bash中,每当我input一个很长的命令,并且注意到之前我必须运行其他东西,我只需要将它注释掉,如下所示:

me@home> #mysuperlongcommand with some arguments me@home> thecommandIhavetorunfirst #and then: then up up me@home> #mysuperlongcommand with some arguments #I just need to uncomment it! 

然而,这种相当反复的情况并不像zsh那样容易解决,因为#mysuperlongcommand将以这种方式运行(并导致zsh: command not found: #mysuperlongcommand

刚开始尝试zsh,我也遇到了这个问题。 你可以做setopt interactivecomments注释来激活bash式的注释。

我用

 bindkey "^Q" push-input 

从zsh手册:

将整个当前多行构造推送到缓冲区堆栈并返回到顶层(PS1)提示。 如果当前的parsing器结构只是一个单一的行,这就像是一个push-line。 下一次编辑器启动或popupget-line时,构造将被popup缓冲区堆栈的顶部并加载到编辑缓冲区中。

所以看起来像这样:

 > long command Ctrl+Q => long command disappears to the stack > forgotten command long command reappears from stack > long command 

另外,如果您设置了INTERACTIVE_COMMENTS选项( setopt INTERACTIVE_COMMENTS ),您将能够像您习惯的那样在交互式shell中使用注释。

我发现自己也经常这样做。 我所做的是剪切长命令,执行需要先执行的命令,然后粘贴长命令。这很容易: CTRL + U将当前命令剪切到缓冲区, CTRL + Y将其粘贴。 在zsh和bash中运行。