Why does replacement of something by using :%s/,/\n/gc in vim gives me ^@ instead of giving me newline. Sed replacement works perfectly sed s/,/'\n'/g. Any idea how to do sed thingy in Vim and save time.


Simply because a line break in the replacement component of the substitution command is represented by \r in Vim rather than \n...


Alernatively, you can use this:


Where the ^M is entered by typing Ctrl+V then Enter

See :h s/\r and :h s/<CR>

FYI using \n will...

insert a <NL> (<NUL> in the file) (does NOT break the line)

...to quote :h s/\n


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