LoginSignup
41
35

More than 5 years have passed since last update.

Vimでプロジェクト固有の設定を適用する

Posted at

基本の設定でははインデントはスペース2つ。
けど、プロジェクトAではインデントをハードタブにしたい。

といった時にプロジェクト固有のVimの設定ができると便利。
もちろんできます。

.vimrc

まずは.vimrcにそれを実現する設定を記述

~/.vimrc
augroup vimrc-local
  autocmd!
  autocmd BufNewFile,BufReadPost * call s:vimrc_local(expand('<afile>:p:h'))
augroup END

function! s:vimrc_local(loc)
  let files = findfile('.vimrc.local', escape(a:loc, ' ') . ';', -1)
  for i in reverse(filter(files, 'filereadable(v:val)'))
    source `=i`
  endfor
endfunction

これで、.vimrc.localというファイルがあると、それを読み込んでくれるようになる。

.vimrc.local

あとは、下のようにプロジェクト固有の設定ファイルをつくってやればいい。

path_to_project/.vimrc.local
set noexpandtab
set tabstop=4
set shiftwidth=4

ついでに

.vimcrc.localをバージョン管理から除く

~/.gitconfig
[core]
    excludesfile = ~/.gitignore
~/.gitignore
.vimrc.local
41
35
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
41
35