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.
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:
Note that the mappings for
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:
In order to copy/paste between Vim windows in OSX, one needs to use the commands:
||cut current line in iTerm|
||paste the cut text in iTerm|
This can be quite annoying, though. The vimrc file adds the following shortcuts using function keys:
<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:
Can be commented out, or modified to insist on another colourscheme, e.g.:
In order to see which colour schemes are already installed, open a Vim window, and in Command mode type:
(Do not push
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.
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
Although not part of the .vimrc file, this is worth mentioning since it concerns the
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
Check out this post on stackoverflow for more info.
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,
||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.
Syntax groups for R
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
hi link rDollar DollarBlue
and above this declaration, the
DollarBlue colour is specified by the following line in
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.
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
augroup texcmds block, to allow the following:
||Compile current TeX file with pdflatex|
So, to compile a TeX file with an associated BibTeX file, I just need to press
<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:
||lines needed to start document|
||lines needed for bibliography|
||start a section|
||start a frame (Beamer)|
||another equation environment|
||another align environment|
||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
\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
<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
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
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
- In any tex file in this directory, pressing
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:
||Compile current Tex file with pdflatex|
||Compile current folder's master Tex file with pdflatex/bibtex|
||Run bibtex for current Tex file|
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.