有人可以提供 Vim 命令 gqip 的详细说明吗?
Could Someone Provide a Broken down Description for the Vim Command gqip?
我的理解是命令 gqip
在正常模式下告诉 vim 格式化当前段落,以空格分隔,使用 formatoptions
作为规则。但是我找不到关于命令本身的任何信息来查看其他可能的用例。更具体地说,我想知道的是,如果您将命令 gqip
分解为 g
、q
、i
和 p
,它们的作用是什么各个组件如何赋予命令其行为?
gq{motion}
(:help gq
) 格式化被{motion}
.
覆盖的行
动作通常可以是任何移动光标的命令,在这种情况下,它涵盖初始和最终光标位置之间的所有内容,或“文本对象”。
:help text-objects
列出所有文本对象,具体为:
ip "inner paragraph", select [count] paragraphs (see
|paragraph|).
Exception: a blank line (only containing white space)
is also a paragraph boundary.
When used in Visual mode it is made linewise.
这个问题说明了最大的问题之一,即依赖从随机来源收集的随机、不连贯的信息片段,而不是正确地学习 Vim。
gqip
实际上是 gq
,一个运算符,ip
,一个动作。
“运算符”和“运动”的概念在 $ vimtutor
的第 2 课中介绍,并在用户手册的第 4 章中进一步讨论::help 04.1
,而文本对象的概念是在同一章中进一步介绍::help 04.8
.
学习 Vim 甚至“不像”学习一门语言,它 是 学习一门语言,用户手册的结构遵循通用语言教学技术:一开始,用户会得到一些基本命令(“删除”、“抽出”、“到下一个词”等,词汇)并展示如何组合它们(语法)以影响文件中的文本。这个想法是从简单的开始,逐渐引入更多的词汇和更多的语法规则。
一旦用户内化了 一些 词汇和 一些 语法,他们就可以轻松获得新命令并立即将它们与以前获得的命令组合起来在更复杂的“句子”中,就像语言学习者一样。
并且,FWIW,这是整个 :help 10.7
,它恰好涵盖了 gqap
,很容易推断出任何 gq
+ 动作,这要归功于你学到的东西 较早,在第 4 章中:
10.7 Formatting text
When you are typing plain text, it's nice if the length of each line is
automatically trimmed to fit in the window. To make this happen while
inserting text, set the 'textwidth' option:
:set textwidth=72
You might remember that in the example vimrc file this command was used for
every text file. Thus if you are using that vimrc file, you were already
using it. To check the current value of 'textwidth':
:set textwidth
Now lines will be broken to take only up to 72 characters. But when you
insert text halfway through a line, or when you delete a few words, the lines
will get too long or too short. Vim doesn't automatically reformat the text. To tell Vim to format the current paragraph:
gqap
This starts with the "gq" command, which is an operator. Following is "ap",
the text object that stands for "a paragraph". A paragraph is separated from
the next paragraph by an empty line.
Note:
A blank line, which contains white space, does NOT separate
paragraphs. This is hard to notice!
Instead of "ap" you could use any motion or text object. If your paragraphs
are properly separated, you can use this command to format the whole file:
gggqG
"gg" takes you to the first line, "gq" is the format operator and "G" the
motion that jumps to the last line.
In case your paragraphs aren't clearly defined, you can format just the lines
you manually select. Move the cursor to the first line you want to format.
Start with the command "gqj". This formats the current line and the one below
it. If the first line was short, words from the next line will be appended.
If it was too long, words will be moved to the next line. The cursor moves to
the second line. Now you can use "." to repeat the command. Keep doing this
until you are at the end of the text you want to format.
有了:help user-manual
提供的基础知识,gqip
就不是谜了。
我的理解是命令 gqip
在正常模式下告诉 vim 格式化当前段落,以空格分隔,使用 formatoptions
作为规则。但是我找不到关于命令本身的任何信息来查看其他可能的用例。更具体地说,我想知道的是,如果您将命令 gqip
分解为 g
、q
、i
和 p
,它们的作用是什么各个组件如何赋予命令其行为?
gq{motion}
(:help gq
) 格式化被{motion}
.
动作通常可以是任何移动光标的命令,在这种情况下,它涵盖初始和最终光标位置之间的所有内容,或“文本对象”。
:help text-objects
列出所有文本对象,具体为:
ip "inner paragraph", select [count] paragraphs (see |paragraph|). Exception: a blank line (only containing white space) is also a paragraph boundary. When used in Visual mode it is made linewise.
这个问题说明了最大的问题之一,即依赖从随机来源收集的随机、不连贯的信息片段,而不是正确地学习 Vim。
gqip
实际上是 gq
,一个运算符,ip
,一个动作。
“运算符”和“运动”的概念在 $ vimtutor
的第 2 课中介绍,并在用户手册的第 4 章中进一步讨论::help 04.1
,而文本对象的概念是在同一章中进一步介绍::help 04.8
.
学习 Vim 甚至“不像”学习一门语言,它 是 学习一门语言,用户手册的结构遵循通用语言教学技术:一开始,用户会得到一些基本命令(“删除”、“抽出”、“到下一个词”等,词汇)并展示如何组合它们(语法)以影响文件中的文本。这个想法是从简单的开始,逐渐引入更多的词汇和更多的语法规则。
一旦用户内化了 一些 词汇和 一些 语法,他们就可以轻松获得新命令并立即将它们与以前获得的命令组合起来在更复杂的“句子”中,就像语言学习者一样。
并且,FWIW,这是整个 :help 10.7
,它恰好涵盖了 gqap
,很容易推断出任何 gq
+ 动作,这要归功于你学到的东西 较早,在第 4 章中:
10.7 Formatting text
When you are typing plain text, it's nice if the length of each line is automatically trimmed to fit in the window. To make this happen while inserting text, set the 'textwidth' option:
:set textwidth=72
You might remember that in the example vimrc file this command was used for every text file. Thus if you are using that vimrc file, you were already using it. To check the current value of 'textwidth':
:set textwidth
Now lines will be broken to take only up to 72 characters. But when you insert text halfway through a line, or when you delete a few words, the lines will get too long or too short. Vim doesn't automatically reformat the text. To tell Vim to format the current paragraph:
gqap
This starts with the "gq" command, which is an operator. Following is "ap", the text object that stands for "a paragraph". A paragraph is separated from the next paragraph by an empty line.
Note: A blank line, which contains white space, does NOT separate paragraphs. This is hard to notice!
Instead of "ap" you could use any motion or text object. If your paragraphs are properly separated, you can use this command to format the whole file:
gggqG
"gg" takes you to the first line, "gq" is the format operator and "G" the motion that jumps to the last line.
In case your paragraphs aren't clearly defined, you can format just the lines you manually select. Move the cursor to the first line you want to format. Start with the command "gqj". This formats the current line and the one below it. If the first line was short, words from the next line will be appended. If it was too long, words will be moved to the next line. The cursor moves to the second line. Now you can use "." to repeat the command. Keep doing this until you are at the end of the text you want to format.
有了:help user-manual
提供的基础知识,gqip
就不是谜了。