blob: d52a338b5b9f6fc325db1c57ff071c2b9d6821ce [file] [log] [blame]
Bram Moolenaar071d4272004-06-13 20:20:40 +00001" Vim filetype plugin file
2" Language: python
Bram Moolenaar01164a62017-11-02 22:58:42 +01003" Maintainer: Tom Picton <tom@tompicton.co.uk>
4" Previous Maintainer: James Sully <sullyj3@gmail.com>
Bram Moolenaarc95a3022016-06-12 23:01:46 +02005" Previous Maintainer: Johannes Zellner <johannes@zellner.org>
Bram Moolenaar01164a62017-11-02 22:58:42 +01006" Last Change: Fri, 20 October 2017
7" https://github.com/tpict/vim-ftplugin-python
Bram Moolenaar071d4272004-06-13 20:20:40 +00008
9if exists("b:did_ftplugin") | finish | endif
10let b:did_ftplugin = 1
Bram Moolenaar9a7224b2012-04-30 15:56:52 +020011let s:keepcpo= &cpo
12set cpo&vim
Bram Moolenaar071d4272004-06-13 20:20:40 +000013
14setlocal cinkeys-=0#
15setlocal indentkeys-=0#
Bram Moolenaar92dff182014-02-11 19:15:50 +010016setlocal include=^\\s*\\(from\\\|import\\)
Bram Moolenaar071d4272004-06-13 20:20:40 +000017setlocal includeexpr=substitute(v:fname,'\\.','/','g')
18setlocal suffixesadd=.py
Bram Moolenaar36782082013-11-28 13:53:34 +010019setlocal comments=b:#,fb:-
20setlocal commentstring=#\ %s
Bram Moolenaar071d4272004-06-13 20:20:40 +000021
Bram Moolenaar18144c82006-04-12 21:52:12 +000022setlocal omnifunc=pythoncomplete#Complete
Bram Moolenaara40ceaf2006-01-13 22:35:40 +000023
Bram Moolenaar071d4272004-06-13 20:20:40 +000024set wildignore+=*.pyc
25
Bram Moolenaardc083282016-10-11 08:57:33 +020026let b:next_toplevel='\v%$\|^(class\|def\|async def)>'
27let b:prev_toplevel='\v^(class\|def\|async def)>'
Bram Moolenaar01164a62017-11-02 22:58:42 +010028let b:next_endtoplevel='\v%$\|\S.*\n+(def\|class)'
29let b:prev_endtoplevel='\v\S.*\n+(def\|class)'
Bram Moolenaardc083282016-10-11 08:57:33 +020030let b:next='\v%$\|^\s*(class\|def\|async def)>'
31let b:prev='\v^\s*(class\|def\|async def)>'
Bram Moolenaar01164a62017-11-02 22:58:42 +010032let b:next_end='\v\S\n*(%$\|^\s*(class\|def\|async def)\|^\S)'
33let b:prev_end='\v\S\n*(^\s*(class\|def\|async def)\|^\S)'
Bram Moolenaare18dbe82016-07-02 21:42:23 +020034
Bram Moolenaarabd468e2016-09-08 22:22:43 +020035execute "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>"
Bram Moolenaar01164a62017-11-02 22:58:42 +010037execute "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>"
Bram Moolenaarabd468e2016-09-08 22:22:43 +020039execute "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>"
Bram Moolenaar01164a62017-11-02 22:58:42 +010041execute "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>"
Bram Moolenaarabd468e2016-09-08 22:22:43 +020043
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>"
Bram Moolenaar01164a62017-11-02 22:58:42 +010046execute "onoremap <silent> <buffer> ][ :call <SID>Python_jump('n', '". b:next_endtoplevel."', 'W', 0)<cr>"
47execute "onoremap <silent> <buffer> [] :call <SID>Python_jump('n', '". b:prev_endtoplevel."', 'Wb', 0)<cr>"
Bram Moolenaarabd468e2016-09-08 22:22:43 +020048execute "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>"
Bram Moolenaar01164a62017-11-02 22:58:42 +010050execute "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>"
Bram Moolenaarabd468e2016-09-08 22:22:43 +020052
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>"
Bram Moolenaar01164a62017-11-02 22:58:42 +010055execute "xnoremap <silent> <buffer> ][ :call <SID>Python_jump('n', '". b:next_endtoplevel."', 'W', 0)<cr>"
56execute "xnoremap <silent> <buffer> [] :call <SID>Python_jump('n', '". b:prev_endtoplevel."', 'Wb', 0)<cr>"
Bram Moolenaarabd468e2016-09-08 22:22:43 +020057execute "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>"
Bram Moolenaar01164a62017-11-02 22:58:42 +010059execute "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>"
Bram Moolenaar071d4272004-06-13 20:20:40 +000061
Bram Moolenaar36782082013-11-28 13:53:34 +010062if !exists('*<SID>Python_jump')
Bram Moolenaar01164a62017-11-02 22:58:42 +010063 fun! <SID>Python_jump(mode, motion, flags, ...) range
64 let l:startofline = (a:0 >= 1) ? a:1 : 1
65
Bram Moolenaare18dbe82016-07-02 21:42:23 +020066 if a:mode == 'x'
67 normal! gv
68 endif
69
Bram Moolenaar01164a62017-11-02 22:58:42 +010070 if l:startofline == 1
71 normal! 0
72 endif
Bram Moolenaare18dbe82016-07-02 21:42:23 +020073
Bram Moolenaar36782082013-11-28 13:53:34 +010074 let cnt = v:count1
Bram Moolenaar36782082013-11-28 13:53:34 +010075 mark '
76 while cnt > 0
Bram Moolenaare18dbe82016-07-02 21:42:23 +020077 call search(a:motion, a:flags)
78 let cnt = cnt - 1
Bram Moolenaar36782082013-11-28 13:53:34 +010079 endwhile
Bram Moolenaare18dbe82016-07-02 21:42:23 +020080
Bram Moolenaar01164a62017-11-02 22:58:42 +010081 if l:startofline == 1
82 normal! ^
83 endif
Bram Moolenaar36782082013-11-28 13:53:34 +010084 endfun
85endif
Bram Moolenaar071d4272004-06-13 20:20:40 +000086
Bram Moolenaar36782082013-11-28 13:53:34 +010087if has("browsefilter") && !exists("b:browsefilter")
Bram Moolenaar071d4272004-06-13 20:20:40 +000088 let b:browsefilter = "Python Files (*.py)\t*.py\n" .
Bram Moolenaare18dbe82016-07-02 21:42:23 +020089 \ "All Files (*.*)\t*.*\n"
Bram Moolenaar071d4272004-06-13 20:20:40 +000090endif
Bram Moolenaar9a7224b2012-04-30 15:56:52 +020091
Bram Moolenaarabd468e2016-09-08 22:22:43 +020092if !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
Bram Moolenaarb1332082013-10-06 14:22:40 +020096
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
Bram Moolenaar9a7224b2012-04-30 15:56:52 +0200110let &cpo = s:keepcpo
111unlet s:keepcpo