关于 Vim 中文本格式的问题

发布于 2024-11-14 21:35:49 字数 1410 浏览 2 评论 0原文

我使用 Vim 编写的文本不是代码,只是自由形式的书写。为此,我喜欢让 formatoptions 包含 w 标志,有时还包含 a 标志。

w 标志应该使得当一行以非空白字符结束时出现段落结束,而不是在第一个空白行(这是 Vim 默认的)。以下是帮助文档中的片段:

w   Trailing white space indicates a paragraph continues in the next line.
    A line that ends in a non-white character ends a paragraph.

a 标志使您在键入时自动重新格式化。例如,在下面有文本、w 和 a 的文档中,当我只键入“段落中的最后一行”而不是下面的内容时,行会重新格式化。

This it the first line of the paragraph. <cr>
The text in it reformats properly as I type <cr>
up to the last line of the paragraph, which is <cr>
right after this line, that is, just below here: <cr>
This is the last line of paragraph.<cr>
This is the first line of second paragraph. <cr>
Even though there is no blank line between <cr>
it and first paragraph, any reformatting of <cr>
the first paragraph ends at the last line <cr>
of first paragraph.<cr>
<cr>
This the the first line after second paragraph<cr>

现在回答我的问题: 使用 aw 标志,当我在第一段中键入时,重新格式化可以正常工作,即第二段保持不变。但有时我想使用 vap 选择当前段落。在我看来,设置了 w 标志后,应该只选择第一段。但事实上,在第一段中发出 vap 也会选择第二段,一直到带有 的空行,似乎忽略了 w< /code> 格式选项标志。

这是预期的行为吗?我错过了什么吗?为什么 vap 不只选择我所在的段落,该段落以第一行结束且没有尾随空格?

I'm using Vim to write text that isn't code, just free form writing. To do this I like to have formatoptions include the w flag and sometimes the a flag.

The w flag is supposed to make it so an end-of-paragraph occurs when a line ends in a non-blank character, rather than at first blank line (which is Vim default). Here is snippet from the help docs:

w   Trailing white space indicates a paragraph continues in the next line.
    A line that ends in a non-white character ends a paragraph.

The a flag makes reformatting automatic, as you type. For example, in document with text below and w and a flags the lines reformat as I type only up to the 'last line in paragraph' and not below.

This it the first line of the paragraph. <cr>
The text in it reformats properly as I type <cr>
up to the last line of the paragraph, which is <cr>
right after this line, that is, just below here: <cr>
This is the last line of paragraph.<cr>
This is the first line of second paragraph. <cr>
Even though there is no blank line between <cr>
it and first paragraph, any reformatting of <cr>
the first paragraph ends at the last line <cr>
of first paragraph.<cr>
<cr>
This the the first line after second paragraph<cr>

Now to my question:
With a and w flags the reformatting works properly as I type in the first paragraph, i.e, second paragraph remains untouched. But sometimes I want to select the current paragraph using vap. It seems to me that with the w flag set this should select only the first paragraph. But in fact issuing vap in first paragraph selects the second paragraph also, all the way down to the blank line with <cr>, seemingly ignoring the w formatoptions flag.

Is this expected behavior? Am I missing something? Why does vap not select only the paragraph I'm in, which ends at first line with no trailing whitespace?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

榆西 2024-11-21 21:35:49

如果您阅读 :h paragraph 的帮助,则不会提到“fo”设置。所以它
看起来 fo 设置并没有真正改变,它定义了一个段落。这可能是一个错误或不清楚的文档,因此您可能想在 vim-dev 邮件列表上讨论这个问题。

If you read the help at :h paragraph this does not mention the 'fo' setting. So it
looks like the fo setting does not really change, what defines a paragraph. This might be a bug or unclear documentation, so you might want to discuss this on the vim-dev mailinglist.

心在旅行 2024-11-21 21:35:49

:help text-objects:h paragraph 中,您可以看到 vim 的段落在每个空行之后开始,并且也在指定的一组段落宏中开始通过“段落”选项中的字符对。仅包含空格的空白行也是段落边界。

formatoptions 中的 w 标志仅在您键入时自动设置段落格式时有所不同:它将分割行并在不结束段落的行末尾留下空格。我认为帮助文本有点令人困惑。

From :help text-objects or :h paragraph you can see that a paragraph for vim begins after each empty line, and also at each of a set of paragraph macros, specified by the pairs of characters in the 'paragraphs' option. Blank lines containing only whitespace are also paragraph boundaries.

The w flag in formatoptions only makes a difference when autoformatting a paragraph as you type: it will split lines and leave whitespace at the end of lines which do not end a paragraph. I suppose the help text is a bit confusing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文