printf + VIM

Recommended Posts

Elwren    122
Hey, I'm using VIM to code in and came to a silly issue where I have really long strings that go past the desired 80 column length. How do I separate this string into different lines? I thought it would be a '\' at the end of the line but this doesn't work. I tried google'n it but wasn't really sure what to search for. Thanks for the help.

Share on other sites
ApochPiQ    23061
You can split a string literal by using double-double quotes:

"This ""string ""is ""concatenated ""into ""a single ""line by ""the compiler."// Equivalent to:"This string is concatenated into a single line by the compiler."

This will work as long as the only characters between two pairs of quotes is whitespace. For instance, you can do "half a " _______ "half b" (where underscores are meant to be spaces).

You can even get really crazy and do things like "This ""is ""a ""total ""waste ""of ""quotes." Some portability macros use this trick for platform-specific strings, e.g.:

#ifdef _WIN32 #define FOO "bar"#else #define FOO "baz"#endifprintf("This is "FOO" country.\n");