在使用诸如less这样的Bash程序查看数据表时,将第一行固定在顶部。

huangapple go评论51阅读模式
英文:

pin the first row when viewing a data table with a bash program such as less

问题

我有一个以空格为分隔符的文件 data.txt,我正在使用 less 读取它:

less -S data.txt

我希望第一行保持固定在终端的顶部。

在bash中是否有一种方法可以实现这个目标?不一定要使用 less,如果需要的话,可以定义一个新的bash函数或别名。

英文:

I have a space-delimited file data.txt that I am reading with less:

less -S data.txt

I want the first row to stay pinned to the top of the terminal.

Is there a way to accomplish this in bash? It doesn't need to be using less, and it's fine if it requires defining a new bash function or alias.

答案1

得分: 1

我有时会将Vim用作分页器:

command | vim -

在Vim中,您可以使用<kbd>ctrl</kbd>+<kbd>w</kbd> <kbd>s</kbd>来垂直拆分屏幕。

默认情况下,这将让屏幕一分为二,有点烦人。您可以使用数字前缀,比如<kbd>1</kbd> <kbd>ctrl</kbd>+<kbd>w</kbd> <kbd>s</kbd>,使顶部拆分为一行高。

使用<kbd>ctrl</kbd>+<kbd>w</kbd> <kbd>w</kbd>,或者<kbd>ctrl</kbd>+<kbd>w</kbd> <kbd>ctrl</kbd>+<kbd>w</kbd>在拆分之间切换。

每次想要一个带有一行拆分的分页器时,手动操作都不太方便。以下是如何在单个命令中执行的方法:

command | vi -c &#39;1split | winc w&#39; -

-c告诉Vim在打开文件后运行两个命令。第一个命令 1split 在屏幕顶部创建一个一行高的拆分。:winc w 是执行<kbd>ctrl</kbd>+<kbd>w</kbd> <kbd>w</kbd>切换到底部拆分的冒号命令方式,这样您就可以准备滚动主视图。

vi ...部分创建一个别名,如下:

alias vl=&#39;vi -c &quot;1split | winc w&quot; -&#39;

然后,您可以轻松使用它,例如 command | vl

英文:

I sometimes use Vim as a pager:

command | vim -

In Vim you can use <kbd>ctrl</kbd>+<kbd>w</kbd> <kbd>s</kbd> to split the screen vertically.

This has an annoying default to split the screen in half. You can give it a numeric prefix like <kbd>1</kbd> <kbd>ctrl</kbd>+<kbd>w</kbd> <kbd>s</kbd> to make the top split one line tall.

Use <kbd>ctrl</kbd>+<kbd>w</kbd> <kbd>w</kbd>, or <kbd>ctrl</kbd>+<kbd>w</kbd> <kbd>ctrl</kbd>+<kbd>w</kbd> to toggle between the splits.

This is all inconvenient to fiddle with manually each time you want a pager with a one-line split. Here is how to do it in a single command:

command | vi -c &#39;1split | winc w&#39; -

The -c tells Vim to run two commands after opening the file. The first one 1split creates a one line split at the top of the screen. The :winc w is the colon command way to execute a <kbd>ctrl</kbd>+<kbd>w</kbd> <kbd>w</kbd> to switch the cursor to the bottom split, so you're ready to scroll the main view.

Make an alias for the vi ... part like

alias vl=&#39;vi -c &quot;1split | winc w&quot; -&#39;

and then it's easy to use as command | vl.

huangapple
  • 本文由 发表于 2023年7月24日 15:05:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76752106.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定