-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathparameter_objects.vim
104 lines (97 loc) · 3.19 KB
/
parameter_objects.vim
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
" A Vim plugin that defines a parameter text object.
" Maintainer: David Larson <[email protected]>
" Last Change: Mar 15, 2010
"
" This script defines a parameter text object. A parameter is the text between
" parentheses or commas, typically found in a function's argument list.
"
" See:
" :help text-objects
" for a description of what can be done with text objects.
" Also See:
" :help a(
" If you want to operate on the parentheses also.
"
" Like all the other text-objects, a parameter text object can be selected
" following these commands: 'd', 'c', 'y', 'v', etc. The script defines these
" operator mappings:
"
" aP "a parameter", select a parameter, including one comma (if there is
" one).
"
" iP "inner parameter", select a parameter, not including commas.
"
" If you would like to remap the commands then you can prevent the default
" mappings from getting set if you set g:no_parameter_object_maps = 1 in your
" .vimrc file. Then remap the commands as desired, like this:
"
" let g:no_parameter_object_maps = 1
" vmap <silent> ia <Plug>ParameterObjectI
" omap <silent> ia <Plug>ParameterObjectI
" vmap <silent> aa <Plug>ParameterObjectA
" omap <silent> aa <Plug>ParameterObjectA
if exists("loaded_parameter_objects") || &cp || v:version < 701
finish
endif
let loaded_parameter_objects = 1
if !exists("g:no_parameter_object_maps") || !g:no_parameter_object_maps
vmap <silent> iP <Plug>ParameterObjectI
omap <silent> iP <Plug>ParameterObjectI
vmap <silent> aP <Plug>ParameterObjectA
omap <silent> aP <Plug>ParameterObjectA
endif
vnoremap <silent> <script> <Plug>ParameterObjectI :<C-U>call <SID>parameter_object("i")<cr>
onoremap <silent> <script> <Plug>ParameterObjectI :call <SID>parameter_object("i")<cr>
vnoremap <silent> <script> <Plug>ParameterObjectA :<C-U>call <SID>parameter_object("a")<cr>
onoremap <silent> <script> <Plug>ParameterObjectA :call <SID>parameter_object("a")<cr>
function s:parameter_object(mode)
let ve_save = &ve
set virtualedit=onemore
let l_save = @l
try
" Search for the start of the parameter text object
if searchpair('(',',',')', 'bWs', "s:skip()") <= 0
return
endif
normal! "lyl
if a:mode == "a" && @l == ','
let gotone = 1
normal! ml
else
normal! lmlh
endif
let c = v:count1
while c
" Search for the end of the parameter text object
if searchpair('(',',',')', 'W', "s:skip()") <= 0
normal! `'
return
endif
normal! "lyl
if @l == ')' && c > 1
" found the last parameter when more is asked for, so abort
normal! `'
return
endif
let c -= 1
endwhile
if a:mode == "a" && @l == ',' && !exists("gotone")
else
normal! h
endif
normal! v`l
finally
let &ve = ve_save
let @l = l_save
endtry
endfunction
function s:skip()
let name = synIDattr(synID(line("."), col("."), 0), "name")
if name =~? "comment"
return 1
elseif name =~? "string"
return 1
endif
return 0
endfunction
" vim:fdm=marker fmr=function\ ,endfunction