LoginSignup
2
1

More than 5 years have passed since last update.

vimでcamelCaseな文字列をchain-caseに置換する

Posted at

まずは結論から

置換対象のテキスト
longLongLongString
vim
:s/\v\C([a-z])([A-Z])/\1-\L\2/g
置換後のテキスト
long-long-long-string

vim特有のメタ文字について

\v -> very magic

素のvimの正規表現はPerl/Rubyなどの一般的な正規表現などとは異なり、正規表現のメタ文字をバックスラッシュでエスケープしなければなりません。
very magicモードにすると、メタ文字のエスケープが免除され、一般的な正規表現のように書ける。
(筆者はeregex.vim使う派)

\C -> case sensitive

ignorecaseしている場合でも大文字小文字を区別する。

\L -> lower case

マッチした文字列を小文字に変換

2
1
1

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