Sentence s, paragraph p in Vim text object

introduction

I have been using ideaVim for almost half a year, it is time to give feedback to the community~~

Most of the text objects in vim text objects are easy to understand. This article mainly focuses on the sentences and paragraphs that are relatively seldom used and difficult to understand, and display and understand the code.

references

vim help documentation

text

Here we need to understand their definitions first:

sentence s

A sentence ends with '.', '!' or '?' followed by a newline, space or tab. Any number of closing brackets
and quotation marks may appear between closing punctuation and whitespace characters: ')', ']', '"' and '''. Paragraph and subsection boundaries are also considered sentence boundaries.
If
'cpoptions' contains 'J' flag, at least two spaces after punctuation must appear, and tabs
are not considered whitespace.

Our sentence does not represent a line in encoding, it strictly obeys the definition above.

paragraph p

A paragraph begins with each blank line or a paragraph macro
defined by a pair of characters in the 'paragraphs' option. Its default value is "IPLPPPQPP TPHPLIPpLpItpplpipbp", that is, the macros ".IP", ".LP",
etc. (these are nroff macros, so the period must appear in the first column). Section boundaries are also considered paragraph boundaries.
Note that blank lines (lines containing only whitespace) are not paragraph boundaries.
Also note: this does not include '{' or '}' occurrences in the first column. But if the '{' flag is included in 'cpoptions'
, then the first column '{' can be used as a paragraph boundary posix.

the case

For example, the cursor is now as shown in the figure:
insert image description here

Think about pressing vis, what will we select?
insert image description here
Here the sentences are bounded by the boundaries of the paragraphs.

We return to the original state and press vip:
insert image description here

Now add a full stop on the original basis.
insert image description here
At this time vis, the part before the space is selected as a sentence.
insert image description here

Summarize

Sentences seem tasteless to use in code. In my initial understanding, a sentence should be a line, but I figured it out because the line already has many shortcut operations. For example, select a line: V, repeat: yy ddand so on, there is really no need to do more.

Paragraphs can be used between blank lines: { or }jumps, which are more common.

Guess you like

Origin blog.csdn.net/sayWhat_sayHello/article/details/123176119