vim c++ break line

2019-09-11 05:00发布

How can I break long lines when writing c++ code in vim? For example, if I have something like

56 fprintf(stderr, "Syntax error reading recursion value on 
57                line %d in file %s\n", line_count, filename);

I get the following compile errors:

:56:25: warning: missing terminating " character
:56: error: missing terminating " character
:57: error: stray ‘\’ in program
:57:37: warning: missing terminating " character
:57: error: missing terminating " character

I'm a vim newbie.

Thanks!

4条回答
太酷不给撩
2楼-- · 2019-09-11 05:35

That's not a Vim problem, that's a C problem.

Put quotes at the end of one line and the start of the other. Maybe you're looking for this:

fprintf(stderr, "Syntax error reading recursion value on "
                "line %d in file %s\n", line_count, filename);

...and if you want to know how to turn one-long-line into two, if you're splitting mid-string, go to where you want to split and then type 'i' followed by quote-enter-quote. Vim will follow your cindent rules when aligning the second line.

Alternatively, maybe it's a view problem? If you have a linebreak in there, it'll give you a compile error. However, in vim it is possible to have it appear to break the line, put set wrap and set lbr in your vimrc file. Check out :help lbr for info. There's also a way to configure the "leader" on the line, so you know it's a view-only linebreak.

查看更多
祖国的老花朵
3楼-- · 2019-09-11 05:42

Like Billy ONeal, I'm a bit confused why you're asking this as a Vim question. The code you need to write is:

fprintf(stderr, "Syntax error reading recursion value on "
                "line %d in file %s\n", line_count, filename);

Note that there's no comma - when you remove the extra whitespace, that's just two string literals together. They'll be combined into one, which I believe is exactly what you want.

查看更多
戒情不戒烟
4楼-- · 2019-09-11 05:44

Put a trailing \ on the end of the line you want to continue.

查看更多
倾城 Initia
5楼-- · 2019-09-11 05:54

my advice would be to not break the string -

instead do

    fprintf (stderr,  
             "Syntax error reading recursion value on line %d in file %s\n", 
             line_count, 
             filename);
查看更多
登录 后发表回答