" Press F9 to run the script autocmd FileType python map :w:exec '!python3' shellescape(@%, 1) autocmd FileType python imap :w:exec '!python3' shellescape(@%, 1) 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\\)\\> let g:ale_fixers = { \ '*': ['remove_trailing_lines', 'trim_whitespace'], \ 'python': ['black', 'add_blank_lines_for_python_control_statements'], \} function! LoadVirtualEnv() if filereadable('./.venv/bin/activate') let g:virtualenv_path = getcwd() . '/.venv/bin/python' let g:python3_host_prog = g:virtualenv_path echo "Loaded virtual environment: " . g:virtualenv_path elseif filereadable('./venv/bin/activate') let g:virtualenv_path = getcwd() . '/venv/bin/python' let g:python3_host_prog = g:virtualenv_path echo "Loaded virtual environment: " . g:virtualenv_path else " If no virtualenv is found, fall back to the default Python " Check if variables exist before unsetting them if exists('g:virtualenv_path') unlet g:virtualenv_path endif if exists('g:python3_host_prog') unlet g:python3_host_prog endif endif endfunction autocmd BufEnter * call LoadVirtualEnv()