Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 84 lines (56 sloc) 4.238 kb
ba40f98 @knatten Version 0.1: Initial upload
knatten authored
1 This is a mirror of http://www.vim.org/scripts/script.php?script_id=3717
2
3 SnippetySnip is a vim tool for automatically inserting parts (snippets) of other files in a file. I wrote it to insert sourcecode examples from source files into html blog-posts, but it can be used for all sorts of text files.
4
f3f769d @knatten Version 0.5
knatten authored
5 In the source file, you mark up a region of text (a snippet) and give it a name. In the target file, you mark where you want this particular snippet inserted.
ba40f98 @knatten Version 0.1: Initial upload
knatten authored
6
7 For instance:
8
9 source.py:
10 (...)
11 #snippetysnip_begin:foo
12 def foo():
13 return 0
14 #snippetysnip_end
15 (...)
16
17 target.html:
18 <p><code>
19 <!-- snippetysnip:/path/to/source.py:foo -->
20 </code></p>
21
22 When SnippetySnip is run, the function foo() from source.py is inserted into the html file, which then looks like this:
23
24 target.html:
25 <p><code>
26 <!-- snippetysnip:/path/to/source.py:foo -->
27 def foo():
28 return 0
29 <!-- snippetysnip_end:/path/to/source.py:foo -->
30 </code></p>
31
32
6258cba @knatten Version 0.6
knatten authored
33 SnippetySnip does not care about the format of the comments in your particular language, it only looks for the snippetysnip-strings. A snippet name can consist of letters, numbers or any of the characters "-_.".
ba40f98 @knatten Version 0.1: Initial upload
knatten authored
34
35 You can have many snippets in a source file, and a target file can reference multiple snippets from multiple sources.
36
37 Paths can be relative or absolute.
38
db69408 @knatten Version 0.3
knatten authored
39
f3f769d @knatten Version 0.5
knatten authored
40
41 HOW TO USE
42 In the source files, surround each snippet with snippetysnip_begin:SNIPPET_NAME and snippetysnip_end. These tags need to be on separate lines, but except from that, they can be inside the comment style of your choice, depending on the host language. See the example above.
43 In the target file, put on a separate line snippetysnipp:FILE_NAME:SNIPPET_NAME
44 Paths can be relative or absolute. See the example above, or python/SnippetySnip/integration_tests/ for a more extensive one.
45 To run SnippetySnip and insert all your snippets, do ":call SnippetySnip()" without the quotes. It is suggested you make a map to make this easier, see INSTALLATION
46 It can be tedious to type the snippet inclusion strings in the target file. To get this string automatically, go to your source file, place the cursor inside the snippet you want the inclusion string for and do ":call SnippetySnipPrintCurrentSnippetString()" without the quotes. It will print the string for you (with html comments). It is suggested you make a map to make this easier, see INSTALLATION.
47 About cursor position: Since the entire buffer is replaced, it is impossible to exactly remember the cursor position. SnippetySnip does however make a best effort, and puts the cursor back at the same line and column.
48
49
6258cba @knatten Version 0.6
knatten authored
50
51 INSTALLATION
52 Download SnippetySnip-<version>.tgz into your vim directory (usually ~/.vim on Linux systems) and do
53 tar zxf SnippetySnip-<version>.tgz
54
55 To make SnippetySnip easier to use, I suggest you set up a mapping in ~/.vimrc. These should do nicely:
56 map <Leader>s :call SnippetySnip()<CR> "Type <Leader>s to run SnippetySnip
57 map <C-s> :call SnippetySnip()<CR> "Press Ctrl+s to run SnippetySnip
58 map <Leader>S :call SnippetySnipPrintCurrentSnippetString()<CR> "Type <Leader>S to print the name of the current snippet
59
60
61
db69408 @knatten Version 0.3
knatten authored
62 ADVANCED USAGE
63 It is possible to give arguments before="..." and/or after="..." when including a snippet. These arguments will be inserted between the snippet command and the actual snippet. Here is an example, inserting code snippets into Wordpress posts:
64
65 original target:
66 <!-- snippetysnip:source.cpp:foo:(before='[sourcecode language="cpp"]', after='[/sourcecode]') -->
67
68 modified target:
69 <!-- snippetysnip:source.cpp:foo:(before='[sourcecode language="cpp"]', after='[/sourcecode]') -->
70 [sourcecode language="cpp"]
71 imported();
72 code();
73 here();
74 [/sourcecode]
75 <!-- snippetysnip_end:source.cpp:foo -->
76
77 (This was motivated by the fact that html-comments do not work well inside [sourcecode] blocks on Wordpress)
78
f3f769d @knatten Version 0.5
knatten authored
79 If you want SnippetySnipPrintCurrentSnippetString() to include arguments, define g:SnippetySnipArguments. For instance, you can put this line in ~/.vimrc:
80 let g:SnippetySnipArguments = "(before='[sourcecode language=\"cpp\"]', after='}[/sourcecode]')"
81
82 SnippetySnip is also available on github: https://github.com/knatten/SnippetySnip
83
Something went wrong with that request. Please try again.