.config/nvim/after/ftplugin/python.vim (view raw)
1set shiftwidth=4 tabstop=4 softtabstop=4 expandtab autoindent smartindent
2
3setlocal path=.,**
4setlocal wildignore=*/__pycache__/*,*.pyc
5
6set include=^\\s*\\(from\\\|import\\)\\s*\\zs\\(\\S\\+\\s\\{-}\\)*\\ze\\($\\\|\ as\\)
7
8function! PyInclude(fname)
9 let parts = split(a:fname, ' import ')
10 let l = parts[0]
11 if len(parts) > 1
12 let r = parts[1]
13 let joined = join([l, r], '.')
14 let fp = substitute(joined, '\.', '/', 'g') . '.py'
15 let found = glob(fp, 1)
16 if len(found)
17 return substitute(joined, '\.', '/', 'g') . '.py'
18 endif
19 endif
20 return substitute(joined, '\.', '/', 'g') . '.py'
21endfunction
22
23setlocal includeexpr=PyInclude(v:fname)
24setlocal define=^\\s*\\<\\(def\\\|class\\)\\>