I'm trying to grok the change list on vim and I'm having trouble understanding the following behavior:
As example I insert the following text:
I like chips and fish.
Realized I got the nouns in the wrong order, so I want to get:
I like fish and chips.
Starting with a fresh vim instance with no .vimrc (vim -u NONE) this is exactly what I do (# are just for explanation):
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-
>
My first question is why the jump didn't work in the first place?
Second, the -invalid- entry of the change list doesn't make any sense to me. As you saw I never went beyond line 1. Why is an entry with line 2?
Im using Vim 7.4.52
Update: The -invalid- seems to be a bug. I already reported it:
https://code.google.com/p/vim/issues/detail?id=283
In the default Vim on Mac OS X (7.3 Normal version without GUI, no patches), g; moves the cursor to the c in chips and the output of :changes is different from yours:
change line col text
> 0 1 16 I like fish and chops.
The fact that only one change is remembered is consistent with this paragraph from :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).
so everything is normal (if a bit surprising).
With a reasonably recent MacVim (7.4.258), I get the behavior you describe for g; and a slightly different :changes output ("fish" is missing in yours):
change line col text
1 1 16 I like fish and chips.
> 0 2 16 -invalid-
It smells a lot like you discovered a bug and I strongly suggest you notify the vim_dev mailing list about it (if they are not already aware).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With