tags:

views:

184

answers:

2
+2  Q: 

Coda Clips for Vim

I'm currently trying to switch from Coda (a Mac IDE) to Vim. One thing I loved about Coda and my knowledge of Vim cannot replace were the so-called "clips". Basically, you type, say, "new", press TAB, and the text is replaced with a basic XHTML page. And you can add as many keyword/clips combinations as you want.

The most I could get with Vim so far was to create a new file containing my clip, and then use :r FILE in Vim in order to get it inserted, but this is not a very elegant solution, as I'd have to carry these clips around in every directory I have a file I want to use my clips with.

So assuming I've explained things properly, what would be my choices?

+8  A: 

For various editors, there's a functionality called '''snippets''' which tab expands the beginnings of common text (like a HTML div, or C function definition) into a skeleton for that code.

There's a couple vim plugins that present this functionality. Two off the top of my bookmark list:

I heard of another plugin for quick HTML editing that uses snippets recently:

Check those out and see if they're near what you're looking for.


Also, you can define a default BufNewFile action in vim - which lets you read in a skeleton for a file if it doesn't already exist automatically.

                                                *skeleton* *template*
To read a skeleton (template) file when opening a new file: >

  :autocmd BufNewFile  *.c      0r ~/vim/skeleton.c
  :autocmd BufNewFile  *.h      0r ~/vim/skeleton.h
  :autocmd BufNewFile  *.java   0r ~/vim/skeleton.java

Put those (or the equivalent) in your .vimrc (w/o the leading colon) to have them set up automatically every time you run vim.

rampion
Thanks a billion, snipMate is exactly what I was looking for. I'll keep your response in mind, for later on, when I get to know Vim better. Thanks!
XLR3204S
+1 for SnipMate.
jeffjose
+1  A: 

As well as the various snippet plugins, Vim also has an abbreviation feature built in, using the :ab[breviate] command.

For example you can define this:

:ab <h <head>^M</head>^M<body>^M<\body>

Then when you type <h<SPACE> it will expand into the full text. The ^M in the example above are actually carriage returns inserted in the string definition with <ctrl-V><RETURN>.

Dave Kirby