在 Vim 中,如何按一个字符将一个长字符串分成多行? [英] In Vim how do I split a long string into multiple lines by a character?
本文介绍了在 Vim 中,如何按一个字符将一个长字符串分成多行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这么长的正则表达式字符串
I have this long regex string
(\.#.+|__init__\.py.*|\.wav|\.mp3|\.mo|\.DS_Store|\.\.svn|\.png|\.PNG|\.jpe?g|\.gif|\.elc|\.rbc|\.pyc|\.swp|\.psd|\.ai|\.pdf|\.mov|\.aep|\.dmg|\.zip|\.gz|\.so|\.shx|\.shp|\.wmf|\.JPG|\.jpg.mno|\.bmp|\.ico|\.exe|\.avi|\.docx?|\.xlsx?|\.pptx?|\.upart)$
我想用 |
分割它并将每个组件放在一个新行上.
and I would like to split it by |
and have each component on a new line.
最终的形式是这样的
(\.#.+|
__init__\.py.*|
\.wav|
\.mp3|
\.mo|
\.DS_Store|
... etc
我知道我可能可以用宏来做这件事,但我认为更聪明的人可以找到更快/更简单的方法.
I know I can probably do this as a macro, but I figured someone smarter can find a faster/easier way.
感谢任何提示和帮助.谢谢!
Any tips and helps are appreciated. Thanks!
推荐答案
试试这个:
:s/|/|\r/g
以上内容适用于当前行.
The above will work on the current line.
要对整个文件执行替换,请在 s 前添加 %
:
To perform the substitution on the entire file, add a %
before the s:
:%s/|/|\r/g
细分:
: - enter command-line mode
% - operate on entire file
s - substitute
/ - separator used for substitute commands (doesn't have to be a /)
| - the pattern you want to replace
/ - another separator (has to be the same as the first one)
|\r - what we want to replace the substitution pattern with
/ - another separator
g - perform the substitution multiple times per line
这篇关于在 Vim 中,如何按一个字符将一个长字符串分成多行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文