2

How to insert newlines in vim?

For example in a file containing

test-classes; classes; xmlunit-1.3.jar

I am looking for the vim equivalent of sed command

sed -i 's/; /\n/g' classpath

to obtain

test-classes
classes
xmlunit-1.3.jar
3

You almost got it right, just use \r instead of \n:

:%s/; /\r/g
1
  • 3
    For non-vim variants of vi, you'd probably need to use a literal newline character instead of \r - which you can obtain by typing Ctrl-V Ctrl-M. This will display as ^M. – D_Bye Dec 7 '12 at 10:37

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.