Vim has built in spell checking. You do not need external spell checkers. Simply use :set spell
to enable spell checking.
To disable spell checking in code listings, you need to modify the vim syntax file for tex.
Copy $VIMRUNTIME/syntax/tex.vim
to $HOME/.vim/syntax/tex.vim
. Around line 402, this file has:
syn region texZone start="\\begin{verbatim}" end="\\end{verbatim}\|%stopzone\>" contains=@Spell
syn region texZone start="\\begin{code}" end="\\end{code}\|%stopzone\>" contains=@Spell
" listings package:
syn region texZone start="\\begin{lstlisting}" end="\\end{lstlisting}\|%stopzone\>" contains=@Spell
" moreverb package:
syn region texZone start="\\begin{verbatimtab}" end="\\end{verbatimtab}\|%stopzone\>" contains=@Spell
syn region texZone start="\\begin{verbatimwrite}" end="\\end{verbatimwrite}\|%stopzone\>" contains=@Spell
syn region texZone start="\\begin{boxedverbatim}" end="\\end{boxedverbatim}\|%stopzone\>" contains=@Spell
Change each of these @Spell
to @NoSpell
and vim will not spell check in the respective environments.
Disclaimer: I usually edit .tex
files in Vim, but I don't use the Vim-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:
Created by Michael Sanders
From the manual: snipMate.vim
aims to be an unobtrusive, concise vim
script that implements some of TextMate's snippets features in Vim. A snippet is a piece of often-typed text that you can insert into your document using a trigger word followed by a <tab>
.
snipMate
helps me a lot, mainly because it offers snippets for several languages out of the box, including TeX. For example, when editing a file mydoc.tex
, typing
begin<tab>
will expand to an environment block of the form
\begin{env}
\end{env}
with the cursor selecting the word env
. After typing the environment name, hitting <tab>
again will take the cursor to
\begin{env}
|
\end{env}
for 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:
# \begin{}...\end{}
snippet begin
\begin{${1:env}}
${2}
\end{$1}
So far, so good.
Created by Matt Wozniski
From the manual: Sometimes, it's useful to line up text. Naturally, it's nicer to have the computer do this for you, since aligning things by hand quickly becomes unpleasant. While there are other plugins for aligning text, the ones I've tried are either impossibly difficult to understand and use, or too simplistic to handle complicated tasks. This plugin aims to make the easy things easy and the hard things possible, without providing an unnecessarily obtuse interface. It's still a work in progress, and criticisms are welcome.
Tabular
helps me a lot when I'm trying to add elements in a tabular
environment. It organizes the columns in a human-readable format. Let's suppose we have the following mess entries:
\begin{tabular}{lll}
Hello world & I love ducks & Vim rocks\\
Think of a very long entry & How was your day & Quack!
\end{tabular}
It's quite confusing, but Tabular
can help us. I usually enter in Visual
mode, select the two rows and then issue
:'<,'>Tabularize /&
and we are done. The new rows now look like
\begin{tabular}{lll}
Hello world & I love ducks & Vim rocks\\
Think of a very long entry & How was your day & Quack!
\end{tabular}
I can also apply :Tabularize /&
, but I prefer to delimit my scope. A similar plugin Align
can also be used for this purpose, see my answer to Which text editor to make tables scripts human readable.
Created by Tim Pope
From the manual: Surround.vim
is all about "surroundings": parentheses, brackets, quotes, XML tags, and more. The plugin provides mappings to easily delete, change and add such surroundings in pairs.
I usually use this plugin when editing source code from other languages. Let's suppose I have the following text enclosed between double quotes:
"Hello world"
By calling cs"'
, the double quotes are automatically replaced by single quotes. I decided to make a different use of surround
, 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
:
autocmd FileType tex let b:surround_45 = "``\r''"
Note that 45
is the ASCII code of -
. Now I can simply call cs"-
and my text
"Hello world"
becomes
``Hello world''
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.
From the manual: Manage your runtimepath
with ease. In practical terms, pathogen.vim
makes it super easy to install plugins and runtime files in their own private directories.
Hope it helps. :)
Best Answer
You can do it manually by using
syn match
. For example, your problem with\somevariable
can be solved withThis will disable spellcheking in between
{
and}
after\somevariable
. (It assumes that you do not use}
inside the argument.)Depending on how complicated the part of your document in which you do not want the spell checker on, it might get quite complicated to do something similar. Your example with Tikz seems to be dificult, but the solution above should work with
somevariable
changed to anything else.EDIT: If you would like to have
{
and}
highlighted as well, as per default, then you should includetexDelimiter
incontains
, so that it becomescontains=@NoSpell,texDelimiter
instead ofcontains=@NoSpell
EDIT: There can be problems if
\somevariable
matches something special, like\cite
. Since\cite
is highlighted withtexRefZone
, this should be added tocontainedin
, so the command should be: