I'm trying to configure the NERDCommenter plugin to handle multiline ruby comments (i.e., nested inside =begin and =end).

The relevant setting is something like this:

let g:NERDCustomDelimiters = {
    \ 'ruby': {'left': '# ', 'leftAlt': "=begin\n", 'rightAlt': "\n=end" }
    \ }

except this gives me the ^@ control character instead of an actual newline.

Found this in a primer on vimscript

Note that strings can be specified with either double-quotes or single-quotes as delimiters. Double-quoted strings honor special "escape sequences" such as "\n" (for newline), "\t" (for tab), "\u263A" (for Unicode smiley face), or "\" (for the escape character).

and made sure to place the strings inside double quotes. Still no dice. What gives?

  • If you double escape the newline (\\n instead of \n), does it change anything? I had a similar problem, and I remember solving it by putting one or more backslashes in front of the newline character. If a double escape fails, maybe try with 3 or 4 escapes.
    – saginaw
    Commented Jan 24, 2016 at 11:43
  • I actually tried that, but it just escapes the first backslash, returning a literal "\n" string.
    – Ryan Lue
    Commented Jan 24, 2016 at 15:03

1 Answer 1


^@, if you look at man ascii, is the ASCII NUL character. That makes me think this has to do with how newlines are inserted in the replacement string of a :substitute command. From :h :s%:

  <CR>        split line in two at this point
              (Type the <CR> as CTRL-V <Enter>)                  s<CR>
  \r          idem                                               s/\r
  \<CR>       insert a carriage-return (CTRL-M)
              (Type the <CR> as CTRL-V <Enter>)                  s/\<CR>
  \n          insert a <NL> (<NUL> in the file)
              (does NOT break the line)     

Since \n inserts a <NUL>, perhaps you should try \r=end.

  • You know, I was going to mention that I'd tried this, too. Unfortunately, I just get another control character (^M).
    – Ryan Lue
    Commented Jan 24, 2016 at 18:25
  • @RyanLue and ^M is the carriage return. Odd. I'll have to experiment a bit.
    – muru
    Commented Jan 24, 2016 at 18:27
  • @muru Have you succeeded in the experiments ? Having the similar problem here, doing :'<,'>s/\n/\n\n/ produces ^@^@ instead of newlines, and joins the lines. Even just s/\n/\n/ gives ^@ Commented Feb 19, 2018 at 2:44
  • @SergiyKolodyazhnyy try s/\n/\r\r/.
    – muru
    Commented Feb 19, 2018 at 2:46
  • @muru that does produce a newline after each line, but it also produces two newlines after the very last one. Commented Feb 19, 2018 at 2:50

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.