是否可以在退出后在屏幕上保留 less 的输出?
Is it possible to keep the output of less on the screen after quitting?
我正在使用 oh-my-zsh,它将 git diff
和 git log
等函数的输出通过管道传输到 less
,同时这对于读取终端。如果我需要回头参考它,那么在 :q
退出后就不可能了
退出后是否可以选择在我的终端中保留文件的当前视图?
其次,如果有一个选项,我需要在哪里编辑我的 oh-my-zsh 配置以确保通过管道传输到 less 的任何内容都通过该选项?
要防止 less
在退出时清除屏幕,您可以使用选项 -X
:
启动它
less -X FILE
如果您想将此选项自动传递给 less 的每个实例,您可以在 ~/.zshrc
:
中相应地设置 LESS
环境变量
export LESS="-X"
Note:
If your shell has syntax coloring enabled, the -X
option will cause your less output to display those color change escape sequences as inline ESC
text.
This can be fixed by also passing the raw-control-chars
display option, -r
. For example:
export LESS="-Xr"
这也包括 less
由另一个程序启动的情况,例如 man
。如果你想为单个命令禁用这个选项,你可以在前面加上 LESS=
。例如
LESS= man less
对于Git具体而言,可以通过以下方式处理
git config --global color.ui true
git config --global core.pager 'less -Xr'
我正在使用 oh-my-zsh,它将 git diff
和 git log
等函数的输出通过管道传输到 less
,同时这对于读取终端。如果我需要回头参考它,那么在 :q
退出后是否可以选择在我的终端中保留文件的当前视图?
其次,如果有一个选项,我需要在哪里编辑我的 oh-my-zsh 配置以确保通过管道传输到 less 的任何内容都通过该选项?
要防止 less
在退出时清除屏幕,您可以使用选项 -X
:
less -X FILE
如果您想将此选项自动传递给 less 的每个实例,您可以在 ~/.zshrc
:
LESS
环境变量
export LESS="-X"
Note: If your shell has syntax coloring enabled, the
-X
option will cause your less output to display those color change escape sequences as inlineESC
text.
This can be fixed by also passing theraw-control-chars
display option,-r
. For example:export LESS="-Xr"
这也包括 less
由另一个程序启动的情况,例如 man
。如果你想为单个命令禁用这个选项,你可以在前面加上 LESS=
。例如
LESS= man less
对于Git具体而言,可以通过以下方式处理
git config --global color.ui true
git config --global core.pager 'less -Xr'