forked from mgedmin/pythonhelper.vim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonhelper.vim
More file actions
136 lines (108 loc) · 3.7 KB
/
Copy pathpythonhelper.vim
File metadata and controls
136 lines (108 loc) · 3.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
" File: pythonhelper.vim
" Author: Michal Vitecek <fuf-at-mageo-dot-cz>
" Maintainer: Marius Gedminas <[email protected]>
" Version: 0.93
" Last Modified: 2017-03-14
"
" Overview
" --------
" Vim script to help moving around in larger Python source files. It displays
" current class, method or function the cursor is placed in on the status
" line for every python file. It's more clever than Yegappan Lakshmanan's
" taglist.vim because it takes into account indetation and comments to
" determine what tag the cursor is placed in.
"
" Requirements
" ------------
" This script needs only VIM compiled with Python interpreter. It doesn't rely
" on exuberant ctags utility. You can determine whether your VIM has Python
" support by issuing command :ver and looking for +python in the list of
" features.
"
" Installation
" ------------
" 1. Make sure your Vim has python feature on (+python). If not, you will need
" to recompile it with --with-pythoninterp option to the configure script
" 2. Copy pythonhelper.vim to the $HOME/.vim/plugin directory
" 3. Copy pythonhelper.py to the $HOME/.vim/pythonx directory
" 4. Add something like this to your .vimrc:
"
" " color of the current tag in the status line (bold cyan on black)
" highlight User1 gui=bold guifg=cyan guibg=black
" " color of the modified flag in the status line (bold black on red)
" highlight User2 gui=bold guifg=black guibg=red
" " the status line will be displayed for every window
" set laststatus=2
" " set the status line to display some useful information
" set stl=%-f%r\ %2*%m%*\ \ \ \ %1*%{TagInStatusLine()}%*%=[%l:%c]\ \ \ \ [buf\ %n]
"
" 5. Run Vim and open any python file.
"
if !exists("g:pythonhelper_python")
if has("python3")
let g:pythonhelper_python = "python3"
elseif has("python")
let g:pythonhelper_python = "python"
else
finish
endif
endif
execute g:pythonhelper_python 'import pythonhelper'
" VIM functions {{{
function! PHCursorHold()
" only python is supported {{{
if (!exists('b:current_syntax') || (b:current_syntax != 'python'))
let w:PHStatusLine = ''
return
endif
" }}}
" call python function findTag() with the current buffer number and changed ticks
execute g:pythonhelper_python 'pythonhelper.findTag(' . expand("<abuf>") . ', ' . b:changedtick . ')'
endfunction
function! PHBufferDelete()
if bufnr("") == expand("<abuf>")
" set PHStatusLine for this window to empty string
let w:PHStatusLine = ""
endif
" call python function deleteTags() with the cur
execute g:pythonhelper_python 'pythonhelper.deleteTags(' . expand("<abuf>") . ')'
endfunction
function! TagInStatusLine()
" return value of w:PHStatusLine in case it's set
if (exists("w:PHStatusLine"))
return w:PHStatusLine
" otherwise just return empty string
else
return ""
endif
endfunction
function! PHPreviousClassMethod()
call search('^[ \t]*\(class\|def\)\>', 'bw')
endfunction
function! PHNextClassMethod()
call search('^[ \t]*\(class\|def\)\>', 'w')
endfunction
function! PHPreviousClass()
call search('^[ \t]*class\>', 'bw')
endfunction
function! PHNextClass()
call search('^[ \t]*class\>', 'w')
endfunction
function! PHPreviousMethod()
call search('^[ \t]*def\>', 'bw')
endfunction
function! PHNextMethod()
call search('^[ \t]*def\>', 'w')
endfunction
" }}}
" event binding, vim customizing {{{
" autocommands binding
augroup PythonHelper
autocmd!
autocmd CursorMoved * call PHCursorHold()
autocmd CursorMovedI * call PHCursorHold()
autocmd BufEnter * call PHCursorHold()
autocmd BufDelete * silent call PHBufferDelete()
augroup END
" }}}
" vim:foldmethod=marker