Mercurial > vim
annotate runtime/ftplugin/python.vim @ 31362:7fc63cd1c462
Added tag v9.0.1014 for changeset abb9d25924d87e07c6a92c18147c6ffa777520ac
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Mon, 05 Dec 2022 22:45:04 +0100 |
parents | 17c4178f26ea |
children | 8ae680be2a51 |
rev | line source |
---|---|
7 | 1 " Vim filetype plugin file |
2 " Language: python | |
12756
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
10261
diff
changeset
|
3 " Maintainer: Tom Picton <tom@tompicton.co.uk> |
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
10261
diff
changeset
|
4 " Previous Maintainer: James Sully <sullyj3@gmail.com> |
9286
64035abb986b
commit https://github.com/vim/vim/commit/c95a302a4c42ec8230473cd4a5e0064d0a143aa8
Christian Brabandt <cb@256bit.org>
parents:
5663
diff
changeset
|
5 " Previous Maintainer: Johannes Zellner <johannes@zellner.org> |
22565 | 6 " Last Change: Mon, 5 October 2020 |
12756
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
10261
diff
changeset
|
7 " https://github.com/tpict/vim-ftplugin-python |
7 | 8 |
9 if exists("b:did_ftplugin") | finish | endif | |
10 let b:did_ftplugin = 1 | |
3496
d1e4abe8342c
Fixed compatible mode in most runtime files.
Bram Moolenaar <bram@vim.org>
parents:
827
diff
changeset
|
11 let s:keepcpo= &cpo |
d1e4abe8342c
Fixed compatible mode in most runtime files.
Bram Moolenaar <bram@vim.org>
parents:
827
diff
changeset
|
12 set cpo&vim |
7 | 13 |
14 setlocal cinkeys-=0# | |
15 setlocal indentkeys-=0# | |
5663
1dea14d4c738
Update runtime files. Add support for systemverilog.
Bram Moolenaar <bram@vim.org>
parents:
5510
diff
changeset
|
16 setlocal include=^\\s*\\(from\\\|import\\) |
22565 | 17 setlocal define=^\\s*\\(def\\\|class\\) |
13482
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
18 |
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
19 " For imports with leading .., append / and replace additional .s with ../ |
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
20 let b:grandparent_match = '^\(.\.\)\(\.*\)' |
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
21 let b:grandparent_sub = '\=submatch(1)."/".repeat("../",strlen(submatch(2)))' |
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
22 |
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
23 " For imports with a single leading ., replace it with ./ |
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
24 let b:parent_match = '^\.\(\.\)\@!' |
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
25 let b:parent_sub = './' |
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
26 |
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
27 " Replace any . sandwiched between word characters with / |
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
28 let b:child_match = '\(\w\)\.\(\w\)' |
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
29 let b:child_sub = '\1/\2' |
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
30 |
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
31 setlocal includeexpr=substitute(substitute(substitute( |
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
32 \v:fname, |
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
33 \b:grandparent_match,b:grandparent_sub,''), |
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
34 \b:parent_match,b:parent_sub,''), |
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
35 \b:child_match,b:child_sub,'g') |
9eebe457eb3c
Update runtime files. Convert a couple of help files to utf-8.
Christian Brabandt <cb@256bit.org>
parents:
13125
diff
changeset
|
36 |
7 | 37 setlocal suffixesadd=.py |
5510 | 38 setlocal comments=b:#,fb:- |
39 setlocal commentstring=#\ %s | |
7 | 40 |
13125 | 41 if has('python3') |
22565 | 42 setlocal omnifunc=python3complete#Complete |
16086 | 43 elseif has('python') |
44 setlocal omnifunc=pythoncomplete#Complete | |
13125 | 45 endif |
626 | 46 |
7 | 47 set wildignore+=*.pyc |
48 | |
10261
bdd7fc1a38c0
commit https://github.com/vim/vim/commit/dc08328821a2c11e33dfb1980332e4923ec64fca
Christian Brabandt <cb@256bit.org>
parents:
10153
diff
changeset
|
49 let b:next_toplevel='\v%$\|^(class\|def\|async def)>' |
bdd7fc1a38c0
commit https://github.com/vim/vim/commit/dc08328821a2c11e33dfb1980332e4923ec64fca
Christian Brabandt <cb@256bit.org>
parents:
10153
diff
changeset
|
50 let b:prev_toplevel='\v^(class\|def\|async def)>' |
12756
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
10261
diff
changeset
|
51 let b:next_endtoplevel='\v%$\|\S.*\n+(def\|class)' |
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
10261
diff
changeset
|
52 let b:prev_endtoplevel='\v\S.*\n+(def\|class)' |
10261
bdd7fc1a38c0
commit https://github.com/vim/vim/commit/dc08328821a2c11e33dfb1980332e4923ec64fca
Christian Brabandt <cb@256bit.org>
parents:
10153
diff
changeset
|
53 let b:next='\v%$\|^\s*(class\|def\|async def)>' |
bdd7fc1a38c0
commit https://github.com/vim/vim/commit/dc08328821a2c11e33dfb1980332e4923ec64fca
Christian Brabandt <cb@256bit.org>
parents:
10153
diff
changeset
|
54 let b:prev='\v^\s*(class\|def\|async def)>' |
12826 | 55 let b:next_end='\v\S\n*(%$\|^(\s*\n*)*(class\|def\|async def)\|^\S)' |
56 let b:prev_end='\v\S\n*(^(\s*\n*)*(class\|def\|async def)\|^\S)' | |
10153
715d6c5707b8
commit https://github.com/vim/vim/commit/abd468ed0fbcba391e7833feeaa7de3ced841455
Christian Brabandt <cb@256bit.org>
parents:
10140
diff
changeset
|
57 |
16086 | 58 if !exists('g:no_plugin_maps') && !exists('g:no_python_maps') |
59 execute "nnoremap <silent> <buffer> ]] :call <SID>Python_jump('n', '". b:next_toplevel."', 'W', v:count1)<cr>" | |
60 execute "nnoremap <silent> <buffer> [[ :call <SID>Python_jump('n', '". b:prev_toplevel."', 'Wb', v:count1)<cr>" | |
61 execute "nnoremap <silent> <buffer> ][ :call <SID>Python_jump('n', '". b:next_endtoplevel."', 'W', v:count1, 0)<cr>" | |
62 execute "nnoremap <silent> <buffer> [] :call <SID>Python_jump('n', '". b:prev_endtoplevel."', 'Wb', v:count1, 0)<cr>" | |
63 execute "nnoremap <silent> <buffer> ]m :call <SID>Python_jump('n', '". b:next."', 'W', v:count1)<cr>" | |
64 execute "nnoremap <silent> <buffer> [m :call <SID>Python_jump('n', '". b:prev."', 'Wb', v:count1)<cr>" | |
65 execute "nnoremap <silent> <buffer> ]M :call <SID>Python_jump('n', '". b:next_end."', 'W', v:count1, 0)<cr>" | |
66 execute "nnoremap <silent> <buffer> [M :call <SID>Python_jump('n', '". b:prev_end."', 'Wb', v:count1, 0)<cr>" | |
9407
619a98a67f67
commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents:
9286
diff
changeset
|
67 |
16086 | 68 execute "onoremap <silent> <buffer> ]] :call <SID>Python_jump('o', '". b:next_toplevel."', 'W', v:count1)<cr>" |
69 execute "onoremap <silent> <buffer> [[ :call <SID>Python_jump('o', '". b:prev_toplevel."', 'Wb', v:count1)<cr>" | |
70 execute "onoremap <silent> <buffer> ][ :call <SID>Python_jump('o', '". b:next_endtoplevel."', 'W', v:count1, 0)<cr>" | |
71 execute "onoremap <silent> <buffer> [] :call <SID>Python_jump('o', '". b:prev_endtoplevel."', 'Wb', v:count1, 0)<cr>" | |
72 execute "onoremap <silent> <buffer> ]m :call <SID>Python_jump('o', '". b:next."', 'W', v:count1)<cr>" | |
73 execute "onoremap <silent> <buffer> [m :call <SID>Python_jump('o', '". b:prev."', 'Wb', v:count1)<cr>" | |
74 execute "onoremap <silent> <buffer> ]M :call <SID>Python_jump('o', '". b:next_end."', 'W', v:count1, 0)<cr>" | |
75 execute "onoremap <silent> <buffer> [M :call <SID>Python_jump('o', '". b:prev_end."', 'Wb', v:count1, 0)<cr>" | |
10153
715d6c5707b8
commit https://github.com/vim/vim/commit/abd468ed0fbcba391e7833feeaa7de3ced841455
Christian Brabandt <cb@256bit.org>
parents:
10140
diff
changeset
|
76 |
16086 | 77 execute "xnoremap <silent> <buffer> ]] :call <SID>Python_jump('x', '". b:next_toplevel."', 'W', v:count1)<cr>" |
78 execute "xnoremap <silent> <buffer> [[ :call <SID>Python_jump('x', '". b:prev_toplevel."', 'Wb', v:count1)<cr>" | |
79 execute "xnoremap <silent> <buffer> ][ :call <SID>Python_jump('x', '". b:next_endtoplevel."', 'W', v:count1, 0)<cr>" | |
80 execute "xnoremap <silent> <buffer> [] :call <SID>Python_jump('x', '". b:prev_endtoplevel."', 'Wb', v:count1, 0)<cr>" | |
81 execute "xnoremap <silent> <buffer> ]m :call <SID>Python_jump('x', '". b:next."', 'W', v:count1)<cr>" | |
82 execute "xnoremap <silent> <buffer> [m :call <SID>Python_jump('x', '". b:prev."', 'Wb', v:count1)<cr>" | |
83 execute "xnoremap <silent> <buffer> ]M :call <SID>Python_jump('x', '". b:next_end."', 'W', v:count1, 0)<cr>" | |
84 execute "xnoremap <silent> <buffer> [M :call <SID>Python_jump('x', '". b:prev_end."', 'Wb', v:count1, 0)<cr>" | |
85 endif | |
7 | 86 |
5510 | 87 if !exists('*<SID>Python_jump') |
13735 | 88 fun! <SID>Python_jump(mode, motion, flags, count, ...) range |
12756
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
10261
diff
changeset
|
89 let l:startofline = (a:0 >= 1) ? a:1 : 1 |
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
10261
diff
changeset
|
90 |
9407
619a98a67f67
commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents:
9286
diff
changeset
|
91 if a:mode == 'x' |
619a98a67f67
commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents:
9286
diff
changeset
|
92 normal! gv |
619a98a67f67
commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents:
9286
diff
changeset
|
93 endif |
619a98a67f67
commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents:
9286
diff
changeset
|
94 |
12756
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
10261
diff
changeset
|
95 if l:startofline == 1 |
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
10261
diff
changeset
|
96 normal! 0 |
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
10261
diff
changeset
|
97 endif |
9407
619a98a67f67
commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents:
9286
diff
changeset
|
98 |
13735 | 99 let cnt = a:count |
5510 | 100 mark ' |
101 while cnt > 0 | |
9407
619a98a67f67
commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents:
9286
diff
changeset
|
102 call search(a:motion, a:flags) |
619a98a67f67
commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents:
9286
diff
changeset
|
103 let cnt = cnt - 1 |
5510 | 104 endwhile |
9407
619a98a67f67
commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents:
9286
diff
changeset
|
105 |
12756
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
10261
diff
changeset
|
106 if l:startofline == 1 |
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
10261
diff
changeset
|
107 normal! ^ |
3b26420fc639
Long overdue runtime update.
Christian Brabandt <cb@256bit.org>
parents:
10261
diff
changeset
|
108 endif |
5510 | 109 endfun |
110 endif | |
7 | 111 |
5510 | 112 if has("browsefilter") && !exists("b:browsefilter") |
7 | 113 let b:browsefilter = "Python Files (*.py)\t*.py\n" . |
9407
619a98a67f67
commit https://github.com/vim/vim/commit/e18dbe865d190e74fb5d43ac8bc6ac22507d0223
Christian Brabandt <cb@256bit.org>
parents:
9286
diff
changeset
|
114 \ "All Files (*.*)\t*.*\n" |
7 | 115 endif |
3496
d1e4abe8342c
Fixed compatible mode in most runtime files.
Bram Moolenaar <bram@vim.org>
parents:
827
diff
changeset
|
116 |
10153
715d6c5707b8
commit https://github.com/vim/vim/commit/abd468ed0fbcba391e7833feeaa7de3ced841455
Christian Brabandt <cb@256bit.org>
parents:
10140
diff
changeset
|
117 if !exists("g:python_recommended_style") || g:python_recommended_style != 0 |
715d6c5707b8
commit https://github.com/vim/vim/commit/abd468ed0fbcba391e7833feeaa7de3ced841455
Christian Brabandt <cb@256bit.org>
parents:
10140
diff
changeset
|
118 " As suggested by PEP8. |
22565 | 119 setlocal expandtab tabstop=4 softtabstop=4 shiftwidth=4 |
5400 | 120 endif |
16086 | 121 |
22565 | 122 " Use pydoc for keywordprg. |
123 " Unix users preferentially get pydoc3, then pydoc2. | |
124 " Windows doesn't have a standalone pydoc executable in $PATH by default, nor | |
125 " does it have separate python2/3 executables, so Windows users just get | |
126 " whichever version corresponds to their installed Python version. | |
127 if executable('python3') | |
128 setlocal keywordprg=python3\ -m\ pydoc | |
129 elseif executable('python') | |
130 setlocal keywordprg=python\ -m\ pydoc | |
5400 | 131 endif |
132 | |
16086 | 133 " Script for filetype switching to undo the local stuff we may have changed |
134 let b:undo_ftplugin = 'setlocal cinkeys<' | |
135 \ . '|setlocal comments<' | |
136 \ . '|setlocal commentstring<' | |
137 \ . '|setlocal expandtab<' | |
138 \ . '|setlocal include<' | |
139 \ . '|setlocal includeexpr<' | |
140 \ . '|setlocal indentkeys<' | |
141 \ . '|setlocal keywordprg<' | |
142 \ . '|setlocal omnifunc<' | |
143 \ . '|setlocal shiftwidth<' | |
144 \ . '|setlocal softtabstop<' | |
145 \ . '|setlocal suffixesadd<' | |
146 \ . '|setlocal tabstop<' | |
147 \ . '|silent! nunmap <buffer> [M' | |
148 \ . '|silent! nunmap <buffer> [[' | |
149 \ . '|silent! nunmap <buffer> []' | |
150 \ . '|silent! nunmap <buffer> [m' | |
151 \ . '|silent! nunmap <buffer> ]M' | |
152 \ . '|silent! nunmap <buffer> ][' | |
153 \ . '|silent! nunmap <buffer> ]]' | |
154 \ . '|silent! nunmap <buffer> ]m' | |
155 \ . '|silent! ounmap <buffer> [M' | |
156 \ . '|silent! ounmap <buffer> [[' | |
157 \ . '|silent! ounmap <buffer> []' | |
158 \ . '|silent! ounmap <buffer> [m' | |
159 \ . '|silent! ounmap <buffer> ]M' | |
160 \ . '|silent! ounmap <buffer> ][' | |
161 \ . '|silent! ounmap <buffer> ]]' | |
162 \ . '|silent! ounmap <buffer> ]m' | |
163 \ . '|silent! xunmap <buffer> [M' | |
164 \ . '|silent! xunmap <buffer> [[' | |
165 \ . '|silent! xunmap <buffer> []' | |
166 \ . '|silent! xunmap <buffer> [m' | |
167 \ . '|silent! xunmap <buffer> ]M' | |
168 \ . '|silent! xunmap <buffer> ][' | |
169 \ . '|silent! xunmap <buffer> ]]' | |
170 \ . '|silent! xunmap <buffer> ]m' | |
171 \ . '|unlet! b:browsefilter' | |
172 \ . '|unlet! b:child_match' | |
173 \ . '|unlet! b:child_sub' | |
174 \ . '|unlet! b:grandparent_match' | |
175 \ . '|unlet! b:grandparent_sub' | |
176 \ . '|unlet! b:next' | |
177 \ . '|unlet! b:next_end' | |
178 \ . '|unlet! b:next_endtoplevel' | |
179 \ . '|unlet! b:next_toplevel' | |
180 \ . '|unlet! b:parent_match' | |
181 \ . '|unlet! b:parent_sub' | |
182 \ . '|unlet! b:prev' | |
183 \ . '|unlet! b:prev_end' | |
184 \ . '|unlet! b:prev_endtoplevel' | |
185 \ . '|unlet! b:prev_toplevel' | |
186 \ . '|unlet! b:undo_ftplugin' | |
187 | |
3496
d1e4abe8342c
Fixed compatible mode in most runtime files.
Bram Moolenaar <bram@vim.org>
parents:
827
diff
changeset
|
188 let &cpo = s:keepcpo |
d1e4abe8342c
Fixed compatible mode in most runtime files.
Bram Moolenaar <bram@vim.org>
parents:
827
diff
changeset
|
189 unlet s:keepcpo |