25

私はこの長い正規表現文字列を持っています

(\.#.+|__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)$

|それを分割して、各コンポーネントを新しい行に配置したいと思います。

最終的な形でこのようなもの

(\.#.+|
__init__\.py.*|
\.wav|
\.mp3|
\.mo|
\.DS_Store|
... etc

おそらくこれをマクロとして実行できることはわかっていますが、より賢い人がより速く/より簡単な方法を見つけることができると思いました.

ヒントやヘルプをいただければ幸いです。ありがとう!

4

3 に答える 3

64

これを試してください:

:s/|/|\r/g

上記は現在の行で機能します。

ファイル全体で置換を実行する%には、s の前にa を追加します。

:%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
于 2013-05-31T06:06:43.903 に答える
19

の各インスタンス|をそれ自体と改行 ( \r)に置き換えます。

:s/|/|\r/g

(実行する前に、カーソルが問題の行にあることを確認してください)

于 2013-05-31T06:06:31.590 に答える
-4

実際に|は、パターンの前に追加する必要はありません。これを試してみるとs/,/,\r/g、改行の後にカンマがカンマに置き換えられます。

于 2015-11-19T04:35:39.223 に答える