简体   繁体   中英

How remove text wrap using vim text editor?

I'm trying to write a vim script for remove the text wrap, I am using the following code but it's doesn't provide exact output. eg \\string{this indicate newline} if "this" appears in first line, "indicate" is in second line etc then how I remove text wrap. Is it possible?

:%s/\\string{\zs\(\_[^}]*\)\ze}/\1/gec

Edit based on OP's comment:

for example (i/p): \string{1 <enterkey> 2 <enterkey> 3 <enterkey> 
4 <enterkey> 5 <enterkey>}. i need (o/p) \string{1 2 3 4 5}. 

Before I have:

\string{1
2
3
4
5
}

After I want:

\string{1 2 3 4 5}

Before I have (new pattern):

\string{1 
{2} 
{3} 
4 
5}

After I want:

\string{1 {2} {3} 4 5}

This line does what you want:

%s/\\string{\_[^}]*/\=substitute(submatch(0),"\n",' ','g')/

it changes:

foobar
\string{1
2
3
4
5
}
foobar

into:

foobar
\string{1 2 3 4 5 }
foobar

It would be easier to understand your question if you gave a longer example of text, and what you want to do with it. If I understand correctly, you could like to remove the line wrap on lines that contain \\\\string{this .

You could use :%g/\\\\string{this/j . It executes the j command on every line matching the \\\\string{this pattern.

Input:

some text
\string{this
indicate}
more text

Turns into:

some text
\string{this indicate}
more text

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM