4

In expression :s/foo/bar\n/g When replacing \n inserts a null byte, according to the docs I have to use \r. Since I insert newlines more frequently than null bytes, is there a way to change this mapping?

So I want :s/foo/bar\n/g to insert a newline, not nullbyte.

6

You could do this via a :cnoremap <expr> \r that checks (via getcmdtype() and getcmdpos()) that the current command-line is a :s Ex command, and you're editing the replacement part.

I would recommend against this, and just accept and learn that \r has to be used. Otherwise, you'll become dependent on your mapping and will struggle on systems that are not yours / do not have your configuration.

  • 2
    aren't we all ? I mean, I cannot efficiently use vim without my own vimrc. – Mathieu Westphal May 18 '15 at 15:21
  • That's why you keep your vimrc on github or bitbucket and pull it down to the new machine. – Jonathan Landrum May 20 '15 at 14:09

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.