Vim supports embedding syntax highlighting of one language in another. I use that to support both MP and Lua syntax highlighting in ConTeXt regions. The basic trick is do define a syntax region as follows:
unlet b:current_syntax
syn include @LUA syntax/lua.vim
syn region luatex matchgroup=contextIdentifier
\ start='\\startluacode'
\ end='\\stopluacode'
\ contains=@LUA
Then everything inside \startluacode
... \stopluacode
will have Lua syntax highlighting. Here is a screenshot showing code from one of my modules (not that the lua comments and the function os.remove
inside the \startluacode
environment are syntax highlighted)
For completeness, here is a screenshot showing highlighted Metapost code inside a tex file
The same idea will also work in LaTeX, as follows:
unlet b:current_syntax
syn include @LUA syntax/lua.vim
syn region luatexSnip matchgroup=Snip
\ start='\\begin{\z(luacode\|luacode*\)}'
\ end='\\end{\z1}'
\ contains=@LUA
syn region luatexSnip matchgroup=Snip
\ start='\\\(directlua\|luadirect\){'
\ end='}'
\ contains=@LUA
highlight link Snip SpecialComment
Vim also supports auto-completion, but I don't use that feature so I don't know if language dependent auto-completion is possible or not.
Other requirements, like forward/backward search, spell checking, structure browser, are straight forward, but even then, vim is not what you will call an IDE.
emacs can do this sort of thing fairly easily
(defun change-mathvar (a b)
(interactive "sfrom: \nsto: ")
(beginning-of-buffer)
(while (re-search-forward
"\\(\\\\(\\|\\\\\\[\\|[^\\\\]\$\$?\\|\\\\begin{equation}\\|\\\\begin{align}\\)" nil 1)
(query-replace-regexp a b t (point)
(progn (re-search-forward
"\\(\\\\)\\|\\\\\\]\\|[^\\\\]\$\$?\\|\\\\end{equation}\\|\\\\end{align}\\)" nil 1) (point)))))
this looks for $
\(
\[
\begin{equation}
\begin{align}
as math-start. Other environments can be added.
Starting from a document such as
\documentclass{article}
\begin{document}
i i aib
\[i i aib \]
i i aib
\begin{equation}
i i aib
\end{equation}
\end{document}
then executing M-x change-mathvar
the editor will prompt for the old and new names then do a query-replace of the variable names to produce:
\documentclass{article}
\begin{document}
i i aib
\[x x aib \]
i i aib
\begin{equation}
x x aib
\end{equation}
\end{document}
Note it hasn't changed anything out of math and it only changes i
where it appears as a complete word, not aib
. If you want aib
to change as well change the t
in the code to nil
to make a non-delimited match.
Best Answer
I am very happy with vim and the
tabular
plugin. To align the table, place the cursor anywhere inside the (nonaligned) table and type:Tabularize /&
. The result is a nicely aligned table.Before:
Then a
:Tabularize /&
, after:If you need this often, you can assign a custom shortcut for this.