[Tex/LaTex] How to set up spell-checking with vim

spellingvim

I'm using vim to write my thesis. It's a multi-document project, with most tex files in subdirectories from the master-document. I've set up a couple of \newcommands to replace the use of \section*{} in the Introduction, but when writing the sections, misspelt words aren't highlighted.

I thought it was a problem with vim-latexsuite, so I've just uninstalled it, but still, spell-checking functionality doesn't work in these sections.

For example, a MWE with the following files:-

thesis.tex
thesis.tex.latexmain
Classes/Thesis.cls
Intro/intro.tex

thesis.tex :

\documentclass[twoside,openany,titlepage,12pt]{Classes/Thesis}

\pagenumbering{roman}
\begin{document}

\include{Intro/intro}

% ...

\end{document}

Classes/Thesis.cls :

\ProvidesClass{Classes/Thesis}[2014/07/14 v1.2 Thesis template]

\LoadClass[pdftex, a4paper]{report}

\usepackage[pdftex,
            plainpages = false,
            pdfpagelabels,
            bookmarks,
            bookmarksopen = true,
            bookmarksnumbered = true,
            breaklinks = true,
            linktocpage,
            pagebackref,
            colorlinks = true,
            % Colour settings from::
            % http://tex.stackexchange.com/questions/30243
            linkcolor=NavyBlue,
            citecolor=BrickRed,
            filecolor=black,
            urlcolor=BrickRed,
            hyperindex = true,
            hyperfigures
            ]{hyperref}

\usepackage{tocbibind}
\usepackage{bookmark}
\usepackage[english]{babel}
\usepackage{times}
\usepackage[a4paper]{geometry}
\usepackage{pdfpages}


\newcommand\chapwtoc[1]{%
  \phantomsection
  \chapter*{#1}
  \addcontentsline{toc}{chapter}{#1}
  \markboth{#1}{}
}

\newcommand\secwtoc[1]{%
  \phantomsection
  \section*{#1}%
  \markright{#1} % Get the Section name in headnotes
  \addcontentsline{toc}{section}{#1}
}

Intro/intro.tex :

\chapwtoc{First chapter}

this is a msisisspelt word. Some mnore mis-spellings.


\secwtoc{First section}

some more misskjkpellings.

% vim: spell spelllang=en_gb

thesis.tex.latexmain is an empty file, as suggested in the latexsuite documentation for Multiple file LaTeX projects

How do I get spell-checking to work in the intro.tex sections? Using vim 7.4 on Linux

Best Answer

You can force spell checking for tex documents by putting the following into .vim/after/ftplugin/tex.vim or .vim/after/ftplugin/tex/spelling.vim:

set spelllang=en_gb spell

Your approach to do it with modeline magic

% vim: spell spelllang=en_gb

should work too, but you need to explicitly enable modelines. (They can be a security issue.) To do so, put the following into your .vimrc:

set modeline