This describes some of the features in the vimrc file. The most useful features are probably the commenting, code highlighting and TeX commands (including how to set a LaTeX master file). These pages are 'advanced', because they go a lot further than the minimal vimrc file described in this post.

## Arrow keys

The first thing you'll probably notice is that the arrow keys do not work (in any mode). Following this guy's advice, the .vimrc file disabled the arrow keys, and now you can only move around in Command mode with the following keys:

 j down k up h left l right

Note that the mappings for j and k have been changed slightly to allow for moving around a long (line-breaked) line.

If you want to re-enable the arrow keys, in the .vimrc file comment out the following lines in the augroup vimcmds block:

nnoremap <up> <nop>
nnoremap <down> <nop>
nnoremap <left> <nop>
nnoremap <right> <nop>
inoremap <up> <nop>
inoremap <down> <nop>
inoremap <left> <nop>
inoremap <right> <nop>
nnoremap j gj
nnoremap k gk


Note that one comments in the .vimrc file using the double quotation mark key: ".

## Copy/pasting shortcuts

In order to copy/paste between Vim windows in OSX, one needs to use the commands:

 :. !pbcopy cut current line in iTerm :r !pbpaste paste the cut text in iTerm

This can be quite annoying, though. The vimrc file adds the following shortcuts using function keys:

  Shortcut for!pbcopy (use in Visual mode)  Shortcut for :r !pbpaste (use in Command mode)

Note that <F2> is more like copy instead of cut (text is not deleted).

## Wombat colour scheme

The .vimrc file assumes the wombat16 colour scheme is installed (as in the previous post). However, this is not necessary, and the following line:

colorscheme wombat16


Can be commented out, or modified to insist on another colourscheme, e.g.:

colorscheme pablo


In order to see which colour schemes are already installed, open a Vim window, and in Command mode type:

:colorscheme


(Do not push <Enter>)

followed by a <Space>, and then tapping the <Tab> key will cycle through all the installed colour schemes. I discovered this tip here.

My original colour theme of choice was solarized, but as explained in the the previous post, I later found it unsuitable. Still, if you install it following the site's instructions (after installing Tim Pope's pathogen), simply uncomment the block below "Solarized commands in the .vimrc file.

## Commenting

There is a block at the end of the .vimrc file (look for the ToggleComment function), containing code originally obtained from here, which allows commenting in R, C++, etc, to be done in Command or Visual mode by typing @@.

 @@ Comment/uncomment

## Recording

Although not part of the .vimrc file, this is worth mentioning since it concerns the @ key.

Note that a single @ key in command mode is used for pasting recorded commands. For example,

• q <letter>: Turn on recording
• Type stuff/do commands
• q: Turn off recording
• @ <letter>: Redo recorded commands

## Code highlighting

Another nice feature in Eclipse is that if you the cursor pauses on a word for two seconds or so, all the instances of that word will be highlighted. Some code implementing this feature in Vim was posted here, and is included in the .vimrc file. So,

 z/ Turn highlighting on/off

Note that if the highlighting is turned on/off, next time a search is made using /, all of the instances of the word will be highlighted. To turn this feature off completely, it seems necessary to close/reopen the file.

## R features

### Syntax groups for R

One of the things I added to the wombat16.vim and .vimrc files are labels for new 'syntax groups'.

For example, rDollar is the syntax group containing only the $ key. If your R code uses a lot of data frames, it may be useful to have $ in a different colour. The following line in the vimrc file makes this association.

autocmd FileType r syn match rDollar /[\$]/


The .vimrc file declares the group, and the wombat16.vim file specifies the colour. For example, the following line in wombat16.vim links the rDollar group to the specially defined DollarBlue colour:

hi link rDollar DollarBlue


and above this declaration, the DollarBlue colour is specified by the following line in wombat16.vim:

hi DollarBlue           guifg=#92a1ea ctermfg=110 gui=none


There are several other groups/examples, which could be used as templates for making your own colour groups for R or other languages. Please see the next post or the Vim documentation for more information.

## TeX commands

As much as I love Vim, when I started to use it for LaTeX, I was really missing some of the great features of Kile. I also didn't enjoy needing to type a command in a separate window in order to compile.

Fortunately, one of my friend (thanks, James) came to the rescue and provided me with a couple of commands which are now in the augroup texcmds block, to allow the following:

  Compile current TeX file with pdflatex  Run bibtex

So, to compile a TeX file with an associated BibTeX file, I just need to press <F6> and <F8> a couple of times (or, see next section below).

There are also a few other shortcuts that have been added in order to create some environments quickly. In Command mode:

 \doc +  lines needed to start document \bib +  lines needed for bibliography \fig +  figure environment \sec +  start a section \frame +  start a frame (Beamer) \eq +  equation environment \eqn +  another equation environment \al +  align environment \aln +  another align environment \item +  itemize environment \enum +  enumerate environment \sep +  a commented horizontal line, to separate blocks

## LaTeX: setting the master file

When working on a large LaTeX project (e.g. a thesis), it helps to split the document up into a main.tex TeX file and then use \input or \include to insert sections/chapters/blocks of Tex into the main file.

The only problem is, if you are busy editing chapter1.tex which is included in main.tex, pressing <F6> would not compile the document (in fact, it would lead to an error). In order to compile the document, you would need to first switch to main.tex before compiling it using <F6>.

One great feature of Kile is that you can set main.tex to be the master file, and then even if you are in chapter1.tex, the compile shortcut will still compile main.tex.

While there is no feature that I know of to set a master file using Vim, there is a trick which works just as well. Borrowing an idea from the vim-latex suite, do the following:

• Save all your project files in a separate folder
• If your main file is called main.tex, create an empty file called main.tex.latexmaster
• In any tex file in this directory, pressing <F7> will compile main.tex

Note that <F7> runs bibtex and pdflatex a couple of times, so that any new citations will (should) instantly appear correctly. The main idea for this trick came from this page.

## Summary of function keys

The following table lists the current function key shortcuts:

  Shortcut for !pbcopy (use in Visual mode)  Shortcut for :r !pbpaste (pasting into Vim)  Compile current Tex file with pdflatex  Compile current folder's master Tex file with pdflatex/bibtex  Run bibtex for current Tex file

## That's it

The above features/shortcuts have made my Vim experience more enjoyable, and hopefully some of the above features may be of use to you. Also, you can use some of the code in the .vimrc file as a starting point from which to create your own commands.