├── README.md ├── autoload └── python │ └── utils.vim ├── compiler └── python.vim ├── ftdetect └── python.vim └── plugin └── autocmd.vim /README.md: -------------------------------------------------------------------------------- 1 | # Installation 2 | 3 | Django command depends on the [vim-dispatch](https://github.com/tpope/vim-dispatch) module, therefore it is necessary to install it. For installation modules and packages in vim, I use a lightweight package manager - [vim-plug](https://github.com/junegunn/vim-plug/wiki). In your vimrc: 4 | 5 | ``` 6 | Plug 'tpope/vim-dispatch' 7 | 8 | if has('nvim') 9 | " Adds neovim support to vim-dispatch 10 | Plug 'radenling/vim-dispatch-neovim' 11 | endif 12 | 13 | Plug 'aliev/vim-python' 14 | ``` 15 | 16 | [vim-dispatch](https://github.com/tpope/vim-dispatch) will allow run the external commands asynchronously, without exiting from Vim. As we know running external commands blocks vim. As the backend for vim-dispatch, I recommend using tmux. If you're using neovim, you don't need tmux. 17 | 18 | # Env options 19 | 20 | Ignore Python warnings (very useful for vim-htmldjango_omnicomplete plugin) 21 | 22 | ``let $PYTHONWARNINGS="ignore"`` 23 | 24 | # Python Compiler 25 | 26 | Compiler options: 27 | 28 | ``let g:python_compiler_fixqflist = 1`` 29 | -------------------------------------------------------------------------------- /autoload/python/utils.vim: -------------------------------------------------------------------------------- 1 | " Sometimes Python issues debugging messages 2 | " which don't belong to a call stack context 3 | " this function filters these messages 4 | function! python#utils#fix_qflist() " {{{ 5 | let l:traceback = [] 6 | let l:qflist = getqflist() 7 | 8 | for l:item in l:qflist 9 | if !empty(l:item.type) 10 | call add(l:traceback, l:item) 11 | endif 12 | endfor 13 | 14 | if !empty(l:traceback) 15 | call setqflist(l:traceback) 16 | endif 17 | endfunction " }}} 18 | -------------------------------------------------------------------------------- /compiler/python.vim: -------------------------------------------------------------------------------- 1 | " Vim compiler file 2 | " Compiler: Unit testing tool for Python 3 | " Maintainer: Ali Aliev 4 | " Last Change: 2015 Nov 2 5 | 6 | if exists("current_compiler") 7 | finish 8 | endif 9 | 10 | let current_compiler = "python" 11 | 12 | if exists(":CompilerSet") != 2 " older Vim always used :setlocal 13 | command -nargs=* CompilerSet setlocal 14 | endif 15 | 16 | " Disable Python warnings 17 | if !exists('$PYTHONWARNINGS') 18 | let $PYTHONWARNINGS="ignore" 19 | endif 20 | 21 | " For Flake8 first 22 | CompilerSet efm =%E%f:%l:\ could\ not\ compile, 23 | CompilerSet efm +=%-Z%p^, 24 | CompilerSet efm +=%A%f:%l:%c:\ %t%n\ %m, 25 | CompilerSet efm +=%A%f:%l:\ %t%n\ %m, 26 | 27 | " Python errors are multi-lined. They often start with 'Traceback', so 28 | " we want to capture that (with +G) and show it in the quickfix window 29 | " because it explains the order of error messages. 30 | 31 | CompilerSet efm +=%+GTraceback%.%#, 32 | 33 | " The error message itself starts with a line with 'File' in it. There 34 | " are a couple of variations, and we need to process a line beginning 35 | " with whitespace followed by File, the filename in "", a line number, 36 | " and optional further text. %E here indicates the start of a multi-line 37 | " error message. The %\C at the end means that a case-sensitive search is 38 | " required. 39 | CompilerSet efm +=%E\ \ File\ \"%f\"\\,\ line\ %l\\,%m%\\C, 40 | CompilerSet efm +=%E\ \ File\ \"%f\"\\,\ line\ %l%\\C, 41 | 42 | " The possible continutation lines are idenitifed to Vim by %C. We deal 43 | " with these in order of most to least specific to ensure a proper 44 | " match. A pointer (^) identifies the column in which the error occurs 45 | " (but will not be entirely accurate due to indention of Python code). 46 | CompilerSet efm +=%C%p^, 47 | 48 | " Any text, indented by more than two spaces contain useful information. 49 | " We want this to appear in the quickfix window, hence %+. 50 | CompilerSet efm +=%+C\ \ \ \ %.%#, 51 | CompilerSet efm +=%+C\ \ %.%#, 52 | 53 | " The last line (%Z) does not begin with any whitespace. We use a zero 54 | " width lookahead (\&) to check this. The line contains the error 55 | " message itself (%m) 56 | CompilerSet efm +=%Z%\\S%\\&%m, 57 | 58 | " We can ignore any other lines (%-G) 59 | CompilerSet efm +=%-G%.%# 60 | 61 | if filereadable("Makefile") 62 | CompilerSet makeprg=make 63 | else 64 | CompilerSet makeprg=python 65 | endif 66 | 67 | " vim:foldmethod=marker:foldlevel=0 68 | -------------------------------------------------------------------------------- /ftdetect/python.vim: -------------------------------------------------------------------------------- 1 | " Vim compiler file 2 | " Compiler: Unit testing tool for Python 3 | " Maintainer: Ali Aliev 4 | " Last Change: 2015 Nov 2 5 | 6 | autocmd FileType python compiler python 7 | -------------------------------------------------------------------------------- /plugin/autocmd.vim: -------------------------------------------------------------------------------- 1 | if !exists('g:python_compiler_fixqflist') 2 | let g:python_compiler_fixqflist = 1 3 | endif 4 | 5 | augroup python 6 | au! 7 | if g:python_compiler_fixqflist == 1 8 | au QuickFixCmdPost * call python#utils#fix_qflist() 9 | endif 10 | augroup end 11 | --------------------------------------------------------------------------------