Vim for LaTeX, part 4

With the advent of a new school year (at a new school), I’ve fallen away from the PhilTeX blog and forum much more than I would’ve liked. But I’m back for another, much shorter, install­ment in my ongo­ing series on con­fig­ur­ing Vim for use as a LaTeX editor.

One of my favorite plu­g­ins for Vim is snip­Mate. Snip­Mate is great for LaTeX, but it comes in handy any time I use Vim—be it for tex­tile, mark­down, emails in mutt, and so on.

The basic idea is sim­ple: snip­Mate gives you both default and cus­tom filetype-specific word or phrase com­ple­tions. So when I am writ­ing in a .tex file, if I type sec and then a TAB I get the following:

\section{Section Name} % {{{
\label{sec:Section Name}
% section Section Name }}}

What is more, the first occurence of ‘Sec­tion Name’ is high­lighted. If I start typ­ing it gets replaced with my title. Another <TAB> takes me to the sec­ond occurence of ‘Sec­tion Name’, and a third takes me to the blank space before the end of the sec­tion so I can start writing.

The default snip­pets are great and are really help­ful. But the real power comes in the fact that you can cus­tomize snip­pets really eas­ily. All you do is edit (or cre­ate) a filetype.snippets file for your file­type. An exam­ple will make this more clear.

I like to use the \citet{} and \citep{} com­mands for cita­tions fre­quently. But I don’t want to type that every time. So I put the fol­low­ing in my tex.snippets file

# citations
snippet cpp
    \citep[${1:pp}]{${2:key}}${3}
snippet cp
    \citep{${1}}${2}
snippet ctt
    \citet[${1:pp}]{${2:key}}${3}
snippet ct
    \citet{${1}}${2}

This means that cpp<TAB> will give me \citep[pp]{key}. The cur­sor will be on the ‘pp’, and when I type a page num­ber it will write over that, a <TAB> will move the cur­sor to ‘key’, where I can write in my cite key, and a third <TAB> will move the cur­sor imme­di­ately after the clos­ing bracket.

In gen­eral, if you want to write a com­mand, you fol­low this formula:

snippet shortcut_key
  \command_you_want{${1}}

You can have as many tab stops as you want, so far as I can tell: just put ${1} for the first, and so on. If you want some text to be high­lighted (so you can type over it) when you get to that tab stop, do a ${1:your text}.

You can do basi­cally any­thing you want here (except lead with a pound sign (#), since that is the com­ment leader for .snip­pets files). You could do a sig­na­ture or a para­graph or a long series of com­mands. If you want to set your LaTeX foot­notes off like this:

 end of line.%
%
%
\footnote{my note.}%
%
%

you can. The world is your oyster.

I have redone some com­mands (e.g., to do man­ual sec­tion folds on {{{ }}}), and have writ­ten an hand­ful of addi­tional snip­pets for my .tex files. Feel free to check them out on this page of my github account. If you want to look at all my snip­pets, you can find them one direc­tory up in that account

Note:

To be fair, I think I’m using an out­dated ver­sion of this plu­gin. Nev­er­the­less, it doesn’t work per­fectly for me. Some­times the tab stops get messed up and don’t put my cur­sor in the right place. It isn’t a big deal for me, but be warned that it might happen.

Even with the occa­sional prob­lem, I think snip­Mate makes my writ­ing life much eas­ier. I com­mend it to you, if you use Vim.

6 comments so far, add yours

Vim for LaTeX, part 3

This is part three of my multi-part series on set­ting up Vim as a writ­ing envi­ron­ment for LaTeX. Last week I wrote a cou­ple of posts about my basic Vim setup in my .vimrc. Today I’ll explain the setup and basic usage of my favorite LaTeX plugin.

Con­tinue Read­ing

Links

I came across a cou­ple of links I thought peo­ple might be inter­ested in this week.

Con­tinue Read­ing

Update on Homebrew

The other day I wrote a post about the Mac pack­age man­ager, Home­brew. After using the pro­gram and get­ting to know it a bit bet­ter, I need to make a cor­rec­tion to some­thing I said there.

Con­tinue Read­ing

My .vimrc file

Ear­lier today I wrote a very basic post about cus­tomiz­ing Vim via your .vimrc file. In this post I want to get into more spe­cific details about my .vimrc settings.

Con­tinue Read­ing

Vim for LaTeX, part 2

Last week I wrote a post that offered an intro­duc­tion to the text edi­tor Vim, as well as a brief guide to learn­ing the odd­ity and power of Vim. Today I fol­low up with part two of my series of posts on Vim: cus­tomiz­ing Vim. This is the intro­duc­tory part. If you just want to see my .vimrc, look at part 3 in this series.

Con­tinue Read­ing

LaTeX resources

When you are work­ing with LaTeX, it is almost cer­tain that you will even­tu­ally want to do some­thing that you don’t know how to do. What do you do in this sit­u­a­tion? I want to offer a few quick resources that are avail­able for LaTeX trou­bleshoot­ing. To the right of this post, in the links sec­tion, there are links to a few rel­e­vant LaTeX resources, like LaTeX for philoso­phers and so on, so I won’t men­tion them.

Con­tinue Read­ing

Homebrew, the Mac package manager

I want to throw my hat in the ring with those who have already endorsed Home­brew for the Mac. Home­brew is a fan­tas­tic way to install lots of the pro­grams that you’ll very likely want to use as you get more and more into LaTeX.

Con­tinue Read­ing

Vim for LaTeX, Part 1

Kevin wrote an exe­ce­lent post on text edi­tors for LaTeX recently. He did a nice job cov­er­ing a host of edi­tors there. As I’ve said before, I’m a big fan of Vim. I don’t have any­thing against other text edi­tors, but I think Vim has a lot of advan­tages and is really good for writ­ing LaTeX and other plain text doc­u­ments. But Vim isn’t exactly easy to learn. (As Kevin notes, LaTeX isn’t easy to learn either, so don’t let the learn­ing curve dis­suade you from try­ing Vim out.) Though I can’t make Vim easy to learn, I think I can serve as a bit of a guide, and I can hope­fully offer some advice and sug­ges­tions to make get­ting started with Vim and LaTeX eas­ier. So this will be the first in a series of posts that explains how I use Vim for phi­los­o­phy papers.

Con­tinue Read­ing

More new additions to PhilTeX

I am very excited to announce that PhilTeX is growing!

Con­tinue Read­ing