• Advertisement
Sign in to follow this  

printf + VIM

This topic is 4617 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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 this post


Link to post
Share on other sites
Advertisement
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"
#endif

printf("This is "FOO" country.\n");

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement