Skip to content

Instantly share code, notes, and snippets.

@koki-h
Created April 5, 2010 14:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save koki-h/356395 to your computer and use it in GitHub Desktop.
Save koki-h/356395 to your computer and use it in GitHub Desktop.
#!/bin/sh
# vim で、特定ファイル全部を、確認しながら置換する
# http://subtech.g.hatena.ne.jp/cho45/20100405/1270444967
# をシェルスクリプトにしてみた。
# $ replace-confirn /Foo/Bar/ *.txt のようにして使う。
# (変な引数を渡すと当然変な結果になるので注意)
# コマンドが起動するとvimが開き、パターンにマッチする部分がハイライト表示されるので
# そのまま置換するときはy、置換せずに次のマッチに飛ぶときはnをタイプする。
# すべてのファイルを表示し終わると普通のvimのコマンドモードになるので:qをタイプして終了する。
pattern=$1
shift
files=$*
vim -c "silent! argdo %s${pattern}gc | update" ${files}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment