-
Notifications
You must be signed in to change notification settings - Fork 0
/
tSkeleton.txt
executable file
·324 lines (237 loc) · 11.6 KB
/
tSkeleton.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
*tSkeleton.txt* tSkeleton -- File Templates and Code Skeletons
Author: Thomas Link, samul AT web.de
-----------------------------------------------------------------------
*tSkeleton-install*
Install~
Extract tSkeleton.zip (or copy the contained files) to your local
vimfiles directory (see also |add-global-plugin|). The files
"bits.samples" and "map.samples" must be copied to their proper places
in order to become accessible:
skeletons/
FILE TEMPLATES ...
map/
MAP FILES FOR CONDITIONAL EXPANSION
menu/
AUTO-GENERATED MENU CACHE
bits/
&filetype.txt (single line templates)
general/
GENERAL CODE SKELETONS ...
&filetype/
FILETYPE SPECIFIC CODE SKELETONS: ONE SKELETON PER FILE ...
If you re-use skeletons from version 1.0 with a later version, you have
to update the |tSkeleton-place-holder| markup.
Then run >
(Linux etc.) >
:helptags $HOME/.vim/doc
(Windows) >
:helptags $VIM/vimfiles/doc
You might want to use imaps.vim's (vimscript #244 or vimscript #475) place
holders in conjunction with template bits.
If you don't use imaps.vim, you can :call TSkeletonMapGoToNextTag().
This will map <c-j> to a function that makes the cursor jump to the next
tag.
-----------------------------------------------------------------------
*tSkeleton-usage*
File templates~
The file skeletons are stored in the skeletons subdirectory. Filling in
a skeleton when creating a new file is controlled by |:autocmd|. This
provides greater flexibility than a &filetype based approach.
Currently, the following file types are supported by default:
- batch.bat
- deplate.txt
- latex.tex
- php.inc.php
- php.php
- plugin.vim
- ruby.rb
- shell.sh
- text.txt
In order to add a new mode, save a skeleton file to
~/.vim/skeletons/file.suffix and add something like this to your .vimrc
file: >
autocmd BufNewFile *.suffix TSkeletonSetup template.suffix
autocmd BufNewFile /here/*.suffix TSkeletonSetup othertemplate.suffix
*tSkeleton-place-holder*
In skeleton files, you can use the following tags:
<+FILE NAME ROOT+> :: the file name root
<+FILE NAME+> :: the file name
<+FILE SUFFIX+> :: the file suffix
<+FILE DIRNAME+> :: the file's directory
<+NOTE+> :: a note
<+DATE+> :: the current date (the format is controlled via
g:tskelDateFormat)
<+AUTHOR+> :: the author's name (g:tskelUserName)
<+EMAIL+> :: the author's e-mail (g:tskelUserEmail)
<+WEBSITE+> :: the author's homepage (g:tskelUserWWW)
<+LICENSE+> :: the name of the license this file is released
under (g:tskelLicense)
In order to define your own tag, you have to define a function called
TSkeleton_TAGNAME() that returns the text to be filled in.
tSkeleton also supports the following pseudo-tags:
<+CURSOR+> :: where to place the cursor after insertion
<+&NAME+> :: a vim option
<+g:NAME+> :: a global variable
<+b:NAME+> :: a buffer local variable
<+?QUERY?+> :: query the user[1]
<+?VAR|QUERY?+> :: query the user and propose some choices from
the variable b:tskelChoices_{VAR} (separated by
"\n")[1]
<+bit:BIT>, <+bit:BIT|"DEFAULT">, <+bit:BIT|COMMANDS> :: insert a
bit; if the bit isn't defined for the current
filetype, use DEFAULT; if DEFAULT matches ".*"
insert it as a string; otherwise interpret it
as a command sequence to be fed to normal
<+tskel:TSKELETON> ... :: same as the above
<+call:FUNCTION(ARGS)+> :: insert the result value of some function
[1] If the query ends with a colon, the second question mark will be
removed.
Check out the "test_tSkeleton" skeleton for examples.
*tSkeleton-modifiers*
Tags can be modified using modifiers, like in: >
<+TAG NAME:MODIFIER+>
Known modifiers:
l :: lower case
u :: upper case
c :: capitalize
C :: transform to CamelCase
s/FROM/TO/ :: replace text (actually a s//g); this has to come last;
the pattern separator can be selected arbitrarily
Example for a ruby class template: >
class <+FILE NAME ROOT:cs*\W*_*+>
<+CURSOR+>
end
-----------------------------------------------------------------------
*tSkeleton-code-skeletons*
*tSkeleton-bits*
Bits/Code Skeletons~
Smaller skeleton bits are stored in SKELETONS/bits/FILETYPE/ or
SKELETONS/bits/general/. I.e., code skeletons can be filetype specific
or generally available.
Skeleton bits can be filled in by typing: >
:TSkeletonBit NAME
For this command, command line completion is implemented. Calling this
command will insert the contents of the respective file below the
current line.
NOTE: Bit names should not contain ampersand (as these are interpreted
as menu accelerators) and periods (which are interpreted as the
separating submenu names from entry names). Other special characters can
be included by encoding them in hex form as %XX as it is done in URLs.
Example: "%5Csection" becomes "\section".
*tSkeleton-key-bindings*
The default key bindings for inserting code skeletons are:
<Leader>## ... Expand name under cursor
<Leader>#t ... Insert code skeleton via command line
<c-\><c-\> ... In insert mode, expand the bit before the cursor
*g:tskelKeyword_{&filetype}*
A bit name usually is the |word| under the cursor. If this doesn't fit
your needs, you can define g:tskelKeyword_{&filetype} to define what
makes up a skeleton name. Example: >
let g:tskelKeyword_viki = '\(#\|{\)\?[^#{[:blank:]]\{-}'
*tSkeleton-embedded-code*
Code skeletons may contain vim code that is evaluated before or after
expanding the tags. The before/after blocks are fed to |:exec| and must
not contain function definitions.
*<tskel:msg>* *<tskel:before>* *<tskel:after>*
*<tskel:here_before>* *<tskel:here_after>*
These special regions must appear in the following order:
<tskel:msg> (An explantory message to be displayed after template expansion)
<tskel:before>
<tskel:after>
<tskel:here_before>
<tskel:here_after>
BibTeX example: >
<tskel:before>
let b:tskelArticleID = input("ID of bibentry: ")
if b:tskelArticleID == "" | let b:tskelArticleID = "<+CURSOR+>" | endif
</tskel:before>
<tskel:after>
unlet b:tskelArticleID
</tskel:after>
@INCOLLECTION{<+b:tskelArticleID+>,
author = {<+CURSOR+>},
title = {<+ARTICLE TITLE+>},
crossref = {<+CROSSREF+>},
pages = {<+PAGES+>},
abstract = {[[~/Projects/Sci/Abstracts/<+b:tskelArticleID+>.txt]]},
}
<++>
In the above example, we query the user for an ID and insert this ID as
entry key and as an abstract's file name.
The before/after blocks are evaluated in the destination buffer. The
variants here_before/here_after are evaluated in the scratch buffer for
the current code skeleton.
*tSkeleton-groups*
*g:tskelBitGroup_{&filetype}*
Groups~
Some filetype's bits might be of use for other filetypes too. You can
make them accessible by defining a g:tskelBitGroup_{&filetype} variable.
E.g., in php mode all html bits are made accessible by setting this
variable (the default): >
let g:tskelBitGroup_php = "php\nhtml"
Bits of type "general" are always accessible.
*tSkeleton-context*
*tSkeleton-map*
Maps -- Context-sensitive expansion~
To some extent, tSkeleton is capable of offering the user only a small
selection of eligible bits for a specific context if a map file
($VIMFILES/skeletons/map/{&filetype}) is provided. Such a map file is made up
of regular expressions matching a specific context (before the cursor
only) and a blank-separated list of eligible bits. The regexp and the
list are separated by whitespace: >
REGEXP BIT1 BIT2 ... BITn
Example: >
<form\\([^>]\\|\\n\\)* name= action= method=
If an eligible bit is undefined, the name is inserted as such.
*tSkeleton-minibits*
Minibits~
Mini bits are kept in the files:
- $PWD/.tskelmini
- $VIMFILES/skeletons/bits/{&filetype}.txt
These files contain whitespace-separated pairs of bit names and their
expansions. These files are meant to keep expansions of accronyms and
abbreviations and the like. Example: >
IMHO In my humble opinion
AFAIK As far as I know
Minibits are not displayed in the menu. (This will probably change.)
*tSkeleton-menu*
*g:tskelMenuPrefix*
Menu~
If g:tskelMenuPrefix is non-empty, tSkeleton will display a menu
containing all eligible bits for a certain filetype.
The menu can be hierarchical and certain entries may have shortcuts by
properly naming the bits. Example: >
&Environment.&Quote
&Environment.Q&uotation
This will create the submenu "Environment" that can be selected by
typing "e" (on Windows) and two entries, the first of which can be
selected by typing "q" and the second by typing "u".
Be aware that the actual bit names are Quote and Quotation (i.e. the
submenu and the ampersand are stripped off).
-----------------------------------------------------------------------
*tSkeleton-commands*
Commands~
*:TSkeletonNewFile*
:TSkeletonNewFile ?template, ?destDir, ?destFileName
*:TSkeletonEdit*
:TSkeletonEdit ?skelDir
*:TSkeletonBit*
:TSkeletonBit NAME
-----------------------------------------------------------------------
*tSkeleton-utilities*
Utilities~
*TSkeletonIncreaseRevisionNumber()*
The function TSkeletonIncreaseRevisionNumber() provides a way to
automatically update a revision number in the form >
@Revision: 1.0.168
In order to use this function, add something like this to your |vimrc|
file: >
autocmd BufWritePre * call TSkeletonIncreaseRevisionNumber()
*:TSkeletonCleanUpBibEntry*
The TSkeletonCleanUpBibEntry command can be used to purge the current bibtex
entry from expendable fields (i.e., lines matching <+.\{-}+>).
For bibtex files, this command is bound to: <Leader>tc
*TSkeletonMapGoToNextTag()*
*TSkeletonGoToNextTag()*
If you don't want to install imaps.vim, this function will map <c-j> to
TSkeletonGoToNextTag() in order to easily jump between tags.