0

I recently learned of the -w option to record inputs. Trying to "play them back" with -s, it seems the playback doesn't perfectly reproduce the edits in at least one way

  • backspaces, <80>kb, are inserted instead of deleting characters.

I'm curious if autoindents are also reproduced, though I can't contrive of an example of such an inconsistency.

Question

How can I reproduce a sequence of edits exactly? Is there an order to .vimrc or other scripts that need to be loaded before interpreting?

Example

I'll edit the file a.c with vim -w edits a.c. This results in the edits file

Aint main() {^Mabc<80>kb<80>kb<80>kbprintf("abc\n");^[o}^[:wq^M

where <80>kb is pressing backspace, and ^M and ^[ are pressing return. The resulting a.c appears as

int main() {
    printf("abc\n");
}

while running vim -s edits a.d results in

int main() {
    abc<80>kb<80>kb<80>kbprintf("abc\n");
}

Evidently the <80>'s haven't clobbered the preceding characters, and the kb's have appeared in the final file. It's the same result with :source! edits.

1 Answer 1

1

How can I reproduce a sequence of edits exactly?

Theoretically, by doing exactly what you did. It appears to not work as it should, though, so you should open an issue over there.

FWIW, <Backspace> should be ^H, not <80>kb. If you substitute all the <80>kbs in edits with ^Hs, then it should work fine.

Note that ^H is not ^ followed by H. It is a literal ^H, inserted via <C-v><C-h>. See :help i_ctrl-v or :help c_ctrl-v, depending on the context.

Note also that <80>kb is not actually a real character that can be inserted normally. It is internal garbage that even changes from operating system to operating system. Vim also does that when recording macros.

To perform the substitution mentioned above…

  1. Start a substitution with :%s/,
  2. insert a literal <80> with <C-k>PA,
  3. type kb/,
  4. insert a literal ^H with <Ctrl-v><Ctrl-h>,
  5. type the rest of the command, /g,
  6. press <CR> to execute it.

I only suggest that substitution as a way to a) temporarily fix the current issue and b) narrow down the problem. Doing that every time you use -w and -s would be unacceptable so this is definitely a bug that you should report.

Is there an order to .vimrc or other scripts that need to be loaded before interpreting?

There is an order, yes, but it is unrelated to the problem at hand.

3
  • 1
    <80>kb is the value of t_kb termcap entry. Mar 16 at 14:44
  • 1
    Yes. And for some reason, Vim handles it correctly when playing back macros while it craps out in the context of -w and -s. FWIW, the exact same thing happens with <Left> (<80>kl) and friends.
    – romainl
    Mar 16 at 15:01
  • 1
    I think it used to not even work in macro playback (or at least I recall having trouble with it) so I always remove them from macros I’m editing.
    – D. Ben Knoble
    Mar 16 at 19:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.