-
Notifications
You must be signed in to change notification settings - Fork 0
/
backpair.txt
163 lines (128 loc) · 5.07 KB
/
backpair.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
*backpair.vim* Go back to the inner position of the inputted pair.
Author: mityu
License: MIT License
==============================================================================
CONTENTS *backpair-contents*
INTRODUCTION |backpair-introduction|
REQUIREMENTS |backpair-requirements|
FUNCTIONS |backpair-functions|
AUTOCOMMANDS |backpair-autocmds|
EXAMPLES |backpair-examples|
==============================================================================
INTRODUCTION *backpair-introduction*
|backpair.vim| is a plugin to help inserting pair then returning back to the
inner position of the pair such as `()`, `[]`, `<>`, `""`, etc. For examples,
if you configure well, you can move like these:
Type )
()| -------------> (|)
Type )
\%(\)| -------------> \%(|\)
Type ]
[[]]| -------------> [[|]]
Note that this plugin does NOT provide any configuration and you need to write
some configurations in your .vimrc so that this plugin works well. See
|backpair-functions| and |backpair-autocmds| for the available functions and
autocommands, and see |backpair-examples| for the example configurations.
==============================================================================
REQUIREMENTS *backpair-requirements*
- Vim 8.2 or later
- Neovim 0.7.0 or later
==============================================================================
FUNCTIONS *backpair-functions*
backpair#add_pair({opener}, {closer} [, {opts}]) *backpair#add_pair()*
Register a pair. {opener} and {closer} is a |String| with one
character at least. If you type {opener}, {closer} and the last
character of {closer} sequentially in insert mode, this plugin reverts
the type of the last character of {closer} and move the cursor to the
position between {opener} and {closer}.
{opts} is a |Dict| to specify some options to enable/disable the rule
dynamically. The available keys are:
- enable_filetypes (optional, |List| of |String|s)
If the current buffer's filetype doesn't appear in this list,
the rule will be disabled.
- disable_filetypes (optional, |List| of |String|s)
If the current buffer's file type appears in this list, the
rule will be disabled.
- skip_if_ongoing (optional, |List| of |String|s)
If one element of this value exists in a list of ongoing
rule's current input, the rule will be disabled.
- condition (optional, |Funcref|)
This function should take no arguments and return boolean
comparable value. If this function returns falsy value, the
rule will be disabled. Note that this function will be
evaluated when after user typed the last character of {closer}
and before the typed character is inserted on buffer.
Examples:
- `call backpair#add_pair("[", "]")`:
Buffer~
-----------------------
|
Type [
-----------> [|
Type ]
-----------> []|
Type ]
-----------> [|]
- `call backpair#add_pair("\(", "\)")`:
Buffer~
-----------------------
|
Type \
-----------> \|
Type (
-----------> \(|
Type \
-----------> \(\|
Type )
-----------> \(\)|
Type )
-----------> \(|\)
`call backpair#add_pair("[", "]", #{skip_if_ongoing: ["[[]"]})`
`call backpair#add_pair("[[", "]]")`
Buffer~
-----------------------
[[]|
Type ]
-----------> [[]]| <------ The first rule is skipped since "[[]"
matches the input for the second rule.
Type ]
-----------> [[|]] <------ The second rule is applied.
backpair#clear_pairs() *backpair#clear_pairs()*
Clear all the registered pairs.
backpair#enable() *backpair#enable()*
Enables |backpair.vim| plugin.
backpair#disable() *backpair#disable()*
Disables |backpair.vim| plugin.
backpair#clear_state() *backpair#clear_state()*
Clear current internal state. Useful to prohibit |backpair.vim|
plugin to trigger any rule that return cursor back to the inner
position of the latest pair on next type of a character.
Example: >
inoremap <C-f> <Cmd>call backpair#clear_state()<CR><C-g>U<right>
<
==============================================================================
AUTOCOMMANDS *backpair-autocmds*
|backpair.vim| provides a |User| autocommand to do initial configurations.
backpair-initialize *backpair-User-backpair-initialize*
On the first load of |backpair.vim|. You can do some plugin
configurations such as to call |backpair#add_pair()|.
==============================================================================
EXAMPLES *backpair-examples*
- Setup this plugin: >
augroup setup-plugin-backpair
autocmd!
autocmd InsertEnter * ++once call backpair#enable()
autocmd User backpair-initialize ++once call s:backpair_config()
augroup END
function s:backpair_config() abort
call backpair#add_pair('(', ')')
call backpair#add_pair('[', ']', #{skip_if_ongoing: ['[[]']})
call backpair#add_pair('[[', ']]')
call backpair#add_pair('<', '>')
call backpair#add_pair('"', '"')
call backpair#add_pair("'", "'")
call backpair#add_pair('「', '」')
endfunction
<
==============================================================================
vim:tw=78:fo=tcq2mM:ts=8:ft=help:norl