In my Vim configuration, I have mapped the
<C-j> key to
<cmd>bn<CR>, but because the
C-j key corresponds to the null character in Vim, this causes some strange issues when defining macros. For instance, if I define a macro for
the macro executes the keystroke
<CR>, as expected. But if I try to define
@q directly with the keystrokes,
^M is the literal newline character, executing
@q behaves like
<CR><C-j>. And indeed, checking
:reg shows that
"q=^M^J when defined directly, and
"q=^M when defined via macro recording. It seems like this extra null character is only appended when the string ends in a carriage return.
I would like to be able to define
"q directly without this terminating null character. My solution for now has been to replace
^M^[. While this works for virtually all cases, it's not perfect (for instance, if the macro ends in the middle of a chord, the
<nop> would exit the chord).
Why does assignment and macro recording differ in this way? And is there a way to perform assign a register without this terminating null character?