-
Notifications
You must be signed in to change notification settings - Fork 6
/
AutoPairs.txt
2023 lines (1571 loc) · 88.4 KB
/
AutoPairs.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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
*AutoPairs.txt* Plugin for automatically inserting brackets, parentheses, and other pairs
*autopairs* *AutoPairs* *auto-pairs*
Insert or delete brackets, parens, and quotes in pair (a fork by LunarWatcher)
Original author: jiangmiao
Maintainer: LunarWatcher (Olivia)
License: MIT
URL: https://github.com/LunarWatcher/auto-pairs
(bugs, feature requests, questions, and pull requests go here)
Changelog: https://github.com/LunarWatcher/auto-pairs/blob/master/CHANGELOG.md
==============================================================================
*autopairs-help-documents* *autopairs-readme*
Table of help documents~
|AutoPairs.txt| (you are here)
Covers the core features of auto-pairs, as well as various meta
surrounding the plugin.
|AutoPairsCompatibility|
Contains a few solutions to incompatibility with specific (known!)
plugins.
|AutoPairsTroubleshooting|
Contains answers to known and common problems with auto-pairs.
|AutoPairsHowTo|
Contains a set of concrete guides for common auto-pairs
configurations.
Note: While the documents aim to contain only categorically relevant info,
there are cases where this won't happen. There are a number of reasons for
this, but the table of contents in each document is still meant to be
representative of the content of the file. If the table of content doesn't
help, it may be in another file.
If not, feel free to ask on GitHub (see: |autopairs-contributing|). I'm trying
my best to keep a clear structure, but I'm highly aware there are parts that
fall short. Identifying those, however, is the tricky part, and you can help
me do this by asking on GitHub.
==============================================================================
CONTENTS *autopairs-contents*
1. Installation .................................. |autopairs-installation|
2. Features .......................................... |autopairs-features|
2.1. Multibyte pairs ............................ |autopairs-multibyte|
3. Fly Mode ........................................... |autopairs-flymode|
4. Shortcuts ........................................ |autopairs-shortcuts|
4.1. Shortcut remapping ................ |autopairs-shortcut-remapping|
5. Options ............................................ |autopairs-options|
6. Diagnosing indentation ..................... |autopairs-diagnose-indent|
7. Functions (API) .................................. |autopairs-functions|
8. Declaring custom pairs .........................|autopairs-custom-pairs|
9. Credits/contributors ............................... |autopairs-credits|
10. Backwards compatibility ................... |autopairs-backwards-compat|
==============================================================================
1. Installation *autopairs-installation*
With vim-plug: >
Plug 'LunarWatcher/auto-pairs'
<
Alternatively, for more stable releases: >
Plug 'LunarWatcher/auto-pairs', {'tag': '*'}
<
Other installation methods are of course supported, but aren't documented
because the author of this help document couldn't be bothered to add all of
them. Most of them should work with a similar syntax anyway, and there's no
special install instructions aside just installing it. No compiling, no
external dependencies, just pure Vimscript. TL;DR: use your favorite plugin
management method/plugin
Note that setting |g:AutoPairsCompatibleMaps| to 0 is HIGHLY recommended.
Future maps, if any are added, will be built around a ctrl-based system rather
than a meta (alt)-based one.
Requirements~
Auto-pairs is fully self-contained. Consequently, it only has one requirement:
Vim 8.1 with patch 1114 or newer.
------------------------------------------------------------------------------
*autopairs-contributing*
*autopairs-support*
Contributing~
If you enjoy the plugin, please consider starring it on GitHub:
https://github.com/LunarWatcher/auto-pairs
This fork is maintained (and will continue to be maintained unless a better
option magically appears). Issues can currently be submitted to
https://github.com/LunarWatcher/auto-pairs/issues
I do, however, keep an eye on the issue tracker in jiangmiao's repo, because
this fork doesn't have nearly as many users as the original, and many legacy
bugs still haunt users.
Questions about the plugin not covered by the documentation can be submitted
as an issue, but should preferably be submitted on GitHub Discussions, in the
repo previously linked.
Direct link: https://github.com/LunarWatcher/auto-pairs/discussions
Pull requests are also more than welcome, and I'll make sure they don't stick
around for 6 years without being merged.
------------------------------------------------------------------------------
*autopairs-migrating*
Migrating from jiangmiao~
Migrating is largely straight-forward. There's some differences to custom
pairs - see |autopairs-migrating-pairs| for migration to the new system, as
well as |autopairs#AutoPairsDefine()|. The gist of it is: there's new pair
objects that allow some more customization of pairs. The addition of these are
entirely backwards-compatible, but they also support specifying languages.
These rely on |g:AutoPairsLanguagePairs|. While the variables can be modified
directly, it's recommended that you use the autoload methods, if you want the
standards to stay intact.
A few notes on config:
* Backspace isn't mapped by default. |g:AutoPairsMapBS|
* Multiline backspace is opt-in. |g:AutoPairsMultilineBackspace|
* Several variables have been removed. It's hard to list all the internal
changes, but if you expect something to work that doesn't, check the
documentation. If the documentation is gone, it's been removed. If you're in
doubt, or have questions, feel free to open an issue.
* All the alt-based maps have been remapped. Compatible maps can be re-enabled
with |g:AutoPairsCompatibleMaps|, but this is strongly discouraged due to the
consequences this has for non-ascii characters.
Overall caveats~
Auto-pairs relies on relatively dumb metrics to guesstimate when to insert,
when to skip, when to balance, etc.
This is a side-effect of full-on language parsing being a huge undertaking,
and one that substantially exceeds the project's limitations.
Since the fork from jiangmiao (and merging in PRs and fixing bugs), there's
been a lot of work put into making these metrics less dumb. At the time of
writing, there's support for string handling, settings for how inclined
auto-pairs is to jump, etc. While these do make auto-pairs better, there are
still going to be edge-cases, and especially surrounding multiline operation.
I'm sure there are ways to work around that, but for the times it fails,
there's a keyboard shortcut to toggle auto-pairs.
TL;DR: auto-pairs isn't perfect by design, but it can be disabled when it
makes a bad call on completion or balancing.
General advice~
This fork has grown _significantly_ since it was forked from upstream jiangmiao,
with a lot of changes and a lot of config. There's also multiple documentation
files, because there's a lot of documentation.
If you're wondering how to do something, take a look at |AutoPairsHowTo|. This
also serves as a bit of a TL;DR: to the extensive documentation in this
document for common questions.
If you've run into problems, take a look at |AutoPairsTrouble|.
You can also ask questions or report bugs over on GitHub - see
|autopairs-contributing|. This also helps me make the documentation (and
especially |AutoPairsHowTo|) more useful.
==============================================================================
2. Features *autopairs-features*
This section is undergoing maintenance. If you have ideas for something to put
here (that adds value beyond the rest of the docs), please consider opening an
issue or a discussion in the GitHub repo.
------------------------------------------------------------------------------
2.1. Multibyte pairs *autopairs-multibyte*
Support for multibyte pairs was added in an earlier version of the plugin
(prior to the forking). They're exactly what you'd think: they're pairs that
contain multiple bytes. One example of this is `'"""': '"""'`, and
`'{%', '%}'.`These act in a compose-like manner, so you can both have {} and
{%%} pairs without breaking one or the other.
These pairs are added in the exact same way as other pairs.
This can theoretically be used for HTML tags as well, but the number of rules
for that would end up being rather ridiculous. There's currently a plan to add
more flexible rules, including stuff applicable to HTML tags and if-else in
some languages, but it's not implemented at this time.
==============================================================================
3. Fly Mode *autopairs-flymode*
Note: Flymode is considered buggy and unreliable. It should be avoided
unless you enjoy spending time on flymode doing weird shit while you're
typing. Creative ideas and/or pull requests for making flymode less bad are
welcome (|autopairs-contributing|), but this feature shouldn't be used and
will not receive bugfixes in its current state.
Fly Mode will always force closed-pair jumping instead of inserting. Only for
")", "}", "]". If jumps in mistake, you can use |g:AutoPairsBackInsert| (default
Key: <M-b>) to jump back and insert closed pair.
The most situation maybe you want to insert single closed pair in the string,
such as: >
")"
Fly Mode is disabled by default. To enable Fly Mode, add following to your
.vimrc: >
let g:AutoPairsFlyMode = 1
Default options: >
let g:AutoPairsFlyMode = 0
let g:AutoPairsShortcutBackInsert = '<C-p><C-b>'
==============================================================================
4. Shortcuts *autopairs-shortcuts*
Shortcuts relying on central keys:
<CR> : Insert new indented line after return if cursor in blank brackets
or quotes. (|g:AutoPairsCRKey|, |g:AutoPairsMapCR|)
<BS> : Delete brackets in pair (|g:AutoPairsMapBS|)
<Space> : Insert spaces around a recently inserted pair (|g:AutoPairsMapSpace|)
These are also defined, but may be one of two variants. See
|g:AutoPairsCompatibleMaps|:
<C-p><C-t> or <M-p>: Toggle Autopairs (|g:AutoPairsShortcutToggle|)
<C-f> or <M-e>: Fast Wrap (|g:AutoPairsShortcutFastWrap|)
<C-p><C-j> or <M-n>: Jump to next closed pair (|g:AutoPairsShortcutJump|)
<C-p><C-b> or <M-b>: BackInsert (|g:AutoPairsShortcutBackInsert|)
And finally, other shortcuts defined by auto-pairs:
<C-p>%key : Move to closed pair (where the pair is represented by
%key). For the list of valid `%key`s, see
|g:AutoPairsMoveCharacter|.
Configurable through |g:AutoPairsMoveExpression|
All the above can be remapped by using the appropriate configuration variable.
Setting a configuration variable to "" disables that keybind
Also note that the prefix for most keybinds is <C-p> by default.
This can be reconfigured with |g:AutoPairsPrefix| if desired or necessitated
by plugin conflict.
------------------------------------------------------------------------------
4.1. Remapping shortcuts *autopairs-shortcut-remapping*
At this time, all keybinds are remappable by using various options (see
|autopairs-options|). The goal is for all of them to be possible to remap.
Additionally, there's currently one keybind that lets you remap `<cr>`. This
also lets you prevent <cr> conflicts, or just remap it if you prefer having
the actions mapped to <CR> on a different key.
In incompatible mode, mappings primarily use the <C-p> prefix. This does,
admittedly, conflict with Ctrl-P (the plugin), and there's no way to change
the prefix itself. The offending mappings can still be remapped, however, but
there's no way to bulk-change the prefix at this time.
==============================================================================
5. Options *autopairs-options*
These options exist in a global variant (`g:variableName`), and may have a
local variant (`b:variableName`), where `variableName` refers to some defined
variable. The documentation contains a notice when a buffer variable
exists, both in the overall list, as well as the entry.
------------------------------------------------------------------------------
*autopairs-options-contents*
This list is a table of contents for the options, sorted by categories.
Core~
- |g:AutoPairs| (has buffer variant) (default: see the entry)
Defines what pairs AutoPairs will complete
- |g:AutoPairsShortcutToggle| (has a buffer variant) (default: see the entry)
Defines the shortcut for toggling auto-pairs
- |g:AutoPairsInitHook| (default: 0 (= null))
A pre-init hook for auto-pairs. This doesn't have that many uses, but can
be used to ensure some bit of code is always executed just before
auto-pairs runs.
- |g:AutoPairsExperimentalAutocmd| (default: 1)
Whether or not to use BufWinEnter instead of BufEnter
- |g:AutoPairsDirectoryBlacklist| (default: [])
Directories to completely disable auto-pairs in
- |b:autopairs_enabled| ("default": 1)
Whether or not auto-pairs is enabled in the buffer. Can also be used to
toggle auto-pairs
- |g:AutoPairsLanguagePairs| (default: see entry)
A set of pairs for different languages - useful for avoiding autocmds and
explicit definition of |b:AutoPairs|
- |g:AutoPairsOpenBalanceBlacklist| (has a buffer variant) (default: [])
Contains a list of characters that don't trigger opening balance checks
- |g:AutoPairsFiletypeBlacklist| (default: see entry)
Filetypes to completely disable auto-pairs in
- |g:AutoPairsPrefix| (default: <C-p>)
Controls the default prefix for all non-compatible maps.
Whitespace and autocomplete~
- |g:AutoPairsCompleteOnlyOnSpace| (has a buffer variant) (default: 0)
Defines whether or not there has to be a space (or EOL) to insert a pair.
- |g:AutoPairsSpaceCompletionRegex| (has a buffer variant) (default: \S)
Defines the regex to use when |g:AutoPairsCompleteOnlyOnSpace| is 1
- |g:AutoPairsAutoBuildSpaceWhitelist| (has a buffer variant) (default: 1)
Whether or not to automatically generate parts of the character whitelist
- |g:AutoPairsNextCharWhitelist| (has a buffer variant) (default: [])
Defines additional characters to add to the list of exceptions for
|g:AutoPairsCompleteOnlyOnSpace|
Compat~
- |g:AutoPairsCompatibleMaps| (default: 0)
Whether or not to use legacy keybinds (from jiangmiao/auto-pairs), or to
use new ones designed not to conflict with other maps, or with characters
in various languages.
- |g:AutoPairsVersion|
This is not directly an option, but it defines the current version of
auto-pairs. Can be used for compatibility checks. DO NOT OVERRIDE!
Backspace~
- |g:AutoPairsMapBS| (has a buffer variant) (default: 0)
Whether or not to map backspace
- |g:AutoPairsMultilineBackspace| (has a buffer variant) (default: 0)
Whether or not to use multiline deletion
- |g:AutoPairsBSAfter| (has a buffer variant) (default: 1)
Whether or not to enable deleting a pair from behind
- |g:AutoPairsBSIn| (has a buffer variant) (default: 1)
Whether or not to enable deleting a pair from within
Newlines~
- |g:AutoPairsMapCR| (has a buffer variant) (default: 1)
Whether or not to map enter
- |g:AutoPairsCRKey| (has a buffer variant) (default: '<CR>')
Which key to use for the return action if |g:AutoPairsMapCR| is 1
- |g:AutoPairsCenterLine| (default: 1)
If |g:AutoPairsMapCR| is 1 and this option is 1, whether or not to center
the current line if it was relatively far down on the screen
- |g:AutoPairsReturnOnEmptyOnly| (has a buffer variant) (default: 1)
Whether or not the pair has to be empty to trigger the return action
Jumping~
- |g:AutoPairsJumpBlacklist| (has buffer variant) (default: [])
Defines a set of close keybinds that don't trigger close skipping.
- |g:AutoPairsNoJump| (has buffer variant) (default: 0)
Whether or not to allow skipping close pairs by typing the close character
for a given pair.
Quote management~
- |g:AutoPairsSingleQuoteMode| (has buffer variant) (default: 2)
How auto-pairs handles single quotes. Reading the documentation is highly
recommended
- |g:AutoPairsSingleQuotePrefixGroup| (has a buffer variant) (default: '^|\W')
A regex that lets you customize how auto-pairs handles single quote
expansion
- |g:AutoPairsSingleQuoteExpandFor| (has a buffer variant) (default: 'fbr')
Character group defining characters that are exempt to auto-pairs ignoring
letters while expanding.
- |g:AutoPairsCarefulStringExpansion| (has a buffer variant) (default: 0)
Whether or not to be careful when running CR on strings. See the entry for
a full explanation
- |g:AutoPairsQuotes| (has a buffer variant) (default: ["'", '"'])
Defines which characters are considered quotes by
|g:AutoPairsCarefulStringExpansion|
String and comment management~
- |g:AutoPairsStringHandlingMode| (has a buffer variant) (default: 0)
How auto-pairs handles strings. HIGHLY EXPERIMENTAL!
Insertion behavior~
- |g:AutoPairsAutoLineBreak| (has a buffer variant) (default: [])
A set of opening characters that trigger an instant line break (as in
auto-pairs does the line break after the open character automagically)
- |g:AutoPairsAutoBreakBefore| (has a buffer variant) (default: [])
A set of opening characters that insert a linebreak before the pair.
- |g:AutoPairsSyncAutoBreakOptions| (has a buffer variant) (default: 0)
Whether or not to automatically assign
|b:AutoPairsAutoBreakBefore| = |b:AutoPairsAutoLineBreak|
Please read the full help entry for limitations!
Balancing~
- |g:AutoPairsPreferClose| (default: 1)
Whether to prefer closing over jumping.
- |g:AutoPairsSearchEscape| (has a buffer variant) (default: 1)
Whether or not to take backslashes into account when inserting pairs
- |g:AutoPairsMultilineClose| (has a buffer variant) (default: 0)
Whether or not to search across lines when looking for close pairs.
- |g:AutoPairsShortcutToggleMultilineClose| (has a buffer variant) (default: <C-p><C-m>)
What keybind to use for toggling |g:AutoPairsMultilineClose|
- |g:AutoPairsSearchCloseAfterSpace| (has buffer variant) (default: 1)
Whether or not to check if the nearest close is after a space
Fast wrap~
- |g:AutoPairsMultilineFastWrap| (default: 0)
Whether or not to let fast wrap work across lines intentionally
- |g:AutoPairsMultibyteFastWrap| (has a buffer variant) (default: 1)
Whether or not to allow moving multibyte pairs with fast wrap
- |g:AutoPairsShortcutFastWrap| (has a buffer variant) (default: see the entry)
Defines the shortcut for fast wrap
Misc. mapping~
- |g:AutoPairsMapSpace| (default: 1)
Whether or not to map space
Misc. navigation~
*autopairs-navigation-options*
- |g:AutoPairsFlyMode| (default: 0)
Whether or not to enable flymode. Please read |autopairs-flymode| before
enabling.
- |g:AutoPairsFlyModeList| (has a buffer variant) (default: '}\])')
Defines what close pairs trigger fly mode if |g:AutoPairsFlyMode| is 1
- |g:AutoPairsShortcutJump| (has a buffer variant) (default: see the entry)
Defines the shortcut for jumping to the first closed pair, regardless of
what that pair is
- |g:AutoPairsShortcutBackInsert| (default: see the entry)
Defines the shortcut for undoing a flymode jump.
- |g:AutoPairsShortcutIgnore| (default: <C-p><C-e>)
Defines the shortcut for ignoring the next pair.
Simpler option than toggling auto-pairs entirely.
- |b:AutoPairsJumpRegex| (default: generated on-demand based on |b:AutoPairs|)
Largely for internal use, but defines how jumps are done when
|g:AutoPairsShortcutJump| is used.
- |g:AutoPairsMoveExpression| (has a buffer variant) (default: <C-p>%key)
Defines an expression that triggers the move feature. Please read the
entry before using.
Fly Mode~
Obligatory re-iteration that fly mode should not be used.
- |g:AutoPairsFlyMode|
- |g:AutoPairsFlyModeList|
- |g:AutoPairsShortcutBackInsert|
------------------------------------------------------------------------------
*g:AutoPairs* *b:AutoPairs*
dict
This variable also exists in a buffer variant.~
Default: >
{'(':')', '[':']', '{':'}',"'":"'",'"':'"', '```':'```', '"""':'"""', "'''":"'''", "`":"`"}
Specifies which symbols should be automatically paired.
To append new pairs without overwriting defaults, add values in your
`.vimrc`.: >
let g:AutoPairs = autopairs#AutoPairsDefine({'<': '>'})
<
Older versions of this plugin didn't use autoload, which made the above
invalid, and required `autocmd VimEnter *` to be used as well. This is no
longer the case.
The example above will enable matching of `<` with `>`. You can also use: >
let g:AutoPairs = { '(': ')', ...}
<
... Where the `...` represents additional mappings, but note that this overrides
all the defaults. If you only do the first mapping in the above example, for
an instance, the ONLY key bracket/quote/other auto-pairs knows of is ().
Previous versions of this document supported a type of assignment that doesn't
work due to plugin sourcing systems.
Modern assignment~
Newer versions of auto-pairs supports a lot more fancy systems for pair
management, including dealing with languages and filetype matching.
The full details are available in |autopairs#AutoPairsDefine()| and
|autopairs-pair-object|, but the gist of it:
>
let g:AutoPairs = autopairs#AutoPairsDefine([
\ "<": ">", " This is still valid
\ {"open": "<", "close": ">"}, " This is a verbose equivalent
\ {"open": "<", "close": ">", "filetype": ["html"]} " This is a filetype-specific mapping
\ ],
\ ["[", " And the final argument is an optional argument containing pairs to remove
\ '"""' ] " This config removes [] and """"""
\ )
<
Note that the above block is somewhat undefined behavior due to it containing
three equivalent pairs. It shouldn't be directly copy-pasted into your config,
because it might not work. The pair objects are valid, however, and the
removals are, but the three pair objects together probably aren't.
The old systems are still valid, however, but doesn't support the new fancy
objects. This means `autopairs#AutoPairsDefine({'<': '>'})` is still valid. It
does, however, not support the new pair objects entirely. You can add pair
objects, but it's not going to handle filetypes. This is by design.
The variable g:AutoPairs is still largely identical, but can now hold
string-string pairs as well as string-object pairs, where the object is,
again, an |autopairs-pair-object|. Processing is indirectly done through
helper functions, though, which is why adding a pair object directly to
|g:AutoPairs| or |b:AutoPairs| doesn't make a difference.
To end the abstract theory, here's one example of usage:
>
let g:AutoPairs = autopairs#AutoPairsDefine([
\ {"open": '\w\zs<', "close": '>'},
\ {"open": "$", "close": "$", "filetype": "tex"},
\ {"open": '\\left(', 'close': '\right)', "filetype": "tex"},
\ {"open": '\vclass .{-} (: (.{-}[ ,])+)? ?\{', 'close': '};', 'mapopen': '{', 'filetype': 'cpp'},
\ {"open": "*", "close": "*", "filetype": ["help"]},
\ {"open": "|", "close": "|", "filetype": "help"}
\ ])
<
This is config from my personal vimrc (as of 03.04.2021). There's lots of ways
to use the variable, of course, which largely depends on what you work with on
a day-to-day basis.
It's also possible to add pairs to the default in other ways, using
|autopairs#AutoPairsAddPair()| and |autopairs#AutoPairsAddPairs()|. This
bypasses autopairs#AutoPairsDefine(), but still loads defaults.
The methods exist because they're used internally, but have been exposed so
you can use them however you see fit.
Multibyte~
`g:AutoPair` additionally supports several types of multibyte pairs. If you're
frequently coding in an HTML template language, `"{%": "%}"` can be added to
the buffer variant of this variable (used in combination with an
`autocmd FileType`). The current behavior:
>
Input: {|
Output: {|}
Input: %
Output: {%|%}
<
There's built-in support for """ and ''', and more can be added if necessary.
There shouldn't be a limit the length (though, for obvious reasons, things
might go wrong if you decide to input an obnoxiously long mapping), so you
should be able to map all pairs used by your favorite language or framework.
*autopairs-regex-escaping*
Open is used in a regex search, and because auto-pairs applies stuff directly,
there's a minor input escape issue. Most people aren't going to experience it,
but if you i.e. wanna add `'\left(': '\right)'`, there is actually a "right
way" to add it. `\left` may cause `\l` to be interpreted as regex; |\l|
to be specific.
Consequentially, the pair has to be declared as `'\\left(': '\right)'` . The
close pair is also used as a regex in some places, but shouldn't cause any
problems. Additional escaping will be added soon to mitigate problems, but
it's fairly niche. TL;DR: if you use backslash in an open pair, you _need_ to
escape it with `\\` for it to work properly.
Note: due to how strings work, you'll need \\\\ if you use a double quote
string, or \\ is interpreted as \ in the string.
This is a bit of a double-sided blade, though; forcing escape of the close
pair in certain places means regex cannot be used. Regex groups for replace
cannot be used either way, so there should be relatively few reasons to have
regex in the closing pair.
Note that all the pairs are run through a \V, so some characters should be
entirely escaped. Direct use consequentially means you can `\v` and get
creative with regexes for pairs.
Section changelog~
v3.0.0-beta8:
- Add updates to |autopairs#AutoPairsDefine| and other functions
- Cleanup
------------------------------------------------------------------------------
*g:AutoPairsCompleteOnlyOnSpace*
number
This variable also exists in a buffer variant.~
Default: 0
Defines whether or not to require a space or end of the line to complete. If
this is 1 and you try: `{|word`, you'll get `{|word`, rather than `{|}word`
if this is 0.
Note that there are a few exceptions to this rule, represented as a part of an
internal variable; |b:autopairs_whitespace_exceptions|
3.0.0-alpha5:~
renamed from *g:AutoPairsCompleteOnSpace* to |g:AutoPairsCompleteOnlyOnSpace|
------------------------------------------------------------------------------
*g:AutoPairsSpaceCompletionRegex*
This variable also exists in a buffer variant.~
Default: '\S'
Note: the value is prefixed with ^|\v| for internal processing reasons, but
this means the regex is very magic by default, and checks characters
immediately after the cursor. Also note that the regex is processed
case-insensitively, and has to evaluate to true to prevent expansion.
Only takes effect if |g:AutoPairsCompleteOnlyOnSpace| is 1. Again, note that
|b:autopairs_whitespace_exceptions| applies.
Example:~
Expanding only on non-alphanumeric characters (... in the English alphabet): >
let g:AutoPairsSpaceCompletionRegex = '\w'
<
Alternatively, if non-english letters are used: >
let g:AutoPairsSpaceCompletionRegex = '[[:lower:][:upper:]0-9]'
<
But do note the caveats of both |[:upper:]| and |[:lower:]|. That said, Vim is
good at dealing with unicode, all things considered, so they should usually be
good enough. Both [:upper:] and [:lower:] seem redundant, but many groups
(including both of these) blatantly disregard the case insensitive flag,
meaning both are required in spite of the regex fundamentally being
case-insensitive
------------------------------------------------------------------------------
*g:AutoPairsAutoBuildSpaceWhitelist*
number
This variable also exists in a buffer variant~
Default: 1
Whether or not to prepopulate |g:AutoPairsNextCharWhitelist|
------------------------------------------------------------------------------
*g:AutoPairsNextCharWhitelist*
list
This variable also exists in a buffer variant~
Default: [] when |g:AutoPairsAutoBuildSpaceWhitelist| is 0; otherwise, dynamic
based on close pairs not in *g:AutoPairsQuoteClosingChar* , which is a list of
characters that count as closing a string. Must not be confused with
|g:AutoPairsQuotes|, which are currently two different options. This may
change in the future.
Only takes effect when |g:AutoPairsCompleteOnlyOnSpace| = 1 (particularly,
when the buffer variant is 1)
Takes any number of characters that act as an exception to only inserting when
there's whitespace after the cursor. Note that this variable does NOT support
multiple bytes per exception; this will not change.
Read: ['a', 'd', 'e'] is okay, ['ac', 'dc', 'e'] is not
------------------------------------------------------------------------------
*b:autopairs_whitespace_exceptions*
[internal]
This variable should not be used directly~
Contains a regex of close pairs that count as an exception to whitespace only
completion when |g:AutoPairsCompleteOnlyOnSpace| is 1.
This variable should not be used directly. There are two control variables:
* To enable or disable automatic population of close pairs that aren't string,
use |g:AutoPairsAutoBuildSpaceWhitelist|
* To manually add pairs to this list, use |g:AutoPairsNextCharWhitelist|
------------------------------------------------------------------------------
*g:AutoPairsOpenBalanceBlacklist*
list[char]
Has a buffer variant~
Default: []
Contains a list of characters that are exceptions to auto-balancing; i.e.
pairs that fully ignore the auto-balancing rules.
Similarly to |g:AutoPairsNextCharWhitelist|, this variable only supports
single characters, and not multibyte values.
Used to populate an internal variable that does the actual heavy lifting.
------------------------------------------------------------------------------
*g:AutoPairsShortcutToggle*
string
This variable also exists in a buffer variant.~
Default: <C-p><C-t> if |g:AutoPairsCompatibleMaps| is 0, <M-p> otherwise
The shortcut to toggle autopairs.
Note that auto-pairs will still be initialized, but no action is taken when
keybinds are pressed, or similar.
------------------------------------------------------------------------------
*g:AutoPairsShortcutFastWrap*
string
This variable also exists in a buffer variant.~
Default: <C-f> if |g:AutoPairsCompatibleMaps| is 0, <M-e> otherwise
Fast wrap the word. All pairs will be considered as a block (including <>).
(|)'hello' after fast wrap at |, the word will be ('hello')
(|)<hello> after fast wrap at |, the word will be (<hello>)
Custom pairs are also taken into consideration for multibyte pairs. In
remaining cases, autopairs jumps through words and places it after the current
word.
See also:~
- |g:AutoPairsMultilineFastWrap|
- |g:AutoPairsMultibyteFastWrap|
------------------------------------------------------------------------------
*g:AutoPairsShortcutJump*
string
This variable also exists in a buffer variant.~
Default: <C-p><C-s> if |g:AutoPairsCompatibleMaps| is 0, <M-n> otherwise
Jump to the first close pair after the cursor, regardless of which it is.
Assuming {}, (), "", and [] are all pairs: >
{
switch (chr) {
case 'a':
for (;;) do something;| Press <C-p><C-s> or <M-n>
break;
default:
throw std::exception("Not implemented for blah blah");
}
}
<
After: >
{
switch (chr) {
case 'a':
for (;;) do something;
break;
default:
throw std::exception("|Not implemented for blah blah");
}
}
<
Note: some jumps may be inaccurate where close == open. This is a detail being
worked out.
Before: >
{
test[]| = new test[]; <C-p><C-s> or <M-n> at |
}
<
After: >
{
test[] = new test[]|;
}
<
------------------------------------------------------------------------------
*g:AutoPairsShortcutBackInsert*
string
This variable also exists in a buffer variant.~
Default: <C-p><C-b> if |g:AutoPairsCompatibleMaps| is 0, <M-b> otherwise
When |autopairs-flymode| does a jump you don't want it to do, you can use this
shortcut to jump back, and automatically do a normal insert.
------------------------------------------------------------------------------
*g:AutoPairsShortcutIgnore*
string
This variable also has a buffer variant~
Default: <C-p><C-e>
Defines what key to use to ignore the next character.
Note that the key itself is a toggle. This means that if you press it twice,
the next pair _won't_ be ignored. It's essentially a way to unignore the next
pair, if the ignore hasn't been used already.
Can be empty to not map a key.
*b:AutoPairsIgnoreSingle*
Buffer variable that controls the ignore logic. Certain functions detect if
this is set to 1, and return an appropriate no-op value. The exact one depends
on the function. Insert returns the key pressed, the <cr> handler returns
nothing (the mapping already has cr in it), etc.
If detected to be 1, it's also set to 0.^1
^1: May change in the future to make <n> ignores possible.
------------------------------------------------------------------------------
*g:AutoPairsMapBS*
int
This variable also exists in a buffer variant.~
Default: 0
Map <BS> to delete brackets and quotes in pair, executes:
inoremap <buffer> <silent> <BS> <C-R>=autopairs#AutoPairsReturn()<CR>
------------------------------------------------------------------------------
*g:AutoPairsMultilineBackspace*
int
This variable exists in a buffer variant~
Default: 0
Whether or not to use multiline deletion on supported pairs
------------------------------------------------------------------------------
*g:AutoPairsBSAfter*
int
This variable exists in a buffer variant~
Default: 1
Whether or not to enable backspacing after a pair. Only takes effect if
|g:AutoPairsMapBS| = 1
Value = 0: []|<bs> -> [|
Value = 1: []|<bs> -> |
------------------------------------------------------------------------------
*g:AutoPairsBSIn*
int
This variable exists in a buffer variant~
Default: 1
Whether or not to enable backspacing within a pair. Only takes effect if
|g:AutoPairsMapBS| = 1.
Value = 0: (|), <bs> at | -> |)
Value = 1: (|), <bs> at | -> |
------------------------------------------------------------------------------
*g:AutoPairsMapCR*
int
This variable also exists in a buffer variant.~
Default: 1
Map <CR> to insert a new indented line if cursor in (|), {|} [|], '|', "|".
Executes: >
inoremap <expr> <buffer> <silent> <CR> AutoPairsReturn()
<
------------------------------------------------------------------------------
*g:AutoPairsCenterLine*
int
Default: 1
When |g:AutoPairsMapCR| is on, center current line after return if the line
is at the bottom 1/3 of the window.
------------------------------------------------------------------------------
*g:AutoPairsMapSpace*
int
This variable also exists in a buffer variant.~
Default: 1
Map <space> to insert a space after the opening character and before the
closing one.
Executes: >
Vim 7.703 and up:
inoremap <buffer> <silent> <SPACE> <C-]><C-R>=AutoPairsSpace()<CR>
Else: inoremap <buffer> <silent> <SPACE> <C-R>=AutoPairsSpace()<CR>
<
------------------------------------------------------------------------------
*g:AutoPairsFlyMode*
int
This variable also exists in a buffer variant.~
Default: 0
Set it to 1 to enable |autopairs-flymode|.
------------------------------------------------------------------------------
*g:AutoPairsMultilineClose*
int
This variable also exists in a buffer variant~
Default: 0
Whether or not to use multiline close.
Note that there's no way to override a bad jump, aside disabling multiline
close and re-inserting the character.
------------------------------------------------------------------------------
*g:AutoPairsShortcutToggleMultilineClose*
type: int
This variable also exists in a buffer variant~
Default: <C-p><C-m>
The shortcut to toggle |g:AutoPairsMultilineClose|
------------------------------------------------------------------------------
*g:AutoPairsDirectoryBlacklist*
path list
Default: []
Defines a set of directories (checked against |getcwd()|) in which the plugin
is completely uninitialized. Note |g:AutoPairsShortcutToggle| cannot enable
autopairs in these directories.
------------------------------------------------------------------------------
*b:autopairs_enabled*
Type: int
Default: 1
This is a buffer variable that defines whether or not autopairs is enabled.
You can use this variable to get more fine-grained control over when the
plugin is enabled as well, if the built-in options aren't satisfactory.
------------------------------------------------------------------------------
*g:AutoPairsInitHook*
Type: |function()| (generally, a funcref)
Default: 0 (intended as null)
This variable lets you do stuff before the initialization of auto-pairs. The
indent behind this variable is to reduce the need for |autopairs-functions| as
much as possible, as the use of these may cause more problems than good. Their
use also requires understanding how they work and when they're supposed to be
called, which may be a bit much to ask for if the intent is a bit of
customization.
It's not required; its primary purpose is for cases where you cannot get away
with using an autocmd, or the execution order of autocmds prevents the
functionality you intend. The function, if present, is triggered as a part of
AutoPairsTryInit, which essentially contains the start of initialization. The
function is, to be specific, called before any other logic to enable variable
initialization.
Example use~
>
fun! s:myFunc()
echo "This is my autopairs hook"
endfun
let g:AutoPairsInitHook = function('s:myFunc')
<
Note~
While the example uses function(), and the type listed is function(), its
underlying |type()| is a funcref. There's many ways to Rome on this one, so
you don't _have_ to use a |function()| to get the funcref.
Note: this may be replaced with a user autocmd in the future.
------------------------------------------------------------------------------
*g:AutoPairsNoJump*
int
Default: 0
This variable also exists in a buffer variant.~
Sets whether or not jump behavior should be invoked. If this variable is set
to 1, no automatic jumps will be performed. Basically:
value = 0:
>
Before: (|) (input: ')', without the quotes)
After : ()|
<
value = 1:
>
Before: (|) (input: ')', without the quotes)
After : ()|)
<
------------------------------------------------------------------------------
*g:AutoPairsSearchCloseAfterSpace*
int
Default: 1
This variable also exists in a buffer variant.~
Sets whether or not to search for close brackets after a space. This is
default behavior in jiangmiao/auto-pairs, and disabled in Krasjet/auto.pairs.
Neither of the two have an option to toggle this, however. Aren't forks
wonderful?
value = 0:
>
Before: [ | ] (input: ']', without the quotes)
After : [ ]| ]
<
value = 1:
>
Before: [ | ] (input: ']', without the quotes)
After : [ ]|
<
------------------------------------------------------------------------------
*g:AutoPairsSingleQuoteMode*
int
Default: 2
Default for upstream: 0
Allowed values: [-1, 0, 1, 2]
This variable also exists in a buffer variant.~