Editing Textile in VIM

I love Textile. All of my blogs use Textile. In some cases I have even extended Textile to provide additional features, making it a simple matter to add programmatically complex functions with a few extra characters.

Sometimes, though, I like to write my articles off-line and post them later. When I do, I typically use either TextMate in OS X, or Vim (wherever I am, sometimes in an SSH session). Unfortunately, though, there isn’t a lot of support for Textile in VIM. But after a little Googling, I found some.

About a year and a half ago, Dominic Mitchell posted his own Textile syntax file for Vim on his blog. I snapped it up and started using it. There is a slight problem, though, in the way it handles Textile URLs. Apparently thanks to the regex pattern for URL strings lifted from RFC 2396, it allows spaces in URLs, which causes the highlighting to continue after the URL ends.

I’ve applied a fix to the script and posted it here in case anyone (other than me) is actually interested in this sort of thing. Thanks much to Dominic Mitchell for creating this syntax file in the first place; I was not relishing the thought of diving in and creating one myself.

Revised Textile syntax file for VIM

If you wish to use the *.textile extension, as TextMate does, to indicate which files contain Textile syntax, you will want to add the following line to your filetypes.vim, which is located wherever your ftplugin directory is located (on my machine it’s /usr/share/vim/vim62/, but it will be different per-installation and wildly different in Windows):

au BufNewFile,BufRead *.textile setf textile  

10 Responses to “Editing Textile in VIM”


  1. 1 Shadowfiend

    Wow, you just posted this barely a week before I went hunting for it. Rock! Thanks!

  2. 2 Aaron

    You’re quite welcome, Shadowfiend, but thank Dominic for actually writing the thing!

  3. 3 Darvas Dorottya

    Hello, thanks for the post.
    I’m searching for a way to convert textile formatted files to html offline. I mean on my desktop, for example with vim, or anything else. I’d like to generate html offline, and upload them on my server.
    Do you know probably a way to do this?
    Is it possible maybe with the classTextile.php?

    Thanks

  4. 4 Aaron

    Hi Darvas, thanks for reading.

    I don’t know of a turnkey way to do what you want to do. It’s definitely possible to install PHP on your local machine and run it from the command line to HTML-ize your textile using classTextile.php. You could even create script and mapping definitions within VIM to pipe the buffer through it, but I don’t have any code to show you.

    If you work anything out, let me know!

  5. 5 Aaron

    It has just come to my attention that the Mac OS X editor that I normally use while editing offline on my Mac, TextMate (which I can’t recommend enough), does support converting textile documents into HTML. Just FYI.

  6. 6 Shadowfiend

    Naturally, thanks are due to Dominic as well :-)

    Also, for converting — another way is to install Ruby and then install the RedCloth gem. Then a simple Ruby script can easily convert it using RedCloth. A better alternative is SuperRedCloth (see http://code.whytheluckystiff.net/redcloth/wiki/SuperRedCloth), which is way faster and more correct.

  7. 7 Brennen

    Re: Locally generating HTML from Textile, if you’re comfortable in Perl, another option is to write a very simple wrapper around Brad Choate’s Text::Textile (see http://search.cpan.org/~bchoate/Text-Textile-2.03/).

  8. 8 Tim Harper

    Lack of textile support in VIM is no more!

    Introducting Textile for VIM:

    http://www.vim.org/scripts/script.php?script_id=2305

  9. 9 Rockwell

    A much more proper way to add the syntax coloring is to place the files in your user directory. Vim will find them there, and you don’t need to go mucking around as root.

    That is, place the above two files in the following locations:

    ~/.vim/syntax/textile.vim
    ~/.vim/filetype.vim

    The filetype.vim file here only needs to be the single line given above.

    Thanks for providing this! It’s a great and useful resource.

  1. 1 vimでblogを書く

Leave a Reply