For example, say I want to replace foo
with bar
on lines 1,3,11, and 15. How could I do that?
:1,15s/foo/bar
will replace foo
with bar
on lines 1-15. But I want to specify multiple individual lines (1,3,11,15), not a range (1-15).
For example, say I want to replace foo
with bar
on lines 1,3,11, and 15. How could I do that?
:1,15s/foo/bar
will replace foo
with bar
on lines 1-15. But I want to specify multiple individual lines (1,3,11,15), not a range (1-15).
1 つの方法::substitute
最初の行で を実行し、次の行で と同じ置換を繰り返し:&&
ます。
:execute '1s/foo/bar' | 5&& | 11&& | 15&&
別の方法::global
行内のみで一致するパターンでコマンドを使用します。
:g/\%1l\|\%5l\|\%11l\|\%15l/s/foo/bar
3 番目の方法: ループを使用します。
:for l in [1,5,11,15] | execute l.'s/foo/bar' | endfor
行番号はどのように思いつきますか?これが目視検査の手動プロセスである場合は、multiselect プラグインを利用できます。複数の連続していない範囲を選択でき、それらにコマンドを適用できます。
:MSExecCmd s/foo/bar