Vim LaTex

I noticed that in the past I produced several posts about combining LaTex and Emacs. While I do like Emacs and respect it’s formidable power I do not consider myself an Emacs user. Most of my day-to-day work is done in Vim which brings different kind of editing power to the table. Emacs is a lisp based framework for building text editing applications - fully programmable, easily customizable and almost endlessly extensible. The power of Emacs comes from what it can do. Vim’s power stems from what it does - and that is providing very powerful and yet simple modal text editing environment. I wanted to say intuitive, but yeah - that would be a lie. Vim is powerful because it allows you to accomplish just about anything in 3-4 keystrokes by chaining and combining simple commands.

Using Vim makes editing text much simpler and easier. It removes a lot of key-presses and movements. Let me give you an example - in a typical coding session you may want to copy the current line, and paste it below. Assuming your cursor is in the middle of the line how would you go about accomplishing it? Typically you would do:

  1. Hit Home to skip to the beginning of the line
  2. Hold shift and hit End to highlight the line
  3. Press Ctrl+C to copy the line
  4. Hit End again to put the cursor at the end of the line
  5. Hit Enter to insert a new line
  6. Press Ctrl+V to paste the line

How do you do it in Vim?

  1. Press the following keys in a sequence: yyp

That’s it. You want to paste the line 3 times? Do yy3p. This is the power you get when you use Vim. Of course die-hard emacs fanboys will remind me that one could always use Emacs’ VIP mode which emulates vi’s modal editing features. And they would be absolutely right. As I said, Emacs is a framework for building editors rather than an editor. So when you launch it in VIP mode you are really using Vi with the lisp powerhouse underneath it.

In theory you could combine the neat features of AUCTex on Emacs and the power the VIP mode gives you to get the best of both worlds. But if you don’t need these features - if you are a Vim purist or if you just need a simple modal text editor I have a nice alternative for you. It’s called VimLaTex.

vim-latex.gif

While it does not have the nice rendering features of AUCTex, VimLaTex is a must-have if you are planning to use Vim to edit LaTex files. The package itself is tiny - you just drop few hundred KB into your .vim directory and add few lines to your .vimrc.

The suite will add bunch of useful menus to your toolbar:

croppercapture100.jpg

These menus are your standard IDE like features - for example options for inserting packages, or snippets of code for special environments and etc.. A lot of the entries come with predefined key-bindings which make your life much easier. For example:

  1. To compile your file do: \ll
  2. To view compiled file do: \lv

You can set the preferred format for both options above by invoking :TTarget. It works like a charm both on Windows and Linux when I tried it.

VimLaTex also uses an interesting concept of placeholders. Whenever you use it to generate snippet of code, it will put funny looking character sequences inside of it. They may look silly until you realize how useful they are. For example let’s say you want to insert a figure:

\begin{figure}[h]
    \centerline{\psfig{figure=«eps file»}}
    \caption{«caption text»}
    \label{fig:«label»}
\end{figure}«»

The placeholders are there to make your life easier. When you press Ctrl+J vim will jump to the first «» delimited sequence and select it. This way you can just type over it. Press Ctrl+J again (while still in insert mode) and you will jump to the next one. How awesome is that?

If you are a Vim lover who also happens to use LaTex or a LaTex user who loves Vim definitely check this one out.

Related Posts:

  • Vi or Emacs? Which one do you use?
  • Emacs with AUCTex as a LaTex IDE
  • LaTex Annoyances
  • Installing LaTex on Windows
  • Upgrading to Vim 7 on Dapper
  • LaTex: Fixing Wrong Figure Numbers
  • Latex: Rotate Inserted Images
  • Latex: Numbered Subsubsections
  • Code Segments in Latex
  • Convert JPG and PNG to EPS on Windows

  • 5 Responses to “Vim LaTex”

    1. Gravatar Paul Says: Reply to this comment

      “The power of Emacs comes from what it can do. Vim’s power stems from what it does.”

      I think I just achieved enlightenment. What a great piece of insight.

      Posted using Mozilla Firefox Mozilla Firefox 3.1b1 on Linux Linux
    2. Gravatar Matt` Says: Reply to this comment

      So wait… what do you do if you just want to type “yyp”?

      Honest question - I’ve never had cause to use any text editor more complex than Notepad (I know, not really a text editor in the same sense, but you know what I mean)

      Posted using Mozilla Firefox Mozilla Firefox 3.0.3 on Windows Windows XP
    3. Gravatar Mirko Says: Reply to this comment

      btw, duplicating a line is a single keypress (ctrl+d) in notepad++ or visual studio with c++ keybindings.

      Posted using Mozilla Firefox Mozilla Firefox 3.0.3 on Ubuntu Linux Ubuntu Linux
    4. Gravatar Luke Maciak UNITED STATES Says: Reply to this comment

      @Paul: D

      @Matt`: Oh, you first enter the edit mode by typing i. Once you are in edit mode you can type normally. Once you type something you hit Esc to go back to command mode where you can use single keystrokes to perform various functions.

      @Mirko: Neat. I didn’t know that. A lot of IDE’s use Ctrl+D to mean “comment-out the highlighted block” though so this is going to be confusing. P

      Still, in Vim I can apply similar philosophy for selecting and copying whole paragraphs or functions. For example y}p will duplicate the whole paragraph. y2}p will duplicate the next paragraph and etc…

      Posted using Mozilla Firefox Mozilla Firefox 3.0.3 on Ubuntu Linux Ubuntu Linux
    5. Gravatar astine UNITED STATES Says: Reply to this comment

      Luke, I don’y believe that VIP mode has been current since the 90’s ) . Currently what is in use is viper, which is more complete and more configurable, (it makes it easier to access Emac’s standard feature set while in Vi mode) In addition, there is a nice patch: Vimpulse, which does a nice job imitating Vim, not just Vi the difference is tangible any serious Vim user (such as myself.)

      Also, I probably wouldn’t use y}p to duplicate a paragraph, as it won’t work if you start with the cursor in the middle. You’d do better to say {y}p, or maybe {v}k$yP if you want to preserve the last blank line. Of course, this starts to get complicated, so you might want to use nmap to map it or something:

      :nmap ^z^a {v}k$yP
      Posted using Safari Safari on Mac OS Mac OS X

    Leave a Reply

    XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <pre lang=""> <em> <i> <strike> <strong>

    [Quote selected]