Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Tag: 0.3

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


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.

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. 

For instance:
    def foo():
        return 0

    <!-- snippetysnip:/path/to/ -->

When SnippetySnip is run, the function foo() from is inserted into the html file, which then looks like this:

    <!-- snippetysnip:/path/to/ -->
    def foo():
        return 0
    <!-- snippetysnip_end:/path/to/ -->

SnippetySnip does not care about the format of the comments in your particular language, it only looks for the snippetysnip-strings.

You can have many snippets in a source file, and a target file can reference multiple snippets from multiple sources.

Paths can be relative or absolute.

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.
In the target file, put on a separate line snippetysnipp:FILE_NAME:SNIPPET_NAME
Paths can be relative or absolute. See the example above, or python/SnippetySnip/integration_tests/ for a more extensive one.
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

Download SnippetySnip-<version>.tgz into your vim directory (usually ~/.vim on Linux systems) and do
tar zxf SnippetySnip-<version>.tgz

To make SnippetySnip easier to use, I suggest you set up a mapping in ~/.vimrc. One of the following should do nicely:
map <Leader>s :call SnippetySnip()<CR> "Type <Leader>s to run SnippetySnip
map <C-s> :call SnippetySnip()<CR> "Press Ctrl+s to run SnippetySnip

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:

original target:
    <!-- snippetysnip:source.cpp:foo:(before='[sourcecode language="cpp"]', after='[/sourcecode]') -->

modified target:
    <!-- snippetysnip:source.cpp:foo:(before='[sourcecode language="cpp"]', after='[/sourcecode]') -->
    [sourcecode language="cpp"]
    <!-- snippetysnip_end:source.cpp:foo -->

(This was motivated by the fact that html-comments do not work well inside [sourcecode] blocks on Wordpress)
Something went wrong with that request. Please try again.