forked from google/styleguide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimscriptfull.xml
1534 lines (1498 loc) · 48.9 KB
/
vimscriptfull.xml
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
<?xml version = '1.0'?>
<?xml-stylesheet type="text/xsl" href="styleguide.xsl"?>
<GUIDE title="Google Vimscript Guide">
<p class="revision">
Revision 1.1
</p>
<address>
Nate Soares<br/>
Joshua Hoak<br/>
David Barnett<br/>
</address>
<OVERVIEW>
<CATEGORY title="Background">
<p>
This is the in-depth vimscript guide. If you're just a casual user
looking to write a plugin, the
<a href="vimscriptguide.html">abbreviated style guide</a> is for you.
</p>
<p>
This rather rotund guide dives into justifications and clarifications.
It provides an idealized set of rules that are rather too draconian to
push on casual scripters.
</p>
<p>
It's for users who want to know why certain decisions were made in the
abbreviated guide and who want to learn a thing or two about using
vimscript safely.
</p>
<p>
Fair warning: Vimscript is a maddening abyss. When you gaze into it, it
gazes also into you. Proceed with caution.
</p>
</CATEGORY>
</OVERVIEW>
<CATEGORY title="Portability">
<p>
Vim is highly configurable. Users can change many of the default
settings, including the case sensitivity, the regular expression rules,
the substitution rules, and more. In order for your vimscript to work
for all users, follow these guidelines:
</p>
<ul>
<li>
Always prefix regular expressions with one of <code>\m</code>,
<code>\v</code>, <code>\M</code>, or <code>\V</code> (prefer
tersity)
<ul>
<li>
Users can change the global "magic level" of regular expressions.
This changes how atoms are parsed in regular expressions,
including <code>.</code>, <code>*</code>, and <code>{</code>.
</li>
<li>
Even if your regular expression does not contain characters which
are affected by the <code>magic</code> setting you must prefix it
with one of the magic control atoms. This future-proofs your
regular expression against other devs modifying it and forgetting
to add the control atom.
</li>
<li>
If you have no opinion about what type of regular expression to
use, prefer the one which makes your regular expression most
concise.
</li>
</ul>
</li>
<li>
Avoid using <code>:s[ubstitute]</code> in scripts.
<ul>
<li>
<code>:substitute</code> moves the cursor.
</li>
<li>
<code>:substitute</code> outputs an error message when the match
does not exist.
</li>
<li>
The meaning of the <code>g</code> flag depends upon the
<code>gdefault</code> setting. If you do use
<code>:substitute</code> you must save <code>gdefault</code>, set
it to <code>0</code> or <code>1</code>, perform the substitution,
and then restore it.
</li>
<li>
Script authors who want a safe way to replace text in the buffer
are encouraged to use <code>maktaba#buffer#Replace</code>.
</li>
</ul>
</li>
<li>
Always use case-explicit operators for strings (<code>=~#</code> and
<code>=~?</code>, never <code>=~</code>).
<ul>
<li>
This also applies to <code>!~ == != > >= <</code> and
<code><=</code>
</li>
<li>
This only applies for strings. <code>==</code> and
<code>>=</code> are fine for numbers, but <code>==#</code> and
<code>>=#</code> must be used for strings.
</li>
<li>
The behavior of <code>=~</code> and friends is dependant upon the
<code>ignorecase</code> setting.
</li>
<li>
You may break this rule when you explicitly want to obey the
user's <code>ignorecase</code> setting. Be prepared to justify
your reasoning.
</li>
</ul>
</li>
<li>
When using regular expressions as arguments to functions, prepend them
with <code>\c</code> or <code>\C</code>.
<ul>
<li>
This forces case to be either explicitly matched or ignored.
</li>
<li>
This is recommended, but not required, when comparing regexes with
operators that specify case sensitivity (<code>=~#</code>, etc.).
</li>
<li>
This rule applies when your regexes are matching syntax, external
APIs, external messages, and most other cases.
</li>
<li>
It does not apply when matching text in the buffer. When matching
text in the buffer you should honor the <code>ignorecase</code>
setting.
</li>
<li>
You may also ignore this rule any time that you explicitly want to
honor the <code>ignorecase</code> setting. Be prepared to justify
your reasoning.
</li>
</ul>
</li>
<li>
Always use <code>normal!</code> instead of <code>normal</code>.
<ul>
<li>
If you forgo the <code>!</code> the command will use the user's
key mappings and you have literally no idea what your macro will
do.
</li>
</ul>
</li>
<li>
Always use the <code>noremap</code> family of commands.
<ul>
<li>
Your plugins generally shouldn't introduce mappings, but if they
do, the <code>map</code> command respects the users existing
mappings and could do anything.
</li>
</ul>
</li>
<li>
When using <code>catch</code>, match the error code rather than the
error text.
<ul>
<li>
The error text may be locale-dependant.
</li>
<li>
See <code>:help error-messages</code>.
</li>
</ul>
</li>
</ul>
<p>
In general, guard all commands and functions against user settings.
</p>
</CATEGORY>
<CATEGORY title="Language Guide">
<ul>
<li>
Line continuations: <strong>Yes</strong>
<ul>
<li>
Plugins that support vi compatibility mode must save and restore
compatibility options as described in the
<strong>Errata section</strong> so line continuations work properly.
</li>
</ul>
</li>
<li>
Exceptions: <strong>Yes, with caution</strong>
<ul>
<li>
Always use an error code in thrown exception messages.
</li>
<li>
Prefer the <code>maktaba#error</code> codes found in
<code>maktaba</code>.
</li>
<li>
Fall back to the vim error codes. See
<code>:help error-messages</code>.
</li>
<li>
Generate custom error messages using
<code>maktaba#error#Message</code>.
</li>
</ul>
</li>
<li>
Global Variables: <strong>As configuration only</strong>
<ul>
<li>
See the plugin guide.
</li>
</ul>
</li>
<li>
Messaging: <strong>As little as possible.</strong>
<ul>
<li>
Loud scripts are annoying.
</li>
<li>
Message the user when an error has occured.
</li>
<li>
Message the user when an operation which takes a long time has
begun work.
</li>
<li>
Avoid messaging otherwise.
</li>
</ul>
</li>
<li>
Type checking:
<strong>Use strict and explicit checks where possible.</strong>
<ul>
<li>
Vimscript has unsafe, unintuitive behavior when dealing with some
types. For instance, <code>0 == 'foo'</code> evaluates to true.
</li>
<li>
Use strict comparison operators where possible. When comparing
against a string literal, use the <code>is#</code> operator.
Otherwise, prefer <code>maktaba#value#IsEqual</code> or check
<code>type()</code> explicitly.
</li>
<li>
Check variable types explicitly before using them. Use functions
from <code>maktaba#ensure</code>, or check
<code>maktaba#value</code> or <code>type()</code> and throw your own
errors.
</li>
<li>
Use <code>:unlet</code> for variables that may change types,
particularly those assigned inside loops.
</li>
</ul>
</li>
<li>
FuncRefs: <strong>No in most cases.</strong>
<ul>
<li>
FuncRefs have inconsistently enforced naming restrictions.
(Functions can have names that FuncRefs can not.)
</li>
<li>
FuncRefs have inconsistent ability to be reassigned (in Vim
7.2 and before you must unlet a FuncRef before assigning it).
</li>
<li>
In most instances where a FuncRef is needed a string works
just as well: just pass the string that you would use to make
the FuncRef.
</li>
<li>
Consider using <code>maktaba#function</code> instead to create and
manipulate handles to functions.
</li>
</ul>
</li>
<li>
Python: <strong>Sparingly</strong>
<ul>
<li>
Hurts code reuse since python code embedded in python plugins is
awkward to share between plugins.
</li>
<li>
Using python introduces python language version dependencies, which
are likely to get stale.
</li>
<li>
Exception: It's reasonable to use python for plugin functionality
that needs to do work in the background, as vimscript can not do
this.
</li>
</ul>
</li>
<li>
Ruby: <strong>No</strong>
<ul>
<li>
We can not assume ruby interoperability.
</li>
<li>
You shouldn't depend upon the version of the ruby language that the
user has installed.
</li>
</ul>
</li>
<li>
Lua: <strong>No</strong>
<ul>
<li>
For the same reasons an Ruby.
</li>
</ul>
</li>
<li>
Dict Functions: <strong>Encouraged</strong>
<ul>
<li>
Vimscript can attach functions to dictionaries. Such functions
have access to the <code>self</code> parameter which access
the dict state.
</li>
<li>
Use these where you would use a class in python.
</li>
<li>
Do not over-use this feature; it is not necessary for helper
functions or API functions, only for encapsulated objects.
</li>
</ul>
</li>
</ul>
<p>
All other language features are fair game.
</p>
</CATEGORY>
<CATEGORY title="Structure">
<ul>
<li>
Provided functionality should be packed into modular plugins.
<ul>
<li>
Every function in your plugin should be specific to your
plugin.
</li>
<li>
General utility functions should be abstracted into library plugins.
</li>
<li>
Manage dependencies with <code>maktaba</code>.
</li>
</ul>
</li>
<li>
<code>plugin-names-like-this</code>
<ul>
<li>
Plugin names should be descriptive and concise.
</li>
</ul>
</li>
<li>
Each plugin must consist of one directory (or code repository), sharing
a name with the plugin (with a "vim-" prefix or ".vim" suffix if
desired).
</li>
<li>
Plugin metadata should be declared in the addon-info.json format (see
the <a href="http://goo.gl/CUXJZC">VAM documentation</a> for details).
</li>
<li>
Functions should go in the <code>autoload/</code> subdirectory of
your plugin.
<ul>
<li>
This allows them to be late-loaded, which speeds up startup
time.
</li>
<li>
This helps vim enforce namespacing conventions.
</li>
</ul>
</li>
<li>
Each file in the <code>plugin/</code> or <code>instant/</code> directory
should begin with the boilerplate
<CODE_SNIPPET>
let [s:plugin, s:enter] = maktaba#plugin#Enter(expand('<sfile>:p'))
if !s:enter
finish
endif
</CODE_SNIPPET>
(This prevents re-entry and allows users to selectively disable
functionality.)
</li>
<li>
User configuration should be via plugin flags defined in
<code>instant/flags.vim</code>.
<ul>
<li>
Define flags with
<code>call s:plugin.Flag('FLAGNAME', DEFAULT_VALUE)</code>.
</li>
<li>
Users can configure these flags using the <code>:Glaive</code>
command (see <a href="https://github.com/google/glaive">glaive</a>).
</li>
</ul>
</li>
<li>
Commands, autocommands, mappings, and settings changes should
occur either in the <code>plugin/</code> or the
<code>ftplugin/</code> subdirectories.
<ul>
<li>
All commands should be defined in <code>plugin/commands.vim</code>
or <code>ftplugin/</code> files.
</li>
<li>
Autocommands should be defined in <code>plugin/autocmds.vim</code>,
inside an augroup.
</li>
<li>
Mappings should be defined in <code>plugin/mappings.vim</code> and
will be disabled unless explicitly enabled by users.
</li>
<li>
If the plugin configures any standard vim settings, those should be
configured in <code>plugin/settings.vim</code> or
<code>instant/settings.vim</code>.
</li>
</ul>
</li>
<li>
Avoid using the <code>after/</code> subdirectory.
<ul>
<li>
<code>after/</code> should be reserved for the user.
</li>
<li>
It is difficult for the user to add their own overrides when
plugins use <code>after/</code>.
</li>
</ul>
</li>
</ul>
<STYLEPOINT title="Libraries vs. Functionality">
<SUMMARY>
Separate library-providing plugins from command-providing plugins.
</SUMMARY>
<BODY>
<p>
Many plugins provide either user functionality (commands,
autocommands, etc) or an API (of autoloaded functions) but not both.
This separation is encouraged, as it allows other plugins to pull in a
library without also pulling in commands, setting changes, and other
plugin functionality that affects the end user.
</p>
</BODY>
</STYLEPOINT>
<STYLEPOINT title="Configuration">
<SUMMARY>
Don't clobber user settings. Provide as much configurability as
possible: that's what Vim's all about.
</SUMMARY>
<BODY>
<ul>
<li>
Use maktaba flags for plugin configuration. Users can configure them
using the <code>:Glaive</code> command.
</li>
<li>
Check if configuration variables exist before setting them.
<CODE_SNIPPET>
if !exists('g:myplugin_option')
let g:myplugin_option = 1
endif
</CODE_SNIPPET>
</li>
</ul>
</BODY>
</STYLEPOINT>
</CATEGORY>
<CATEGORY title="Style Guide">
<p>
Follow google-wide style conventions. Mimic google python style when
in doubt.
</p>
<STYLEPOINT title="Documentation">
<SUMMARY>
Use <a href="https://github.com/google/vimdoc">vimdoc</a>.
</SUMMARY>
<BODY>
<p>
Provide help files generated by
<a href="https://github.com/google/vimdoc">vimdoc</a>. Write
documentation in .vim files in conformance with the vimdoc standards
and include fields like "description" and "author" in the
addon-info.json file (see the
<a href="http://goo.gl/CUXJZC">VAM documentation</a>).
</p>
</BODY>
</STYLEPOINT>
<STYLEPOINT title="Whitespace">
<SUMMARY>
Follow google-wide conventions.
</SUMMARY>
<BODY>
<ul>
<li>
Use two spaces for indents.
</li>
<li>
Do not use tabs.
</li>
<li>
Use spaces around operators except for arguments to commands.
<ul>
<li>
Using spaces around operators for commands is often invalid
syntax. This is inconsistently enforced by vimscript. To be
safe, always omit whitespace around arguments to commands.
</li>
<li>
<CODE_SNIPPET>
let s:variable = "concatenated " . "strings"
command -range=% MyCommand
</CODE_SNIPPET>
<BAD_CODE_SNIPPET>
let s:variable="concatenated "."strings"
command -range = % MyCommand
</BAD_CODE_SNIPPET>
</li>
</ul>
</li>
<li>
Do not introduce trailing whitespace.
<ul>
<li>
You need not go out of your way to remove it.
</li>
</ul>
</li>
<li>
Restrict lines to 80 columns wide.
</li>
<li>
Indent continued lines by two tabs (four spaces).
</li>
<li>
Do not waste whitespace aligning common segments of similar
commands. It is both difficult and expensive to maintain.
<ul>
<li>
<CODE_SNIPPET>
command -bang MyCommand call myplugin#foo()
command MyCommand2 call myplugin#bar()
</CODE_SNIPPET>
<BAD_CODE_SNIPPET>
command -bang MyCommand call myplugin#foo()
command MyCommand2 call myplugin#bar()
</BAD_CODE_SNIPPET>
</li>
</ul>
</li>
</ul>
<SUBSECTION title="Line Continuations">
<ul start="7">
<li>
Prefer line continuations on semantic boundaries.
<ul>
<li>
<CODE_SNIPPET>
command SomeLongCommand
\ call some#function()
</CODE_SNIPPET>
<BAD_CODE_SNIPPET>
command SomeLongCommand call
\ some#function()
</BAD_CODE_SNIPPET>
</li>
<li>
Use your best judgement.
</li>
</ul>
</li>
<li>
Place one space after the backslash denoting a line continuation.
<ul>
<li>
When continuing a multi-line command a pipe can be substituted
for this space as necessary, as follows:
<CODE_SNIPPET>
autocommand BufEnter <buffer>
\ if !empty(s:var)
\| call some#function()
\|else
\| call some#function(s:var)
\|endif
</CODE_SNIPPET>
</li>
</ul>
</li>
<li>
Do not continue multi-line commands when you can avoid it. Prefer
function calls.
</li>
</ul>
</SUBSECTION>
<SUBSECTION title="Comments">
<ul>
<li>
Place a space after the <code>"</code> before the comment text.
<ul>
<li>
<CODE_SNIPPET>
" I am a line comment.
call call(s:my_function)
</CODE_SNIPPET>
</li>
</ul>
</li>
<li>
Do not use inline comments.
<ul>
<li>
Some commands treat them as comments and others as unclosed
quotes. There are many edge cases. It's difficult to get
right and difficult to maintain.
</li>
<li>
Where you would use an inline comment, put a line comment on
the line above.
</li>
</ul>
</li>
<li>
When leaving blank lines in comments, include the quote in the
blank line.
<ul>
<li>
<CODE_SNIPPET>
" I am one continuous
"
" comment block
</CODE_SNIPPET>
</li>
</ul>
</li>
</ul>
</SUBSECTION>
</BODY>
</STYLEPOINT>
<STYLEPOINT title="Variables">
<SUMMARY>
<p>
<code>plugin-names-like-this</code>,
<code>FunctionNamesLikeThis</code>,
<code>CommandNamesLikeThis</code>,
<code>augroup_names_like_this</code>,
<code>variable_names_like_this</code>.
</p>
<p>
Prefix all variables with their scope.
</p>
</SUMMARY>
<BODY>
<ul>
<li>
<code>variable_names_like_this</code>
<ul>
<li>
FuncRef variables count as functions and should be named like
functions.
</li>
<li>
This (pathological) convention is enforced by vim itself.
</li>
</ul>
</li>
<li>
Prefix global variables with <code>g:</code>
<ul>
<li>
Vimscript allows you to create global variables without
prefixing them.
</li>
<li>
It is very bad practice to introduce non-prefixed global
variables into scope.
</li>
<li>
Global variables should only be used for plugin configuration.
</li>
<li>
This does not apply to functions defined in
<code>autoload</code> directories.
</li>
</ul>
</li>
<li>
Prefix script-local variables with <code>s:</code>
<ul>
<li>
This prevents namespace collisions between plugins.
</li>
<li>
This also applies to script-local functions.
</li>
</ul>
</li>
<li>
Prefix function arguments with <code>a:</code>
<ul>
<li>
This is enforced by vim itself.
</li>
</ul>
</li>
<li>
Prefix function-local variables with <code>l:</code>
<ul>
<li>
This is not enforced by vimscript but is good practice.
</li>
<li>
It helps you remember that all other variables must be
prefixed with scope.
</li>
<li>
<code>l:</code> disambiguates between function-local and
vim-predefined variables. For example, <code>count</code>
refers to
<code>v:count</code>, not <code>l:count</code>.
</li>
<li>
It future proofs your scripts against the introduction of new
vim-predefined variables.
</li>
</ul>
</li>
<li>
Prefix pre-defined vim variables with <code>v:</code>
<ul>
<li>
This is not enforced by vimscript but is good practice.
</li>
<li>
It provides context as to where the (undeclared) variable is
coming from.
</li>
<li>
It reminds you that the variable can not be assigned to.
</li>
</ul>
</li>
<li>
Prefix buffer-local variables with <code>b:</code>
<ul>
<li>
This is useful for plugins that keep per-buffer state.
</li>
</ul>
</li>
</ul>
</BODY>
</STYLEPOINT>
<STYLEPOINT title="Strings">
<SUMMARY>
Prefer single quotes.
</SUMMARY>
<BODY>
<p>
Prefer single quoted strings. Specifically, in order of precedence:
</p>
<ul>
<li>
Always use single quotes for regular expressions.
<ul>
<li>
<code>'\s*'</code> is not the same as <code>"\s*"</code>
</li>
<li>
Single quotes will prevent the need for excessive backslashes.
</li>
<li>
Double single quotes escape to one single quote in single
quoted strings: <code>'example ('')'</code> represents the
string
<code>example (')</code>
</li>
</ul>
</li>
<li>
If your string requires escape characters (<code>\n</code>,
<code>\t</code>, etc.) use double quotes.
<ul>
<li>
Escapes can not be expressed in single quoted strings.
</li>
<li>
Remember that <code>'\n'</code> in a regex does not represent a
newline, but rather "\n". You only need to use double quotes
when you want to embed the represented character itself (e.g. a
newline) in the string.
</li>
</ul>
</li>
<li>
If your string contains no escapes nor single quotes, use single
quoted strings.
<ul>
<li>
Most strings in vimscript are regexes, so this provides maximum
consistency.
</li>
</ul>
</li>
<li>
If your non-regex string contains single quotes but no double
quotes, use double quotes.
<ul>
<li>
Don't bother escaping strings if you don't have to.
</li>
<li>
This is similar to the python string rules.
</li>
</ul>
</li>
<li>
If your string contains both single and double quotes, use whichever
quoting style requires less escaping.
<ul>
<li>
Break ties in favor of single quotes.
</li>
</ul>
</li>
</ul>
</BODY>
</STYLEPOINT>
<STYLEPOINT title="Settings">
<SUMMARY>
Prefer long names. Set settings locally.
</SUMMARY>
<BODY>
<ul start="6">
<li>
Prefer long names of built in settings (i.e. <code>tabstop</code>
over
<code>ts</code>).
</li>
<li>
Set local settings unless you explicitly want to set global
settings.
<ul>
<li>
Use <code>setlocal</code> and <code>&l:</code> instead of
<code>set</code> and <code>&</code>.
</li>
</ul>
</li>
</ul>
</BODY>
</STYLEPOINT>
</CATEGORY>
<CATEGORY title="Usage Guide">
<p>
Vim plugins should provide any or all of the following:
<strong>Commands,</strong> <strong>Autocommands,</strong>
<strong>Functions,</strong> <strong>Statusline Flags, and</strong>
<strong>Mappings.</strong>
</p>
<STYLEPOINT title="Commands">
<SUMMARY>
<ul>
<li>Define in <code>plugin/commands.vim</code>.</li>
<li>CommandNamesLikeThis.</li>
<li>Prefer semantic names to a unified prefix.</li>
<li>Do not use <code>[!]</code></li>
<li>Extract logic into functions.</li>
</ul>
</SUMMARY>
<BODY>
<ul>
<li>
<code>CommandNamesLikeThis</code>
</li>
<li>
Commands should be defined in one block with no whitespace between
them.
<ul>
<li>
Name commands semantically at the expense of a common prefix.
</li>
<li>
<BAD_CODE_SNIPPET>
command WhitespaceFixTrailing
command WhitespaceFixIndentation
</BAD_CODE_SNIPPET>
<CODE_SNIPPET>
command FixTrailingWhitespace
command FixIndentation
</CODE_SNIPPET>
</li>
</ul>
</li>
<li>
Use <code>command</code> without a bang.
<ul>
<li>
This notifies users to command name conflicts immediately at
startup.
</li>
<li>
Command name collisions are an error and should not fail
silently.
</li>
<li>
Plugins are guarded against re-entry, so a single vim session
should never attempt to re-define defined commands.
</li>
</ul>
</li>
<li>
Do not put logic in commands.
<ul>
<li>
Delegate to functions instead.
</li>
<li>
Pass non-argument command parameters (<code><bang></code>,
<code><register></code>, etc.) before argument parameters
(<code><f-args></code>, etc.).
</li>
<li>
Otherwise variable-length argument functions are difficult to
implement.
</li>
</ul>
</li>
<li>
Do not autoload commands.
<ul>
<li>
Autoloaded commands will not be available until after a function
in the same file is called.
</li>
<li>
Commands intended to be used in the .vimrc should be defined in
a <code>instant/commands.vim</code> file in plugins using
maktaba, or explicitly installed via an autoload function in
non-maktaba plugins.
</li>
</ul>
</li>
</ul>
<SUBSECTION title="Conventions">
<ul>
<li>
Pass <code><bang></code> to functions with
<code>'<bang>' == '!'</code>.
<ul>
<li>
The function should receive a boolean parameter, not a string.
</li>
</ul>
</li>