less 有相当于 vim 的滚动功能吗?

发布于 2024-11-15 22:41:19 字数 219 浏览 1 评论 0原文

我在 vim 中将滚动设置为 4。这意味着当我向上或向下滚动时,我所在的行与屏幕底部或顶部之间有 4 行。

当我使用 less 时,通常是为了查看联机帮助页,我使用 / 来搜索文本。如果我正在寻找一个执行某些操作的命令行选项,并且我搜索术语“某事”,通常“某事”会出现在解释命令的段落中,并且命令行开关在其上方一两行,所以我必须向上滚动才能看到它。在这种情况下,有什么想法可以让 less 更像 vim 吗?

I have scrolloff set to 4 in vim. This means that when I scroll up or down, there are 4 lines between the line I'm on and the bottom or top of the screen.

When I use less, usually to view a manpage, I use / to search for text. If I'm looking for a command line option that does something and I search for the term 'something' usually 'something' shows up in the paragraph explaining a command, and the command line switch is a line or two above that, so I have to scroll up to see it. Any ideas for how to make less act more like vim in this one case?

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

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

发布评论

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

评论(2

南城追梦 2024-11-22 22:41:19

我相信你想要 -j 选项。它似乎没有底部或顶部模式,而是底部模式或顶部模式。例如:

less -j 4

将始终在第四行(从顶部开始)显示您的搜索词,而

less -j -4 

将始终在从底部开始的第四行显示您的搜索词。

当然,您可以使用别名将您的首选项设置为默认值,方法是将其添加到 .bashrc 中,例如:

alias less="less -j 4"

I believe you want the -j option. It doesn't seem to have a bottom-or-top mode, but rather a bottom-mode or top-mode. For instance:

less -j 4

Will always display your search term on the 4th line (from the top), whereas

less -j -4 

Will always display your search term on the 4th line from the bottom.

And of course, you can use alias to make your preference the default, by adding this to your .bashrc, for instance:

alias less="less -j 4"
满地尘埃落定 2024-11-22 22:41:19

不确定是否可以让 less 自己完成此操作,但您知道可以使用 Vim 代替 less 作为寻呼机吗? Vim 安装宏/目录中有一个名为 less.vim 的宏。将其复制到您自己的 .vim/macros 目录以启用,然后在您的 .bashrc (或任何您的 shell)中使用 less 别名

# example:
alias less='/usr/share/vim/7.x/macro/less.sh'

编辑不幸的是,我自己尝试过,它默认忽略scrolloff。您可以修改 less.sh 以在启动时设置 scrolloff=3

Not sure if you can make less do this by itself, but did you know you can use Vim in place of less as your pager? There's a macro in the Vim installation macros/ directory called less.vim. Copy it to your own .vim/macros directory to enable, then alias less in your .bashrc (or whatever your shell)

# example:
alias less='/usr/share/vim/7.x/macro/less.sh'

EDIT Unfortunately I just tried this myself and it ignores the scrolloff by default. You could modify the less.sh to set scrolloff=3 at launch.

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