3
2

More than 5 years have passed since last update.

Vimの置換コマンドまとめ

Posted at

Vimの置換コマンドに関する、個人的なまとめです。

カーソル行上の文字列を置換

:s/置換前/置換後/

カーソル行以降の文字列を置換

:,$s/置換前/置換後/

ファイル上の文字列を置換

:%s/置換前/置換後/

5~10行目の文字列を置換

:5,10s/置換前/置換後/

ビジュアルモードで選択した範囲内の文字列を置換

:'<,'>s/置換前/置換後/

'<,'>は自動的に入力されます。

よく使うオプション

  • g : 複数の文字列を置換する。
  • c : 置換する前に1つ1つ確認する。

コマンドの末尾に付加して使用する。

参考

http://motw.mods.jp/Vim/substitution.html
https://www.softel.co.jp/blogs/tech/archives/4977

3
2
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
3
2