0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

vimのvimgrep,Quickfix,cdoのまとめ

0
Posted at

稼働環境

Ubuntu 24.04.2 LTS
VIM - Vi IMproved 9.1

vimgrepの使い方

複数のファイルの検索、置換を扱う。

:vim[grep] {pattern} {file} ...
" カレントディレクトリ以下のあらゆるファイルを対象にする
:vim {pattern} **
" app/views以下のあらゆるファイルを対象にする(ディレクトリを再帰的に検索)
:vim {pattern} app/views/**
" カレントバッファを対象にする
:vim {pattern} %

Quickfix listの使い方

Quickfix list が開いたなら、そこから操作を行う。
あらかじめ次のスクリプトを.vimrcに追加しておくこと。
autocmdしなければ:copenする。

" 前へ
nnoremap [q :cprevious<CR>
" 次へ
nnoremap ]q :cnext<CR>
" 最初へ
nnoremap [Q :<C-u>cfirst<CR>
" 最後へ
nnoremap ]Q :<C-u>clast<CR>

autocmd QuickFixCmdPost *grep* cwindow

cdoの使い方

Quickfix listをまとめて置換してくれる。

:cdo %s/hoge/hige/ge | update

参考リンク

ー以上ー

0
1
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
0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?