LoginSignup
12
11

More than 5 years have passed since last update.

Unite.vimで.gitignoreで無視したファイルを候補から除外する

Last updated at Posted at 2013-08-22

Unite.vimでfile_recとかgrepとかでvendor/bundle以下のgemとかが出てきてウザいときがある。そこで.gitignoreで無視したファイルを候補から除外するように設定した。

.vimrc
" .gitignoreで指定したファイルと.git/以下のファイルを候補から除外する
function! s:unite_gitignore_source()
  let sources = []
  if filereadable('./.gitignore')
    for file in readfile('./.gitignore')
      " コメント行と空行は追加しない
      if file !~ "^#\\|^\s\*$"
        call add(sources, file)
      endif
    endfor
  endif
  if isdirectory('./.git')
    call add(sources, '.git')
  endif
  let pattern = escape(join(sources, '|'), './|')
  call unite#custom#source('file_rec', 'ignore_pattern', pattern)
  call unite#custom#source('grep', 'ignore_pattern', pattern)
endfunction
call s:unite_gitignore_source()

Vim Scriptはほとんど書いたことがないのでアレかもしれない。ただ.gitignoreを一行ずつロードしてリストに追加してjoinしてエスケープしてUnite.vimの設定に追加してるだけ。ついでに.git以下も除外するようにした。

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