0

If I save a macro by typing:

:let @s='/{<C-v><C-m>'<Enter>

which looks like:

:let @s='/{^M'

the macro that is actually saved is /{^M^M, with an extra linebreak (that I did not type) appended at the end, and not /{^M (which I intended).

This can be seen by running the macro (@s), or by pasting the macro in the command-line mode by typing:

:let @s='<C-r>s'

What appears is:

:let @s='/{^M^M'

and not what I had originally wrote, which is:

:let @s='/{^M'

This only happens when I write macros in command-line mode, and not when I create macros with q.

I did a bit of testing and this seems to be the case with any macro ending with ^M.

What is the reason for this behavior, and how do I disable it?

I am using VIM 9.0 on Linux.

1

1 Answer 1

0

Others might be able to explain why, but using a literal <Nul> instead of a literal <CR> works:

:let @s = '/{<C-v><C-j>'<CR>
:reg s
Type name Content
  l  "s   /{^J

Frankly, the logic behind Vim's "handling" of <Nul>, <NL>, and <CR> has always been a bit of a puzzle for me. Committing arbitrary rules like "use \n for search and \r for replacement" kind of works for the day-to-day editing but it has never been intellectually satisfying.

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