dotfiles/vim/.vim/after/ftplugin/python.vim

37 lines
1.2 KiB
VimL
Raw Normal View History

2023-05-26 09:06:10 +02:00
" Press F9 to run the script
autocmd FileType python map <buffer> <F9> :w<CR>:exec '!python3' shellescape(@%, 1)<CR>
autocmd FileType python imap <buffer> <F9> <esc>:w<CR>:exec '!python3' shellescape(@%, 1)<CR>
2022-12-18 14:54:56 +01:00
set tabstop=4 shiftwidth=4 autoindent smartindent expandtab
setlocal colorcolumn=80
setlocal path=.,**
setlocal wildignore+=*.pyc
" Add search in other files inside the path
set include=^\\s*\\(from\\\|import\\)\\s*\\zs\\(\\S\\+\\s\\{-}\\)*\\ze\\($\\\|\ as\\)
function! PyInclude(fname)
" Following examples:
" import conv.metrics
" /conv.metrics/
" conv/metrics.py
" from conv import conversion as conv (2)
" /conv import conversion/
" conv/conversion.py conv.py
let parts = split(a:fname, ' import ') " (1) [conv.metrics] (2) [conv, conversion]
let l = parts[0] " (1) conv.metrics (2) conv
if len ( parts ) > 1
let r = parts[1] " conversion
let joined = join([l,r], '.') " conv.conversion
let fp = substitute(joined, '\.', '/', 'g') . '.py'
let found = glob(fp, 1)
if len(found)
return found
endif
endif
return substitute(joined, '\.', '/', 'g') . '.py'
endfunction
setlocal includeexpr=PyInclude(v:fname)
setlocal define=^\\s*\\<\\(def\\\|class\\)\\>
2023-05-26 09:06:10 +02:00