1" Vim filetype plugin file 2" Language: python 3" Maintainer: Tom Picton <[email protected]> 4" Previous Maintainer: James Sully <[email protected]> 5" Previous Maintainer: Johannes Zellner <[email protected]> 6" Last Change: Wed, 20 December 2017 7" https://github.com/tpict/vim-ftplugin-python 8 9if exists("b:did_ftplugin") | finish | endif 10let b:did_ftplugin = 1 11let s:keepcpo= &cpo 12set cpo&vim 13 14setlocal cinkeys-=0# 15setlocal indentkeys-=0# 16setlocal include=^\\s*\\(from\\\|import\\) 17setlocal includeexpr=substitute(v:fname,'\\.','/','g') 18setlocal suffixesadd=.py 19setlocal comments=b:#,fb:- 20setlocal commentstring=#\ %s 21 22setlocal omnifunc=pythoncomplete#Complete 23if has('python3') 24 setlocal omnifunc=python3complete#Complete 25endif 26 27set wildignore+=*.pyc 28 29let b:next_toplevel='\v%$\|^(class\|def\|async def)>' 30let b:prev_toplevel='\v^(class\|def\|async def)>' 31let b:next_endtoplevel='\v%$\|\S.*\n+(def\|class)' 32let b:prev_endtoplevel='\v\S.*\n+(def\|class)' 33let b:next='\v%$\|^\s*(class\|def\|async def)>' 34let b:prev='\v^\s*(class\|def\|async def)>' 35let b:next_end='\v\S\n*(%$\|^(\s*\n*)*(class\|def\|async def)\|^\S)' 36let b:prev_end='\v\S\n*(^(\s*\n*)*(class\|def\|async def)\|^\S)' 37 38execute "nnoremap <silent> <buffer> ]] :call <SID>Python_jump('n', '". b:next_toplevel."', 'W')<cr>" 39execute "nnoremap <silent> <buffer> [[ :call <SID>Python_jump('n', '". b:prev_toplevel."', 'Wb')<cr>" 40execute "nnoremap <silent> <buffer> ][ :call <SID>Python_jump('n', '". b:next_endtoplevel."', 'W', 0)<cr>" 41execute "nnoremap <silent> <buffer> [] :call <SID>Python_jump('n', '". b:prev_endtoplevel."', 'Wb', 0)<cr>" 42execute "nnoremap <silent> <buffer> ]m :call <SID>Python_jump('n', '". b:next."', 'W')<cr>" 43execute "nnoremap <silent> <buffer> [m :call <SID>Python_jump('n', '". b:prev."', 'Wb')<cr>" 44execute "nnoremap <silent> <buffer> ]M :call <SID>Python_jump('n', '". b:next_end."', 'W', 0)<cr>" 45execute "nnoremap <silent> <buffer> [M :call <SID>Python_jump('n', '". b:prev_end."', 'Wb', 0)<cr>" 46 47execute "onoremap <silent> <buffer> ]] :call <SID>Python_jump('o', '". b:next_toplevel."', 'W')<cr>" 48execute "onoremap <silent> <buffer> [[ :call <SID>Python_jump('o', '". b:prev_toplevel."', 'Wb')<cr>" 49execute "onoremap <silent> <buffer> ][ :call <SID>Python_jump('o', '". b:next_endtoplevel."', 'W', 0)<cr>" 50execute "onoremap <silent> <buffer> [] :call <SID>Python_jump('o', '". b:prev_endtoplevel."', 'Wb', 0)<cr>" 51execute "onoremap <silent> <buffer> ]m :call <SID>Python_jump('o', '". b:next."', 'W')<cr>" 52execute "onoremap <silent> <buffer> [m :call <SID>Python_jump('o', '". b:prev."', 'Wb')<cr>" 53execute "onoremap <silent> <buffer> ]M :call <SID>Python_jump('o', '". b:next_end."', 'W', 0)<cr>" 54execute "onoremap <silent> <buffer> [M :call <SID>Python_jump('o', '". b:prev_end."', 'Wb', 0)<cr>" 55 56execute "xnoremap <silent> <buffer> ]] :call <SID>Python_jump('x', '". b:next_toplevel."', 'W')<cr>" 57execute "xnoremap <silent> <buffer> [[ :call <SID>Python_jump('x', '". b:prev_toplevel."', 'Wb')<cr>" 58execute "xnoremap <silent> <buffer> ][ :call <SID>Python_jump('x', '". b:next_endtoplevel."', 'W', 0)<cr>" 59execute "xnoremap <silent> <buffer> [] :call <SID>Python_jump('x', '". b:prev_endtoplevel."', 'Wb', 0)<cr>" 60execute "xnoremap <silent> <buffer> ]m :call <SID>Python_jump('x', '". b:next."', 'W')<cr>" 61execute "xnoremap <silent> <buffer> [m :call <SID>Python_jump('x', '". b:prev."', 'Wb')<cr>" 62execute "xnoremap <silent> <buffer> ]M :call <SID>Python_jump('x', '". b:next_end."', 'W', 0)<cr>" 63execute "xnoremap <silent> <buffer> [M :call <SID>Python_jump('x', '". b:prev_end."', 'Wb', 0)<cr>" 64 65if !exists('*<SID>Python_jump') 66 fun! <SID>Python_jump(mode, motion, flags, ...) range 67 let l:startofline = (a:0 >= 1) ? a:1 : 1 68 69 if a:mode == 'x' 70 normal! gv 71 endif 72 73 if l:startofline == 1 74 normal! 0 75 endif 76 77 let cnt = v:count1 78 mark ' 79 while cnt > 0 80 call search(a:motion, a:flags) 81 let cnt = cnt - 1 82 endwhile 83 84 if l:startofline == 1 85 normal! ^ 86 endif 87 endfun 88endif 89 90if has("browsefilter") && !exists("b:browsefilter") 91 let b:browsefilter = "Python Files (*.py)\t*.py\n" . 92 \ "All Files (*.*)\t*.*\n" 93endif 94 95if !exists("g:python_recommended_style") || g:python_recommended_style != 0 96 " As suggested by PEP8. 97 setlocal expandtab shiftwidth=4 softtabstop=4 tabstop=8 98endif 99 100" First time: try finding "pydoc". 101if !exists('g:pydoc_executable') 102 if executable('pydoc') 103 let g:pydoc_executable = 1 104 else 105 let g:pydoc_executable = 0 106 endif 107endif 108" If "pydoc" was found use it for keywordprg. 109if g:pydoc_executable 110 setlocal keywordprg=pydoc 111endif 112 113let &cpo = s:keepcpo 114unlet s:keepcpo 115