为什么使用“ {”段落对段落进行不同的解释。 &quot}}&quot&quot动议与“ ap”和“ ip&quot?

发布于 2025-01-22 02:36:47 字数 555 浏览 1 评论 0原文

当使用{}在段落之间导航时,VIM似乎用白空间字符对待行,好像它们是段落的一部分,并跳过了它们。此行为已在多个线程中讨论,并给出的解释(基于:H段。

但是,这似乎与VIM对待apip命令的方式不一致, ip 命令实际上确实将用whitespace字符视为段落中断的行。例如,给定以下文本,前两个段落被非空线分开(包含空格),第二段和第三段用空行分开(假设光标在缓冲区的顶部开始)下面发生:

1  abc  # next line contains spaces
2      
3  def  # next line is blank
4  
5  jkl
  • }:将光标移至第4行(即,将行1-4视为段落)
  • dap:删除第1和2行(即,仅处理行1-2作为段落)

这两种行为似乎彼此不一致。为什么这两个命令在段落对象上的行为不同?

When using { or } to navigate between paragraphs, Vim appears to treat lines with white space characters as if they were part of the paragraph and skips past them. This behaviour has been discussed in a number of threads and the explanation given (based on :h paragraph) is that "a paragraph begins after each empty line", which is fine.

However, this does not appear to be consistent with the way Vim treats the ap and ip commands, which actually do treat lines with whitespace characters as paragraph breaks. For example, given the following text where the first two paragraphs are separated by a non-empty line (containing whitespace) and the second and third paragraphs are separated by an empty line (and assuming the cursor starts at the top of the buffer) the following occurs:

1  abc  # next line contains spaces
2      
3  def  # next line is blank
4  
5  jkl
  • }: moves the cursor to line 4 (i.e., treats lines 1-4 as a paragraph)
  • dap: deletes lines 1 and 2 (i.e., treats only lines 1-2 as a paragraph)

These two behaviours appear to be inconsistent with one another. Why do these two commands that operate on a paragraph object behave differently?

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

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

发布评论

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

评论(1

天赋异禀 2025-01-29 02:36:47

中所述:帮助AP:帮助IP

例外:空白行(仅包含白空间)也是段落边界。

因此,ap的行为是自愿与}的行为不同的,并且差异已清楚。但是,这种差异背后的确切理由是没有解释的,并且可能会随着时间的流逝而丢失。您可能需要在VIM的官方邮件列表中询问。

无论如何,我们可以稍微推断一下……

  • vim的}与VI的}一致。这是可以预期的,因为VIM的全部目的毕竟是对VI的令人信服的替补。
  • ap(以及文本对象的整个概念)是VIM。它不在VI中,因此没有现有的行为可以复制,而该功能的人则决定以比}更直观的方式对待“段落”。

As mentioned in :help ap and :help ip:

Exception: a blank line (only containing white space) is also a paragraph boundary.

So the behaviour of ap was made voluntarily different from that of } and the difference is clearly documented. The exact reasoning behind that difference is explained nowhere, though, and may be lost in time. You might want to ask on Vim's official mailing list.

Anyway, we can extrapolate a little…

  • Vim's } is consistent with vi's }. This is expected since Vim's whole purpose is, after all, to be a convincing stand-in for vi.
  • ap (and the whole concept of text objects) is a Vim thing. It wasn't in vi so there is no existing behaviour to replicate and the person who added that feature decided to make it treat "paragraphs" in a slightly more intuitive fashion than }.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文