-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdsf.txt
220 lines (167 loc) · 7.74 KB
/
dsf.txt
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
*dsf.txt* Delete surrounding function call
==============================================================================
CONTENTS *dsf* *dsf-contents*
Installation................................: |dsf-installation|
Usage.......................................: |dsf-usage|
Settings....................................: |dsf-settings|
Issues......................................: |dsf-issues|
==============================================================================
INSTALLATION *dsf-installation*
The easiest way to install the plugin is with a plugin manager:
- vim-plug: https://github.com/junegunn/vim-plug
- Vundle: https://github.com/VundleVim/Vundle.vim
If you use one, just follow the instructions in its documentation.
You can install the plugin yourself using Vim's |packages| functionality by
cloning the project (or adding it as a submodule) under
`~/.vim/pack/<any-name>/start/`. For example:
>
git clone https://github.com/AndrewRadev/dsf.vim ~/.vim/pack/_/start/dsf
<
This should automatically load the plugin for you on Vim start. Alternatively,
you can add it to `~/.vim/pack/<any-name>/opt/` instead and load it in your
.vimrc manually with:
>
packadd dsf
<
If you'd rather not use git, you can download the files from the "releases"
tab and unzip them in the relevant directory:
https://github.com/AndrewRadev/dsf.vim/releases.
==============================================================================
USAGE *dsf-usage*
The plugin defines a mapping to delete a surrounding function call (or
something similar to one), even if it happens to be namespaced. Some examples:
>
nested(function_call(cursor_here)) -> nested(cursor_here)
nested(cursor_here(chewy_center)) -> cursor_here(chewy_center)
One::Two.new([cursor_here]) -> [cursor_here]
One::Two.new(Hash[cursor_here]) -> One::Two.new(cursor_here)
SomeStruct{cursor_here: "Something"} -> cursor_here: "Something"
<
By pressing `dsf` (which stands for "delete surrounding function call") with
the cursor on `cursor_here`, you get the result on the right.
More mappings ~
The plugin defines `csf` to "change surrounding function call", which deletes
only the function itself and leaves the cursor waiting to enter a new name.
For convenience, the `dsnf` (the "n" standing for "next") mapping will look
for a function call after the cursor to delete:
>
var result = function_call(foo, bar(baz));
// With the cursor on "foo", pressing dsnf results in:
var result = function_call(foo, baz);
<
Text objects ~
The text objects for `if` and `af` manipulate function calls with their
contents. Given this example:
>
var result = function_call(one, two);
<
Typing `daf` ("a function call") with the cursor anywhere on
`function_call(one, two)` would result in:
>
var result = ;
<
Typing `dif` ("inner function call") with the cursor anywhere on
`function_call(one, two)` would result in:
>
var result = function_call();
<
To learn more about how text objects work, try the `:help` for |text-objects|.
Multiline ~
The plugin also works on multiline function calls, for example:
>
foo = one(
two
)
foo = two
<
The insides of the function will be automatically indented using the |=|
operator to compensate for any potential changes in indentation level.
Customization ~
If you'd like to set your own mappings, instead of using the built-ins, simply
set the variable `g:dsf_no_mappings` to `1` and use the <Plug> mappings
provided by the plugin:
>
let g:dsf_no_mappings = 1
nmap dsf <Plug>DsfDelete
nmap csf <Plug>DsfChange
nmap dsnf <Plug>DsfNextDelete
nmap csnf <Plug>DsfNextChange
omap af <Plug>DsfTextObjectA
xmap af <Plug>DsfTextObjectA
omap if <Plug>DsfTextObjectI
xmap if <Plug>DsfTextObjectI
<
Change any of the left-hand sides of the `map` calls to whatever you'd like,
or remove lines to leave them unset.
For additional settings check the below section, |dsf-settings|.
==============================================================================
SETTINGS *dsf-settings*
*g:dsf_no_mappings*
>
let g:dsf_no_mappings = 1
<
Default value: 0
If you set this variable to 1, the plugin will not define any default
mappings. You'll still have the <Plug> maps provided to you that you can map
any keys you want to. Check |dsf-usage| for details on that.
*g:dsf_brackets*
>
let g:dsf_brackets = '('
<
Default value: '([{'
You can change this value to determine what brackets identify a "function
call". While in most languages, only "(" is used for those, a useful (even if
technically incorrect) interpretation of "function call" might include things
like `Hash[*some_list]` in ruby, or `SomeStruct{with: "values"}` in go. This
is why the plugin, by default, considers "([{" as brackets.
If you'd like to avoid this, so you don't accidentally delete structs or
something, set this to whatever opening brackets you'd like to detect.
Note that this can be changed per-buffer by setting `b:dsf_brackets`.
*g:dsf_function_pattern*
>
let g:dsf_function_pattern = '\k\+'
<
Default value: '\k\+[?!]\='
The function pattern determines what will be identified as a function name.
This should not include the opening bracket. Usually, a keyword character will
do the trick, but the default also adds some extra characters allowed at the
end to cover special cases for ruby.
The pattern is a Vim regex, if you need more information on those, check the
:help on |pattern-overview|.
Note that this can be changed per-buffer by setting `b:dsf_function_pattern`.
*g:dsf_namespace_pattern*
>
let g:dsf_namespace_pattern = '\k\+::'
<
Default value: '\k\+\%(\.\|::\|:\|#\)'
The namespace pattern determines what will be identified as a namespace that
prefixes a function. This will likely be a set of keyword characters, followed
by something like "::", ".", depending on the language. The default includes a
set of characters that cover a few languages.
If you'd like to NOT cover namespaces at all, and just manipulate the function
name, set it to the empty string:
>
let g:namespace_pattern = ''
<
This might allow you, to, for example, easily change the function call with
`csf` to a different one in the same module/package.
The pattern is a Vim regex, if you need more information on those, check the
:help on |pattern-overview|.
Note that this can be changed per-buffer by setting `b:dsf_namespace_pattern`.
*g:dsf_latex_special_handling*
>
let g:dsf_latex_special_handling = 0
<
Default value: 1
In a latex file, an expression like `\frac{dY}{dt}` is going to be treated as
a "function", though only with the cursor in the first pair of brackets. The
second pair of brackets will end up being left over in the case of a deletion.
This variable controls whether the plugin will attempt to also delete the
second pair of brackets. It's on by default, but it can be turned off in case
it causes trouble. It's only on when the filetype is `tex`, so if you want
support for other filetypes or find any problems, please open an issue.
==============================================================================
ISSUES *dsf-issues*
Any issues and suggestions are very welcome on the github bugtracker:
https://github.com/AndrewRadev/dsf.vim/issues
vim:tw=78:sw=4:ft=help:norl: