Vim更改列表行为

3

我将要理解vim的变更列表,但是我有困难理解以下行为:

例如,我插入了以下文本:

I like chips and fish.

我意识到名词的顺序错了,所以我想改为:

I like fish and chips.

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

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

1
感谢清晰的解释。那显然是一个错误。我已经在vim_dev邮件列表上发布了一个补丁 - Christian Brabandt
抱歉,我晚看到了你的评论。只是想让你知道我已经报告了它。请查看更新。 - Maximiliano Padulo
1个回答

2
在 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),我得到了您描述的行为和略微不同的<:changes>输出(在您的输出中缺少“fish”)。
change line  col text
    1     1   16 I like fish and chips.
>   0     2   16 -invalid-

它的意思是:“它闻起来很像你发现了一个错误,我强烈建议你通知vim_dev邮件列表(如果他们还不知道的话)。 ”

总结一下:1)执行“g;”永远无法实现我想要的效果(因为它只会记住该行上最后一次的更改)。2)"-invalid-"可能是一个bug。对吗? - Maximiliano Padulo
1
是的,在文档所描述的范围内可以这样做,而且是可以的。请注意,在跳转之前,您可以使用 m<backtick> 任意记住您来自哪里。 - romainl
我试图改进《实用 Vim》书第151页的练习,它按你所说的在跳转之前使用标记。只是在已经有另一个标记的地方放置标记似乎有点冗余(来自更改列表)。不幸的是,文档也有一个很好的观点,即仅保留行中的最后一次更改。 - Maximiliano Padulo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接