Sign in to follow this  
Elwren

printf + VIM

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"
#else
#define FOO "baz"
#endif

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this