Jump to content
  • Advertisement
Sign in to follow this  

printf + VIM

This topic is 4885 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
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"
#define FOO "baz"

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

Share this post

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

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!