I just saw a similar question about Emacs/AUCTeX so this one was coming. I use nvi for all my editing including TeX and it would not change it for anything. However, even after almost 20 years of use I never stop to be amazed by clever trick people show me of and on.
This is my favorite list of nvi tricks (to be edited and improved over next couple of days):
1) Do not forget to use key mappings! Don't forget also that the whole power of Unix is on your fingertips as there is nothing easier than to invoke shell commands in nvi. Combination of this two ideas is very potent.
a) Even though nvi has no built in spell checker it doesn't mean that we can't do a spell checking. Actually it is even easier than in most "user friendly editors". This is the most useful line in my .exrc for TeX editing.
map v :w^M:!ispell %^M:e!^M^M
The spell checking is done by pressing ESC+v. Note that people who prefer aspell over ispell can put something like
map v :w^M:!aspell check %^M:e!^M^M
b) Another useful keyboard mapping specifically for TeX users.
map ^X :w^M:!make pdf clean %^M^M
What is does it enables you to tex your most recent edit by pressing Ctrl+X which pending on your pdf-viewer is automatically updated. Almost WYSIWYG for nvi users. Ok for people who want to add this into their .exrc files note that tex-ing is actually done with make utility. So I do have my own home cooked Makefile in my working directory. Targets pdf and clean are described in the Makefile.
2) nvi comes with pretty sensible sets of default values. However a carefully crafted .exrc can dramatically increase productivity of editing. This is my complete .exrc.
set autoindent
set autoprint
set cedit=^[
set extended
set file=^[
set number
set ruler
set shiftwidth=4
set showmatch
set showmode
set tabstop=8
set verbose
set wrapmargin=8
map V !}fmt -w 72 ^M
map v :w^M:!ispell %^M:e!^M^M
map ^X :w^M:!make pdf clean-ps %^M^M
Probably two of the most underappreciated options which were not present in the original vi editor are extended
option which allows you to use extended regular expressions (think egrep
) and cedit=^[
(^[
which is ESC in the verbose mode) allows you to use command history in ex mode.
There are two other options which I do not have in my .exrc file but I find it very useful. By default nvi search is case sensitive. We can override this behavior by setting option ignorecase
(ic
). Since I tend to use extended regular expressions this is not essential feature for me. Second non default option which is very useful is incremental search. Just set searchincr
and you will see what nvi matches words as you type in each letter of your search string.
3) Using abbreviations coming soon.
4) Buffers, markers and similar coming soon
5) Batch editing for beginners coming soon.
Edit:
This edit is inspired by Stefan Kottwitz comment. My favorite thread on vi/vim from stackexchange is "What is your most productive shortcut with VIM?". I almost fall of the chair after reading the first answer "Your problem with Vim is that you don't grok vi".
Best Answer
Disclaimer: I usually edit
.tex
files in Vim, but I don't use theVim-LaTeX
suite.I wouldn't say the following suggestions are tricks per se - they are provided by third-party plugins - but they actually help me with my usual TeX workflow:
snipMate
Created by Michael Sanders
snipMate
helps me a lot, mainly because it offers snippets for several languages out of the box, including TeX. For example, when editing a filemydoc.tex
, typingwill expand to an environment block of the form
with the cursor selecting the word
env
. After typing the environment name, hitting<tab>
again will take the cursor tofor me to type. The snippets list for TeX is not that big, but the plugin seems to have a fairly easy syntax for us to create custom snippets. Here's the code used to create the above snippet:
So far, so good.
Tabular
Created by Matt Wozniski
Tabular
helps me a lot when I'm trying to add elements in atabular
environment. It organizes the columns in a human-readable format. Let's suppose we have the followingmessentries:It's quite confusing, but
Tabular
can help us. I usually enter inVisual
mode, select the two rows and then issueand we are done. The new rows now look like
I can also apply
:Tabularize /&
, but I prefer to delimit my scope. A similar pluginAlign
can also be used for this purpose, see my answer to Which text editor to make tables scripts human readable.surround
Created by Tim Pope
I usually use this plugin when editing source code from other languages. Let's suppose I have the following text enclosed between double quotes:
By calling
cs"'
, the double quotes are automatically replaced by single quotes. I decided to make a different use ofsurround
, so I took an example from the documentation and adapted to my TeX needs. First of all, I have the following line in my.vimrc
:Note that
45
is the ASCII code of-
. Now I can simply callcs"-
and my textbecomes
The documentation has a few examples on TeX snippets.
For those who want to try the plugins I listed above, I highly recommend the use of the awesome
pathogen
plugin created by Tim Pope.Hope it helps.
:)