从少复制特定行 [英] Copy specific line from less

查看:76
本文介绍了从少复制特定行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

搜索完Google之后,我决定写有关stackoverflow的文章,但我找不到关于我的简单问题的任何解决方案,因此我感到更加惊讶.

In the end after searching google I decided to write on stackoverflow, I couldn't find any solution about my simple problem, therefore I am even more surprised.

问题是:

如何从less中复制特定行?可以说我要打开一个男人(默认情况下,默认情况下,less会打开)并想选择并将其复制到剪贴板,然后说将其粘贴到在vim中打开的文件中?我不想使用鼠标滚轮粘贴.我正在寻找Windows中简单的Ctrl-cCtrl-v方法.

How to copy a specific line from less ? Lets say I am opening a man ( which is by default opened by less ) and want to select and copy it to clipboard and after that lets say paste it to file opened in vim ? I don't want to use the mouse wheel to paste. I am looking for a simple Ctrl-c , Ctrl-v method as in windows.

打开手册页时,无法使用'v'键切换到默认编辑器(vim),因为出现"Cannot edit standard input"错误的呼喊声较少. 非常感谢,很抱歉这个问题很愚蠢.

When opening a man page I can't switch to my default editor (which is vim ) with 'v' key because less shouts with "Cannot edit standard input" error. Thanks a lot and sorry if this question is silly.

推荐答案

tl; dr,使用m|.

tl;dr, use m and |.

less的手册页中,通过运行man less:

Within the man page of less, by running man less:

  1. 7g
  2. mx
  3. 6g
  4. |x
    • xclip(Linux)或pbcopy(macOS),复制到剪贴板.
    • cat > file保存到文件,或cat >> file追加模式.
  1. 7g
  2. mx
  3. 6g
  4. |x
    • xclip (Linux) or pbcopy (macOS), to copy to clipboard.
    • cat > file, to save to file, or cat >> file for append mode.

我们会得到:

   less - opposite of more    
    

要学习的关键只是两个less命令: m (标记)和 | (烟斗).

The key things to learn are just two less commands: m (mark), and | (pipe).

后跟任何小写字母,用该字母标记当前位置.

Followed by any lowercase letter, marks the current position with that letter.

我们在上面使用的标记是x,就像在步骤2中一样,它用x标记了行 7 .

The marker we used above is x, as in step 2, it marked line 7 with x.

| <m> shell-command

<m>代表任何标记字母.将输入文件的一部分通过管道传递给给定的shell命令.
文件的待传送部分位于当前屏幕第一行和字母标记的位置之间.
<m>也可以是^$,分别表示文件的开头或结尾.如果<m>.<newline>,则通过管道传输当前屏幕.

<m> represents any mark letter. Pipes a section of the input file to the given shell command.
The section of the file to be piped is between the first line on the current screen and the position marked by the letter.
<m> may also be ^ or $ to indicate beginning or end of file respectively. If <m> is . or <newline>, the current screen is piped.

使用 |x pbcopy,我们将行范围[7, 6]输送到pbcopy,因为行6当前是屏幕上的第一行,而行是我们标记为x的命令,而pbcopy是将文本放入macOS剪贴板的命令.

Using |xpbcopy, we pipe the line-range [7, 6] into pbcopy, as line 6 is currently the first line on the screen, and line 7 is the one we marked as x, and pbcopy is the command to put text into the macOS clipboard.

或者,在Linux上使用xclip,甚至使用dd of=/path/to/file另存为文件.

Alternatively, use xclip on Linux, or even dd of=/path/to/file to save as a file.

文本范围包含边界,因此将复制该范围的开始和结束行,或者至少复制2行.

The text range is boundary inclusive, so both the beginning and the ending lines of the range, or at least 2 lines are copied.

我们从后到上标记了范围,即从下到上,否则,less的行为可能会很尴尬,并且整个屏幕都将通过管道.

We marked the range in the backward way, namely from bottom to top, otherwise, less might behave awkwardly, and throw the whole screen through the pipe.

这篇关于从少复制特定行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆