LoginSignup
29
21

More than 5 years have passed since last update.

vim - 複数ファイルの一括置換

Last updated at Posted at 2015-10-20

qfreplace.vim を使う

:grep で検索する
:copen で QuickFix を開く
:Qfreplace を実行して編集用バッファを開き、対象文字を置換する

bufdo、argdo を使う

vim a.txt b.txt c.txt d.txt e.txt

複数ファイルを一括で加工する (bufdo)
:bufdo :%s/abc/xyz/ge | :update

開いているファイルのうち、いくつかを選んで加工する (argdo)
:args a.txt b.txt
:argdo :%s/abc/xyz/ge | :update

さらに対象ファイルを増やす (argadd)
:args a.txt b.txt
:argadd c.txt d.txt

対象から外す (argdelete)
:args a.txt b.txt c.txt
:argdelete c.txt

新たにリストを作成する (args + 引数 によりリストを新規にする)
:args a.txt b.txt

args で作ったリストは維持しつつも一時リストを作り編集する (arglocal)
:split " ウインドウを開く
:arglocal
:argadd f.txt g.txt
:argdo :%s/abc/xyz/ge | :update
:close

29
21
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
29
21