【问题标题】:Vim change list behaviourVim 更改列表行为
【发布时间】:2014-11-14 09:44:30
【问题描述】:

我正在尝试了解 vim 上的更改列表,但无法理解以下行为:

例如,我插入以下文本:

I like chips and fish.

意识到我得到的名词顺序错误,所以我想得到:

I like fish and chips.

从没有 .vimrc (vim -u NONE) 的新 vim 实例开始,这正是我所做的(# 仅用于解释):

iI like chips and fish.<Esc>  # Insert text. Realize I want to switch the words
Fc                            # Jump back to 'chips'
de                            # Delete the word (and put it in anon register)
ff                            # Jump to the 'fish' word
vep                           # Select the word, and paste from anon register
g;                            # Try to jump back to the position where I change
                              # the word 'chips'. It doesn't work and I get:
E19: Mark has invalid line number

# To see what is going on i print the change list:
:changes
    change line  col text
        2     1   12 I like  and chips.
        1     2   12 -invalid-
    >

我的第一个问题是为什么跳跃一开始就不起作用?

其次,更改列表中的-invalid- 条目对我来说没有任何意义。如您所见,我从未超出第 1 行。为什么第 2 行有一个条目?

我正在使用 Vim 7.4.52

更新: -invalid- 似乎是一个错误。我已经举报了:

https://code.google.com/p/vim/issues/detail?id=283

【问题讨论】:

  • 感谢您的明确解释。这显然是一个错误。我已将patch 发布到 vim_dev 邮件列表。
  • 对不起,我看到你的评论晚了。只是为了让你知道我已经举报了。查看更新。

标签: vim changelist


【解决方案1】:

在 Mac OS X 上的默认 Vim(7.3 普通版,无 GUI,无补丁)中,g; 将光标移动到chips 中的c:changes 的输出与您的不同:

change line  col text
>   0     1   16 I like fish and chops.

仅记住一个变化的事实与:help g;的这一段一致

When two undo-able changes are in the same line and at a column position less
than 'textwidth' apart only the last one is remembered.  This avoids that a
sequence of small changes in a line, for example "xxxxx", adds many positions
to the change list.  When 'textwidth' is zero 'wrapmargin' is used.  When that
also isn't set a fixed number of 79 is used.  Detail: For the computations
bytes are used, not characters, to avoid a speed penalty (this only matters
for multi-byte encodings).

所以一切都很正常(如果有点令人惊讶的话)。

使用相当新的 MacVim (7.4.258),我得到了你为 g; 描述的行为和一个稍微不同的 :changes 输出(你的输出中缺少“鱼”):

change line  col text
    1     1   16 I like fish and chips.
>   0     2   16 -invalid-

闻起来很多就像你发现了一个错误,我强烈建议你通知the vim_dev mailing list(如果他们还不知道的话)。

【讨论】:

  • 总之:1)做g; 永远不会完成我想要的(因为它只会记住最后一次更改)。 2) -invalid- 可能是一个错误。对吗?
  • 是的,在文档中描述的限制范围内,是的。注意,你可以在跳转前使用m&lt;backtick&gt;来任意记住你来自哪里。
  • 我试图改进 Practical Vim 一书中第 151 页上的练习,正如你所说的那样,它在跳转前带有标记。在已经有另一个标记(来自更改列表)的地方放置标记似乎是多余的。遗憾的是,文档也有一个很好的观点,即只保留最后一次更改。
猜你喜欢
  • 1970-01-01
  • 2010-09-14
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多