LoginSignup
9
4

More than 5 years have passed since last update.

vimgrep & 検索と置換

Last updated at Posted at 2018-05-29

vim上でディレクトリ内一括検索・置換。
Sublime Text 3 でいう Cmd+Shift+f みたいな。

Usage

:vim [pattern] [targets]

もしくは

:vimgrep [pattern] [targets]

Patterns & Targets

unko という文字列を *.go のみに限定して検索したい場合

:vim /unko/ **/*.go

src ディレクトリ以下にある unko を検索したい場合

:vim /unko/ src/**/*

Quickfix

.vimrc に以下を記述すると、検索後に自動で Quickfix が起動する。

autocmd QuickFixCmdPost *grep* cwindow$

検索→置換

Quickfix を起動後、検索語句を一括置換したい。

:cdo %s/unko/UNKO/gc

で各ファイルの検索語句を置換できる。

:cdo %s/unko/UNKO/gc | update

なら置換後保存してくれる。

9
4
2

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
9
4