I use gvim to edit LaTex .tex file. I noticed that it checks spelling on the fly only for the commented text. If I have a mistake in a regular text - no underline. If I comment this text with % , the misspell is underlined immediately. What is wrong? Is there any strange option turned on?
The latex ft plugin conveniently defines this behaviour.
SpellChecker : Spell check text including LaTeX documents
Using latexmk, vim spell checking and vim latex-suite
There is an option that appears to come close:
:syntax spell [toplevel | notoplevel | default]
Update
Also
:he ft-tex-syntax
has very useful tidbits, like
Don't Want Spell Checking In Comments? ~
Some folks like to include things like source code in comments and so would
prefer that spell checking be disabled in comments in LaTeX files. To do
this, put the following in your <.vimrc>: >
let g:tex_comment_nospell= 1
You'll have to figure out whether you can use that/extrapolate from there
I had the same problem (VIM 7.3), but this post at the vim-latex-devel mailing list provided the clue. To get the spell checking working, I had to put
syntax spell toplevel
in my ~/.vimrc, but it has to be declared after
syntax enable
or
syntax on
for it to work.
I don't whether this is a crude hack and the intended solution, but I created a file called .vim/after/syntax/tex.vim
containing the single line:
syn match texText "\<\w\+\>" contains=#Spell
Now vim spell checks the normal text between the commands and the text passed as parameters, because you cannot differentiate them syntacticly:
\frametitle{TextToBeChecked}
\pgfuseimage{VariableNotToBeChecked}
Hence, it checks way too much in my preamble. But I have it located in another file, so I don't really care.
This problem often occurs when working with files which are included by a master document.
If you are opening a TeX file which will be included and does not contain a section, chapter, \begin{document}, ... you can mark it by adding %begin-include at the top of the file. This way vim recognizes the file content as being part of the texDocZone region, which enables spellchecking.
With %end-include you can set the end of the texDocZone.
This behavior seems not to be documented, but is described in the vim syntax file: https://github.com/vim/vim/blob/master/runtime/syntax/tex.vim
tl;dr: Add %begin-include to the top of your tex file.
I encountered the same problem -- the .tex file for the first chapter of my book spell checked normally, but the file for the second chapter would only spell check the comments. This apparently happens because vim isn't looking at enough lines of context and gets confused. Ingo Karkat's solution here fixed it for me. Specifically, I used:
syn sync maxlines=2000
syn sync minlines=500
in ~/.vim/after/syntax/tex.vim
tldr; don't put \section commands in your master .tex document
I made the same observation and I also would insist on "before, it worked and I didn't change anything".
Then I observed that this unwanted behaviour only occurred in .tex documents where I have a master.tex that includes chapters as separate chapterx.tex files. Moreover, everything works fine if all the \section definitions are in the chapterx.tex's and NOT in the master.tex.
Otherwise, as I think, the vim syntax and spell checking routines have a hard time determining in which region they are, cf. this question Vim spellcheck not always working in .tex file. Check region in Vim
I found the same problem, but a different solution to it. In some .tex files the spell-check was working as expected others not (documentclass{scrlttr2}). Only in the comments words were underlined ... So I compared the headers of one working and one not working .tex document. I found a surprisingly texblock, which were hindering the spell check in the document itself:
\usepackage{array}
\newenvironment{Conditio}
{\par\vspace{\abovedisplayskip}\noindent\begin{tabular}{>{$}l<{$} #{${}={}$} l}}
{\end{tabular}\par\vspace{\belowdisplayskip}}
And this code was only an "hangover" of a different juridical text, I edited before. Commenting it out, set the normal spell-check with high-lighted texts in the letter document. (MacVim 8.1 latex-suite macOS 10.13.6 vim-latex v1.10.0)
None of the answers here worked for me, but I could see if I typed syntax spell as a command in vim it would work.
It turns out it was because syntax wasn't being set for the tex filetype automatically, and I found the solution here.
vim only spell checking in TeX comments
Editing a LaTeX document with vim, I noticed it was only spell-checking comments. I fixed this
by add this to my ./vimrc:
autocmd FileType plaintex,tex,latex syntax spell toplevel
Related
I recently use the vim to write the latex source. But I got a very strange problem. When I open a old .tex file with vim, the equation will not show as usual. For example, when I type $K$, it just display K unless I move cursor to the line of the equation. And this does not happen when I open a new .tex file. Can anyone help? Thank.
I think you see the effects of the conceal feature; the Tex syntax plugin uses that do shorten certain sequences for display. See :help tex-conceal for the full explanation of that feature.
If this annoys you, just disable concealing, e.g. via
:set conceallevel=0
I've just recently started to use the folding functionality of vim and it's very helpful for the languages that it works really well for.
My issue lies in the way vim comments out the fold markers in scilab code. It defaults to
/*{{{*/ and /*}}}*/
which works great in languages like C, but is not actually a comment in scilab. I get a multiplication error when i try to run the code.
I've tried adding
autocmd FileType scilab set fmr=//{{{,//}}}
to my .vimrc file which doesn't quite do what I'd like. It results in
/*//{{{*/ and /*//}}}*/
which are still not comments. The code "folds" fine but becomes unusable. I could set up a macro to replace every instance of "/*" with "//", but that could have unintended consequences when applied globally to a file.
So the question is: how can i setup vim fold markers comments for scilab files such that it will not render the file unusable?
You do not add the comments to 'foldmarker' itself, there's the 'commentstring' option that influences how Vim surrounds the fold markers (when creating folds with zf). Try setting
:setlocal commentstring=//%s
for your scilab filetype. (Put the command in ~/.vim/after/ftplugin/scilab.vim to make it permanent.)
It sounds to me like vim doesn't understand how SciLab comments work. I'm not sure if vim comes with SciLab syntax logic these days, is syntax highlighted correctly in your SciLab files? If not, you can get the syntax file from here.
Is there a particular reason you want to use marks? They aren't actually needed. If you don't want vim to auto-fold by syntax or indentation level, you can still manually define folds with
:set foldmethod=manual
That lets you select a chunk of text in visual mode and make it into a fold with 'zf'. No marks required.
More info on various vim folding techniques here.
I have a HTML file which contains both HTML and JavaScript. When I folded some code snippets, the syntax highlight didn't work well. Screenshot as following:
Line79 function setColor(color) is not correctly highlighted. Is there any way to fix it?
BTW, I am using GVIM 7.2 in windows 7.
Thanks!
When Vim opens an html file it applies html highlighting throughout the file. When you have a separate language in the html file you need to define syntax regions to let Vim know that parts of the file are to be highlighted differently from the language identified by the file extension. I described how to do this in an answer to an SO question here: In VIM, how can I mix syntax/ident rules of both jinja and javascript in the same file?
Also review the docs at :h syn-include.
Indenting is similar. That is, Vim will apply html indenting rules to everything within the file unless you tell it to indent the Javascript region differently.
NOTE: Maybe since html with embedded javascript is so common the html syntax files may by default support embedded javascript. The tip linked below suggests using :set filetype htmlm4 to get proper highlighting, although a commenter says that should not be necessary:
http://vim.wikia.com/wiki/Syntax_highlighting_for_HTML_with_embedded_Javascript
:syn sync fromstart
(See also help syn-sync-first)
It may be that you have a line in the mapInit() function whose length exceeds vim's 'synmaxcol' setting Notice the highlighting is incorrect on line 77 too (the closing brace).
set synmaxcol
From vim's help:
Maximum column in which to search for
syntax items. In long lines the text
after this column is not highlighted
and following lines may not be
highlighted correctly, because the
syntax state is cleared. This helps to
avoid very slow redrawing for an XML
file that is one long line.
I used Vim LaTeX for six months with natbib and had no problems. But to use a new bib style file (i.e., rfs.bst) I started using harvard.sty, which gives me two minor problems:
(1) syntax highlighting is not complete; specifically for \citeasnoun, Vim only highlights the \cite portion. With another Vim plugin (Vim-plugin-R) I can update the syntax highlighting, but I can't figure out how to do this in Vim. I refreshed the databases in MikTex, but that didn't work.
(2) Vim LaTeX is automatically rerunning as necessary to get references correct -- the status window in Vim shows it going through several runs and the results are as desired -- but I still get this warning:
|| LaTeX Warning: Label(s) may have changed. Rerun to get cross-references right.
How can I fix these? Thanks!
As for the syntax highlighting issue, you could try the following.
In your personal vim settings folder -- typically $HOME/.vim/ on Unix-based systems, or C:\Users\<yourname>\vimfiles (?) on Windows (probably the first entry shown in :set rtp?), create a directory (if there isn't one already) called after, and create a subdirectory of it called syntax, and in it create a file called tex.vim. So the file will be $HOME/.vim/after/syntax/tex.vim for Unix or C:\Users\<yourname>\vimfiles\after\syntax\tex.vim on Windows. (I hope a Windows user will confirm this, since I'm on Linux.)
In that file, put the following line:
syn match texRefZone '\\citeasnoun\%([tp]\*\=\)\=' nextgroup=texRefOption,texCite
Then when you open a LaTeX file, \citeasnoun should be treated just like \cite as for Syntax Highlighting (...that's assuming you're using the default Syntax Highlighting rules for LaTeX files that came with vim 7.3 anyway....)
I think your other question is answered in the comments.
How can I use Latex effectively in VIM?
Is there a way to configure compile errors by highlighting the line in vim?
I have syntax highlight. What are other recommended add-ons? Is a makefile the recommended way to compile a latex file to pdf?
TexWorks lets you open and replace the opened pdf everytime it's recompiled. Is there a plugin to do something similar in vim?
I've just begun playing around with LaTeX-Box. It seems like a good plugin. I, also used VIM-LaTeX for a while, but I didn't really like the key mappings, and it seemed a bit to heavyweight as Jeet described.
I like LaTeX-Box so far because it used latexmk to compile, which is what I was using anyway. Latexmk will sit in the background and watch your .tex file for changes, and then automatically compile for you. And if you use a pdf viewer which refreshed changes (such as evince on Linux) you can see updates every time you change. Adding
let g:LatexBox_latexmk_options = "-pvc -pdfps"
to my .vimrc got latexmk working properly. You also need the latexmk script somewhere on you PATH. The key mapping to start latexmk is the same as Vim-Latex's compile: '\ll' (that's lowercase LL).
I also use SuperTab plugin for completions, which is great. And I took the dictionary files from Vim-LaTeX so I have a ton of auto completion words to use. This dictionary file is: ftplugin/latex-suite/dictionaries/dictionary in the vim-latex files. What I did was copy this file into ~/.vim/dictionaries/ and renamed it 'tex' then I added these lines to my .vimrc file:
set filetype on
au FileType * exec("setlocal dictionary+=".$HOME."/.vim/dictionaries/".expand('<amatch>'))
set complete+=k
Then if I type the beginning of a latex command and hit 'tab' I will get a list of completions. Pretty handy. BTW that 'au' command in the vimrc will also load dictionaries for any other filetypes if you want. A useful trick.
check out vim latex
If you use vim latex put the following in your .vimrc:
let g:Tex_DefaultTargetFormat='pdf'
and it should compile to pdf by default. (I think the default compilation key
is \ll).
You can also check AutomaticLatexPlugin, it has many nice features (see the features list).
Its main point is to compile the document in the background using autocommands, so that you are free from compilation cycle. This works nicely on Linux and MacOs. It contains (extended version of) Latex-Box.
vim-latex is great. But I found it too heavyweight for my tastes. I prefer more of a "Vim with LaTeX compile & view" approach, rather than "A LaTeX IDE with Vim key-bindings". So I rolled my own: 'TeX-PDF: Lightweight "stay-out-of-your-way" TeX-to-PDF development support'.
Also check out: "LaTeX Help : Help for LaTeX in vim.help format" for calling up help of LaTeX from within Vim.
I personally can get by on:
autocmd BufNewFile,BufRead *.tex set makeprg=pdflatex\ %\ &&\ open\ %:r.pdf
where open is Mac OS X specific. Linux users will want a different command to view their compiled file after running make. This works best if you have mapped a key to write and then run make (and you should - once you have single key save and compile, you'll never go back).