xref: /vim-8.2.3635/runtime/ftplugin/python.vim (revision 46359e19)
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:	Thur, 09 November 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
23
24set wildignore+=*.pyc
25
26let b:next_toplevel='\v%$\|^(class\|def\|async def)>'
27let b:prev_toplevel='\v^(class\|def\|async def)>'
28let b:next_endtoplevel='\v%$\|\S.*\n+(def\|class)'
29let b:prev_endtoplevel='\v\S.*\n+(def\|class)'
30let b:next='\v%$\|^\s*(class\|def\|async def)>'
31let b:prev='\v^\s*(class\|def\|async def)>'
32let b:next_end='\v\S\n*(%$\|^(\s*\n*)*(class\|def\|async def)\|^\S)'
33let b:prev_end='\v\S\n*(^(\s*\n*)*(class\|def\|async def)\|^\S)'
34
35execute "nnoremap <silent> <buffer> ]] :call <SID>Python_jump('n', '". b:next_toplevel."', 'W')<cr>"
36execute "nnoremap <silent> <buffer> [[ :call <SID>Python_jump('n', '". b:prev_toplevel."', 'Wb')<cr>"
37execute "nnoremap <silent> <buffer> ][ :call <SID>Python_jump('n', '". b:next_endtoplevel."', 'W', 0)<cr>"
38execute "nnoremap <silent> <buffer> [] :call <SID>Python_jump('n', '". b:prev_endtoplevel."', 'Wb', 0)<cr>"
39execute "nnoremap <silent> <buffer> ]m :call <SID>Python_jump('n', '". b:next."', 'W')<cr>"
40execute "nnoremap <silent> <buffer> [m :call <SID>Python_jump('n', '". b:prev."', 'Wb')<cr>"
41execute "nnoremap <silent> <buffer> ]M :call <SID>Python_jump('n', '". b:next_end."', 'W', 0)<cr>"
42execute "nnoremap <silent> <buffer> [M :call <SID>Python_jump('n', '". b:prev_end."', 'Wb', 0)<cr>"
43
44execute "onoremap <silent> <buffer> ]] :call <SID>Python_jump('o', '". b:next_toplevel."', 'W')<cr>"
45execute "onoremap <silent> <buffer> [[ :call <SID>Python_jump('o', '". b:prev_toplevel."', 'Wb')<cr>"
46execute "onoremap <silent> <buffer> ][ :call <SID>Python_jump('o', '". b:next_endtoplevel."', 'W', 0)<cr>"
47execute "onoremap <silent> <buffer> [] :call <SID>Python_jump('o', '". b:prev_endtoplevel."', 'Wb', 0)<cr>"
48execute "onoremap <silent> <buffer> ]m :call <SID>Python_jump('o', '". b:next."', 'W')<cr>"
49execute "onoremap <silent> <buffer> [m :call <SID>Python_jump('o', '". b:prev."', 'Wb')<cr>"
50execute "onoremap <silent> <buffer> ]M :call <SID>Python_jump('o', '". b:next_end."', 'W', 0)<cr>"
51execute "onoremap <silent> <buffer> [M :call <SID>Python_jump('o', '". b:prev_end."', 'Wb', 0)<cr>"
52
53execute "xnoremap <silent> <buffer> ]] :call <SID>Python_jump('x', '". b:next_toplevel."', 'W')<cr>"
54execute "xnoremap <silent> <buffer> [[ :call <SID>Python_jump('x', '". b:prev_toplevel."', 'Wb')<cr>"
55execute "xnoremap <silent> <buffer> ][ :call <SID>Python_jump('x', '". b:next_endtoplevel."', 'W', 0)<cr>"
56execute "xnoremap <silent> <buffer> [] :call <SID>Python_jump('x', '". b:prev_endtoplevel."', 'Wb', 0)<cr>"
57execute "xnoremap <silent> <buffer> ]m :call <SID>Python_jump('x', '". b:next."', 'W')<cr>"
58execute "xnoremap <silent> <buffer> [m :call <SID>Python_jump('x', '". b:prev."', 'Wb')<cr>"
59execute "xnoremap <silent> <buffer> ]M :call <SID>Python_jump('x', '". b:next_end."', 'W', 0)<cr>"
60execute "xnoremap <silent> <buffer> [M :call <SID>Python_jump('x', '". b:prev_end."', 'Wb', 0)<cr>"
61
62if !exists('*<SID>Python_jump')
63  fun! <SID>Python_jump(mode, motion, flags, ...) range
64      let l:startofline = (a:0 >= 1) ? a:1 : 1
65
66      if a:mode == 'x'
67          normal! gv
68      endif
69
70      if l:startofline == 1
71          normal! 0
72      endif
73
74      let cnt = v:count1
75      mark '
76      while cnt > 0
77          call search(a:motion, a:flags)
78          let cnt = cnt - 1
79      endwhile
80
81      if l:startofline == 1
82          normal! ^
83      endif
84  endfun
85endif
86
87if has("browsefilter") && !exists("b:browsefilter")
88    let b:browsefilter = "Python Files (*.py)\t*.py\n" .
89                \ "All Files (*.*)\t*.*\n"
90endif
91
92if !exists("g:python_recommended_style") || g:python_recommended_style != 0
93    " As suggested by PEP8.
94    setlocal expandtab shiftwidth=4 softtabstop=4 tabstop=8
95endif
96
97" First time: try finding "pydoc".
98if !exists('g:pydoc_executable')
99    if executable('pydoc')
100        let g:pydoc_executable = 1
101    else
102        let g:pydoc_executable = 0
103    endif
104endif
105" If "pydoc" was found use it for keywordprg.
106if g:pydoc_executable
107    setlocal keywordprg=pydoc
108endif
109
110let &cpo = s:keepcpo
111unlet s:keepcpo
112