(親記事はコチラ Vimコマンド&Script入門)
:vimgrep使います。
ヘルプから。
*:vim* *:vimgrep* *E682* *E683*
:vim[grep][!] /{pattern}/[g][j] {file} ...
Search for {pattern} in the files {file} ... and set
the error list to the matches. Files matching
'wildignore' are ignored; files in 'suffixes' are
searched last.
Without the 'g' flag each line is added only once.
With 'g' every match is added.
{pattern} is a Vim search pattern. Instead of
enclosing it in / any non-ID character (see
|'isident'|) can be used, so long as it does not
appear in {pattern}.
'ignorecase' applies. To overrule it put |/\c| in the
pattern to ignore case or |/\C| to match case.
'smartcase' is not used.
If {pattern} is empty (e.g. // is specified), the last
used search pattern is used. |last-pattern|
grepと使いかたは同じですね。
ではファイルを作成。
/tmp $ for i in {1..5};do echo HELLO$i>test_$i.txt;done
/tmp $ vim
ファイルは作成しますが、指定せずにVimを起動します。
:vimgrepを使って、文字列を検索してみましょう。
:vimgrep /HELLO/ *.txt
最初に見つかった文字列が存在するファイルが開いたようです。
検索結果一覧を表示します。
:copen

下の画面の検索結果からファイルを選択してEnterを押すと、上画面に選択したファイルが開きます。



コメント