开发者

In vim, how do I substitute a regex pattern with whitespace?

开发者 https://www.devze.com 2023-03-08 07:08 出处:网络
In my specific case I have (function(){ and I want to replace that with <whitespace char>xxx<whitespace char>

In my specific case I have

(function(){

and I want to replace that with

<whitespace char>xxx<whitespace char>

so it would go from

$('#myId').click(function(){do_something()})

to

$('#myId').clic开发者_如何学运维k xxx do_something()})

I've tried

:s%/(function(){/ xxx /g  

but it throws an error throws an error 'E486: Pattern not found' even though I can find just /(function(){/. Nor does trying to add a \s to the replacement text work.

(sorry about the weird formatting of this question. doesn't really flow well)


transposed the s and %

:s%/(function(){/ xxx /g  

should become

:%s/(function(){/ xxx /g  

I tried it and it works for me.

the former returns E486: Pattern not found: /(function(){/ xxx /g


Your only problem is that it should be :%s not :s%.

:% specifies the whole file as the range for the following Ex command.

:s% means use '%' as the regex separator character (instead of /). So in your query, you aren't finding "/(function" in the current line.


You have to escape some characters

:s%/\(function\(\)\{/ xxx /g  
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号