How to replace a character by a newline in Vim? -


i'm trying replace each , in current file new line:

:%s/,/\n/g  

but inserts looks ^@ instead of actual newline. file not in dos mode or anything.

what should do?

edit: if curious, me, check question why \r newline vim? well.

use \r instead of \n.

substituting \n inserts null character text. newline, use \r. when searching newline, you’d still use \n, however. asymmetry due fact \n , \r do different things:

\n matches end of line (newline), whereas \r matches carriage return. on other hand, in substitutions \n inserts null character whereas \r inserts newline (more precisely, it’s treated input <cr>). here’s small, non-interactive example illustrate this, using vim command line feature (in other words, can copy , paste following terminal run it). xxd shows hexdump of resulting file.

echo bar > test (echo 'before:'; xxd test) > output.txt vim test '+s/b/\n/' '+s/a/\r/' +wq (echo 'after:'; xxd test) >> output.txt more output.txt 
before: 0000000: 6261 720a                                bar. after: 0000000: 000a 720a                                ..r. 

in other words, \n has inserted byte 0x00 text; \r has inserted byte 0x0a.


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -