Skip to content

Instantly share code, notes, and snippets.

@SamWhited
Last active December 11, 2015 23:08
Show Gist options
  • Save SamWhited/4673991 to your computer and use it in GitHub Desktop.
Save SamWhited/4673991 to your computer and use it in GitHub Desktop.
Parse a .gitignore file in vim
" Load a .gitignore file from the current directory
" and parse it for use in Vim
let gitignore = '.gitignore'
if filereadable(gitignore)
let igstring = ''
for oline in readfile(gitignore)
let line = substitute(oline, '\s|\n|\r', '', "g")
if line =~ '^#' | con | endif
if line == '' | con | endif
if line =~ '^!' | con | endif
if line =~ '/$' | let igstring .= "," . line . "*" | con | endif
let igstring .= "," . line
endfor
let execstring = "set wildignore+=".substitute(igstring, '^,', '', "g")
execute execstring
endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment