~gpanders/dotfiles

ref: fe3c3c6d5c840bb713a7160d9c2d0b7f5885ea99 dotfiles/vim/.vim/after/ftplugin/python.vim -rw-r--r-- 1.3 KiB
fe3c3c6dGreg Anders Clean up plugins and use more consistent conventions 2 years ago
                                                                                
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
" Python specific settings
if &filetype !=# 'python'
  finish
endif

let b:undo_ftplugin = get(b:, 'undo_ftplugin', '')

" If a valid formatter executable is found, autoformat the buffer when writing
" the file
let g:python_format_on_write = 0

" gz opens a split window with a python shell
nmap <buffer> gz <Plug>(PytermOpen)

" Don't complete from include files (there are too many!)
setlocal complete-=i

" Use flake8 as makeprg for linting
compiler flake8

" Show boundary at 80 characters
let &l:colorcolumn = join(range(80, 336), ',')

" Populate path from python's sys.path. This is an expensive operation so we
" only call it once and then cache the result
if !exists('g:python_include_path')
  let g:python_include_path = python#include_path()
endif

let &l:path = &path . ',' . g:python_include_path

let b:undo_ftplugin .= '|setl path< cpt< cc<'

if executable('black')
  setlocal formatprg=black\ -q\ -
elseif executable('yapf')
  setlocal formatprg=yapf
endif

if !empty(&l:formatprg)
  augroup ftplugin.python
    autocmd!
    autocmd BufWritePre <buffer>
          \ if g:python_format_on_write |
          \   let view = winsaveview() |
          \   execute '%!' . &l:formatprg |
          \   call winrestview(view) |
          \   unlet view |
          \ endif
  augroup END
  let b:undo_ftplugin .= ' fp<|exe "au! ftplugin.python * <buffer>"'
endif