Let's say I record a macro n that generates the following text:


When I ask for the content with "np it outputs:


So I append in .vimrc file:

let @n = 'i1^M2^M^['

if I save .vimrc and then I call it with @n in a new file, it outputs the string above literally.....

How should I represent the newline key in configuration file?

  • Macros are often a poor substitute for a mapping when you want to save them. Did you type ^ then M, or <C-v><C-m>?
    – D. Ben Knoble
    Feb 2 '20 at 1:53
  • 1
    Did you use "np to paste the escaped characters ^M and ^[ into the vim script?
    – Arnie97
    Feb 2 '20 at 3:31
  • 1
    @D.BenKnoble I typed ^ then M, the second way doest not work either.
    – sebelk
    Feb 2 '20 at 12:05

The solution I've found is:

let @n = "i1\n2\n\e"

however the following does not work:

let @n = 'i1\n2\n\e'

  • 3
    the following does not work Please, read :h expr-" and :h expr-'
    – Matt
    Feb 2 '20 at 12:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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