11
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Vim正規表現-特訓#1]Vimで複数行にまたがる条件で検索

Last updated at Posted at 2015-10-21

課題

改行が含まれる条件で検索したい

From vim help

\.
Matches any single character or end-of-line.
Careful: "\
.*" matches all text to the end of the buffer!

要は_.は改行と文字種全てにマッチします。

実践1

  • HIGE~HEGE区間を検索
HAGEHIGE
HUGE
HEGEHOGE

[最長マッチ検索版]
/HIGE\_.*HEGE

最長マッチ/最小マッチの違いはまた今度。

実践2

  • C/C++のボックスコメントを検索
/*
 * HAGE
 * HIGE
 * HUGE
 * HEGE
 * HOGE
 */

以下で検索します。
/\/\*\_.\{-}\*\/

/:検索
\/\*:ブロックコメントの最初/*
\_.\{-}: 改行含む文字部が0個以上
\*\/:ブロックコメントの最後*/

11
13
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
11
13

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?