TextMate addi(c)tions

Manfred Stienstra, 16 Dec 2005, 11:08 in ruby on rails and tools, last updated 19 Apr 2006, 16:36 (edit).

For the last few months I’ve been using TextMate on my iBook and on the Lil’ Mac at work. I’ve grown accustomed to the various ‘insert snippet’ commands available in TextMate. Unfortunately Vim doesn’t have these commands and I find myself inserting ^Z in my views.

However, Vim configuration is powerful enough to implement these commands. Make sure you’re in command mode and do the following:

:imap <C-z> <lt>%=  %><Left><Left><Left>
:imap <C-x> <lt>%  %><Left><Left><Left>

This will allow you to insert <%= %> and <% %> into your files during insert mode. It is also possible to insert these commands in ~/.vimrc so you don’t have to define them every time you launch vim.

You can find the other mapping syntax rules on the vim.org website and in your vim help files.

Comments

  1. Kevin 14 days later: (delete | show email)

    Hey, I'd love to know if you have other mappings that are useful! I'm trying to build a lot of HTML mappings like this since I use Vim as my primary editor. Feel free to contact me directly.

    Thanks for the post.
    Kevin

  2. Manfred 18 days later: (delete)

    Actually, I don't use any other mappings at the moment. Unfortunately you can't build context sensitive mappings, so a lot of advanced stuff like closing tags when a </ is detected isn't possible without using external scripts (vim supports Python and Ruby scripts). It might be nice to write a few scripts for this purpose.

    Even more advanced TextMate features, like jumping over arguments of method call snippets will require you to hack vim, you could try to do that and send some patches to Bram (creater of vim), although I'm not sure what is view on functionality like that is.

    Inserting large snippets like a complete doctype clutters the configfile, but can be done. I'll leave that as an exercise for the reader (:

    I promise to post any other nice vim mappings/scripts I might create in the future.

  3. jose 107 days later: (delete)

    nice. Will monitor this page...

Add your comment

In order to fight spam on this blog, posting comments from a browser without javascript is currently not supported.