-
Notifications
You must be signed in to change notification settings - Fork 1
/
subvimrc.vim
62 lines (55 loc) · 1.95 KB
/
subvimrc.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
" Vim plugin to load per-project .vimrc files. This will look for files named
" '.subvimrc' in subdirectories of files you open and automatically source
" them to enable one to make per project vimrc settings.
"
" Language: Python
" Author: Brandon Bickford <[email protected]>
" Last Change: 2010 June 27
" License: Copyright 2010 Brandon Bickford
" This program is free software: you can redistribute it and/or modify
" it under the terms of the GNU General Public License as published by
" the Free Software Foundation, either version 3 of the License, or
" (at your option) any later version.
"
" This program is distributed in the hope that it will be useful,
" but WITHOUT ANY WARRANTY; without even the implied warranty of
" MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
" GNU General Public License for more details.
"
" You should have received a copy of the GNU General Public License
" along with this program. If not, see <http://www.gnu.org/licenses/>.
"
" Version: 1.0
function! s:SubVimRCInit()
python << endpython
import vim
import os.path
import sys
VIMRC_NESTED = ".subvimrc"
class SubVimRCInit(object):
def __init__(self):
self.cache = set()
def on_read(self):
filename = vim.current.buffer.name
if not filename:
return
filename = os.path.abspath(filename)
dirname, _ = os.path.split(filename)
while True:
if dirname in self.cache:
break
self.cache.add(dirname)
conf_name = os.path.join(dirname, VIMRC_NESTED)
if os.path.exists(conf_name):
vim.command("source " + conf_name)
new_dirname, _= os.path.split(dirname)
if new_dirname == dirname:
break
dirname = new_dirname
_subvimrc = SubVimRCInit()
endpython
endfunction
if has("python")
call s:SubVimRCInit()
au BufRead,BufNewFile * :py _subvimrc.on_read()
endif