tags:

views:

21706

answers:

6

I'm trying

:%s/,/\n/g

but it inserts what looks like a ^@ instead of an actual newline, the file is not on DOS mode or anything.

What should I do?

EDIT: If you are curious, like me, check this other question as well.

+47  A: 

Use \r instead of \n.

Konrad Rudolph
why does this work this way?
Vinko Vrsalovic
No idea. ;-) It just does and I never bothered to investigate. Shame on me. :-/
Konrad Rudolph
/r is treated as pressing the Enter/Return key. It works on all platforms.
Luka Marinko
+3  A: 

\r seems to work.

_Lasar
+2  A: 

You need to use :%s/,/^M/g To get the ^M character, press Ctrl+V followed by ENTER

dogbane
+1  A: 

Ctrl-V pastes the contents of Windows system buffer.

Hwan
+5  A: 

With Vim on Windows use Ctrl-Q in place of Ctrl-V

grantc
Thanks! I've been looking for that little tidbit.
Darcy Casselman
+12  A: 

Here's the trick: First, set your vi(m) session to allow pattern matching with special characters (ie: newline). It's probably worth putting this line in your .vimrc or .exrc file.

:set magic

Next, do:

:s/,/,^M/g

To get the ^M character, type ctrl-v and hit enter. Under Windows, do ctrl-q enter. The only way I can remember these is by remembering how little sense they make:

"What would be the worst control-character to use to represent a newline?"

"Either 'q' ( because it usually means "Quit") or 'v' because it would be so easy to type ctrl-c by mistake and kill the editor."

"Make it so."

Logan