Writing LaTeX files with GVim

In this post I will show some useful links, some tips and shortcuts I have set in my settings for Vim.

  1. First, here are screenshots and videos you might find useful if you are a beginner :
    • If you don’t know how GVim looks like, here is the screenshot taken from a video at youtube.com :

      And here is how GVim looks like with my own settings :

    • Here is a screencast which explains the basics of vim that you can find with youtube or google videos :

      An other screencast with some explanations about basic but useful plugins available for Vim, which will save your time when you edit files (such as LaTeX files) :

      Once you get the basic idea of what GVim is, here are some lessons :

  2. Secondly, here are some explanations about plugins I use in GVim :
    • MRU is a vim script which enable you to use the Most Recently Used files. If you use the settings I have put in my repository at Github, then press F8, and you will get files you closed recently :

    • When I don’t have used a file recently and want to open one, I press F4 and I get the Vim Explorer

      If you want to enter in a directory, move the cursor to this directory and press enter. If you want to move back, press Backspace. To open a file, place the cursor on this file and press enter.
      You will also notice that all files are sorted according to the extension, a nice feature of the plugin.

    • NerdTree is an other way to search files. When another file is already opened, NerdTree will be opened automatically in a small part of the window, on the left :

      To open it, press Shift+F4. To switch from the buffer opened on the left to the main buffer, you will have to use the mouse, or to type twice ctrl+w, a keystroke which will move automatically the cursor to the main part of the window.

      You can also look at this screencast showing you more about the NerdTree plugin :

    • If you are editing a LaTeX file (it works with other sort of files), select the block you wish to comment, and then type “,ci”. It will comment it, thanks to the plugin NerdCommenter. To uncomment it, do the same thing. Here are screenshots showing you a selected block and then the same block commented after typing ,ci : 

    • Thanks to the AutoComplPop plugin, when you type a word, a popup will automatically be displayed, and will show you all words available in your dictionaries’ directory specified in the settings I have made (~/.vim/ftplugin/tex.vim) : 

    • Let us assume you wish to enter a section in your LaTeX file. With the plugin SnipMate, you will only have to type sec and press tab, and you will have everything expanded. Then when you will enter the title, it will automatically write the same for the label, and once you will have pressed tab again, the cursor will automatically jump to the place where you will have to begin your section. In this screenshot I enter sec :

      Here is what I get when I press tab :

      And while I am typing the title, it automatically type the label :


      And then, pressing tab will make the cursor jump to the right place between the delimited space defined with the snippet (for Ubuntu users not aware of what a snippet is, basically let us say it is similar to a template).

      Also, many other snippets are already defined, and I have defined others snippets by myself. If you want to get a try or to look at it, see the corresponding file in my repository at Github.

      If you don’t get the idea of Snipmate, then look at this video :

    • Let us assume you have multiple files (which we call in this case “buffer“) opened in the same window, and you wish to select one. With the plugin SelectBuffer, you will just have to press F10 and it will open a small area where you will can select the one you want. Once you get it, press F10 again and it will automatically close itself : 

      If you don’t understand what a buffer is, since it is important to understand the use of this plugin, look at this screencast :

    • Let us assume the cursor is positioned on a bracket. Press % in normal mode, and your cursor will automatically jump to the other one, thanks to the matchit plugin. It might be useful for footnotes or other things in *.tex files. 

      The following screencast show an example at 8 min 01 s :

      Let us assume you wish to get 2 files in the same screen. In normal mode, type ;bv and press enter, and the screen will split vertically thanks to the buffer explorer plugin :

      You can try yourself other commands like ;be and ;bs if you are interested.

    • Other plugins are also in my .vim directory. FuzzyFinder for example. If you type :FuzzyFile, you will get the following : 

      For more details, look at the documentation of the plugin or see this screencast.

    • If you type :Calendar and press enter in normal mode, a calendar will be displayed thanks to the calendar plugin

    • Other plugins may be interesting for you, such as the multiple search plugin, the align plugin and the time stamp plugin. But for these plugins, I will let you look by yourself the documentation.
      If you don’t know how to look to the relevant documentation corresponding to the plugin, then do as follow. In normal mode, type :h Align and press enter, and you will get a new buffer displayed for the Align documentation : 

  3. Though it is not plugins, here are some other tips you need to know if you wish to use my settings : 
    • If you want to save a file, press F2.
    • If you want to open a terminal, press shift+F2
    • If you want to open nautilus, press Alt+F2. Notice that if you want to open another file manager, you will have to change it in THE settings. For this, look in the .vimrc file.
    • If you want to close a buffer, that is to say a file, then press F3. If you want to close all buffers currently opened in a window, press shift+F3. And if you don’t want to save and want to exit, press Alt+F3.
    • If you want to compile a *.tex file, press F11. It will also automatically start the viewer after finishing to compile. If you just want to compile, and don’t want to see the result, press Alt+F11. Notice that the default compiler is XeLaTeX, and not pdfLaTeX. If you want to change the compiler, you will have to change my settings, and to do so you will have to modify the tex.vim located in ~/.vim/ftplugin. And if you don’t understand how to modify it after looking at the tex.vim file, let a comment (though you should get a try to XeLaTeX).
    • If you want to enable spell checking for french, press F12. If you want to disable it, press F12 again. If you want to enable spell checking for english, press Alt+F12. If you use most of the time english files, you might change the default mapping in .vimrc to replace the mapping for french by the mapping for english.
    • When you want to copy a selected line, word, etc, press Ctrl+Insert. To cut a selected line, word or other, press Insert+Suppr. And to paste it, press Shift+Insert. If you are not familiar to these shortcuts, then learn to like it instead of changing it, because these shortcuts are also used in other programs.
    • To search a word, type “/” in normal mode, and then enter your word. If several words exist, press enter and then type “n”, which means “next”. The cursor will jump to the next word each time you will press “n”. Once your searches are finished, enter Ctrl+n to cancel highlighting.
    • To open a new tab, press Ctrl+t in normal mode. To move to the next tab, press Ctrl+”left arrow” or Ctrl+”right arrow” depending on what tab you want to select.
    • To format a paragraph, press Shift+q in normal mode. But be aware that you should avoid it with my settings, which won’t let you get a correct formatting with LaTeX files.
    • To emphasize a word, select it and press “,em” in normal mode. See other shortcuts in the latex-suite documentation. But notice that I have changed the default mapping. Instead of pressing ` and the abbreviation, you will have to press “,” and the abbreviation (the reason of this mapping is that a comma is easier to type than a “`” with a french keyboard). Here are some examples of shortcut :



      Shortcuts LaTeX commands
      ,md \textmd{}
      ,tt \texttt{}
      ,sf \textsf{}
      ,up \textup{}
      ,bf \textbf{}
      ,sl \textsl{}
      ,sc \textsc{}
      ,it \textit{}
      ,em \emph{}
      ,a \alpha
      ,b \beta
      ,A \Alpha
      ,B \Beta
      And so on
      etc, etc
      I won’t show you
      all shortcut
      for more details,
      see the latex-suite
      documentation

      In any case this setting is for french keyboards, if you use another keyboard, change this in tex.vim if you want.
    • If you want to search a word in google with firefox, then select the word, and press “f” in visual mode. If you want to search in Wikipedia instead of google, press “w” instead of “f” in visual mode.
  4. Here is another tip with Vim, really useful. Let us assume you wish to enter a word or several words which are painful to typeset with your keyboard, and let us also assume that you often use this or these words. Then using abbreviations is a nice idea. My abbreviations are set in the tex.vim, see the line 33. Basically, an abbreviation is something you type and which will expand automatically to the word or the words you have set previously after you press the space key. So for example, since I have :

    iab bcp beaucoup
    iab qqn quelqu’un
    iab qqc quelque chose

    When I will write bcp, it will transform automatically in beaucoup when I will press the space bar.

    Look here or here for further explanations.

  5. With Vim, another thing really useful is imap (or nmap for normal mode, and vmap for visual map). Imaps are mappings set to work in insert mode. So for example, let us assume you wish to insert a bracket, say “(“. Since I have defined “imap ( ()” in my tex.vim, pressing ( will automatically load the other bracket. So writing ( will write automatically (). When you write “,ja”, it will automatically write {\ja }. Same thing for “…”, it will be replaced automatically by “\ldots”. For further details, see the vim documentation (in normal mode, type “:h imap”).
  6. Don’t forget that Vim is not as bad as Microsoft Word, OpenOffice.org Writer and other similar text processors are. Let us take an example. If you have the following :
    a b c
    d e f
    i j k
    Could you insert a & between each letter in each lines easily ? No. But with Vim it is easy. With Word or other similar softwares, could you easily replace each letter or each word of the beginning of a line ? No. But with vim it is easy to do so. Therefore, if you are a beginner, don’t forget to search with google if something you need to do is painful, maybe there is an easy way with Vim to automatize your task and to achieve your goal.

Finally, here are some links which you could find useful :

Vim tips if you don’t want to use my settings, or are just curious
A course, “Vi : introduction”
A book about Vim available for free
The LaTeX suite documentation in html or in txt format (available in Vim)
A nice ref card of Vim in several formats (download the pdf file) and another one in html, maybe more clear
French speakers should also take a look here
In case you wish to ask a question, Google group is a good place.
Another Vim tutorial
If you are japanese, you could find this blog useful.
If you are french and want to use the bépo keyboard

Advertisements
  1. October 12th, 2010
    Trackback from : watch movies online
  2. November 13th, 2010
    Trackback from : Buy Facebook Fans
  3. April 23rd, 2011

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: