configuration/config/nvim/ftplugin/python.vim

41 lines
1013 B
VimL
Raw Normal View History

2015-12-29 21:26:04 +01:00
" Interactive
nnoremap <buffer> <Leader>i :terminal python -i '%'<CR>
" Lint
2015-12-29 21:46:22 +01:00
function! Pylint()
2015-12-29 21:26:04 +01:00
silent !pylint --reports=n --output-format=parseable '%' > /tmp/errors.err 2> /dev/null
cfile
silent !rm /tmp/errors.err
redraw!
copen
endfunction
nnoremap <buffer> <Leader>x :call Pylint()<CR>
" Folding
2015-12-29 21:46:22 +01:00
function! PythonFold(lnum)
2015-12-29 21:26:04 +01:00
if getline(a:lnum-1) =~ '^\s*def\s' || getline(a:lnum-1) =~ '^\s*class\s'
return indent(a:lnum-1) / 4 + 1
endif
if getline(a:lnum) =~ '^\s*def\s' || getline(a:lnum) =~ '^\s*class\s'
return indent(a:lnum) / 4
endif
if getline(a:lnum+1) =~ '^\s*def\s' || getline(a:lnum+1) =~ '^\s*class\s'
return indent(a:lnum + 1) / 4
endif
if getline(a:lnum+1) =~ '^\S.*$'
return '0'
endif
return '='
endfunction
2015-12-29 21:46:22 +01:00
function! PythonFoldText()
2015-12-29 21:26:04 +01:00
return repeat(' ', indent(v:foldstart - 1) + 4) . '+'
endfunction
setlocal foldmethod=expr
setlocal foldexpr=PythonFold(v:lnum)
setlocal foldtext=PythonFoldText()