LoginSignup
5
2

More than 5 years have passed since last update.

Vimで選択範囲をCamelCaseに変換

Posted at

シェルで、こういう関数を作っておく

.bashrc
camelcase() {
    perl -pe 's#(_|^)(.)#\u$2#g'
}

Fishユーザーはこっち

.config/fish/config.fish
function camelcase
    perl -pe 's#(_|^)(.)#\u$2#g'
end

これで、標準入力をCamelCaseに変換できる。

~> echo array_map | camelcase
ArrayMap

これだけでも結構便利なのだが、思い立ってVimで使ってみたらちょっと感動した。当然なんですが。

out.gif

余談

ちなみにsnake_caseはこうする。

function snakecase
    perl -pe 's#([A-Z])#_\L$1#g' | perl -pe 's#^_##'
end
5
2
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
5
2