LoginSignup
6
6

More than 5 years have passed since last update.

Vim で特定ファイルの filetype を自動認識させる

Posted at

TL;DR

mkdir -p ~/.vim/ftdetect

cat <<EOF > ~/.vim/ftdetect/ruby.vim
au BufRead,BufNewFile Gemfile  set filetype=ruby
au BufRead,BufNewFile Rakefile set filetype=ruby
au BufRead,BufNewFile *.ru     set filetype=ruby
EOF

cat <<EOF > ~/.vim/ftdetect/perl.vim
au BufRead,BufNewFile cpanfile set filetype=perl
EOF

こんな感じで行けます。

Perl だと cpanfile ぐらいかなと思いますが、Ruby だと DSL ファイルなど、自動認識してくれないものが色々あるかもしれませんね。
modeline 1 を記すという手もありますが、書きたくないという場合は、上のように所定のパスに設定を配置しておくと、filetype を適用してくれます 2

GitHub に置いている自分の dotfiles にも反映していますので、ご参考まで。

脚注

6
6
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
6
6