英文:
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 '1split | winc w' -
-c
告诉Vim在打开文件后运行两个命令。第一个命令 1split
在屏幕顶部创建一个一行高的拆分。:winc w
是执行<kbd>ctrl</kbd>+<kbd>w</kbd> <kbd>w</kbd>切换到底部拆分的冒号命令方式,这样您就可以准备滚动主视图。
为vi ...
部分创建一个别名,如下:
alias vl='vi -c "1split | winc w" -'
然后,您可以轻松使用它,例如 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 '1split | winc w' -
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='vi -c "1split | winc w" -'
and then it's easy to use as command | vl
.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论