How to get the value of minlines in Vim - vim

Vim often shows wrong highlight when opening perl files contain pod paragraphs, use command
:syn sync minlines=9999
can handle this problem.I am curious about the value of minlines,so,which command will show minlines's value of current opened file? I didn't find that in vim reference manual.

I do not think there is a native command for that. I suggest you to check it out directly in syntax files. For example, about Perl, take a look at perl.vim. I am on Arch Linux and this file is available here: /usr/share/vim/vim80/syntax/perl.vim. If you go to line 435, you should see this: syn sync minlines=0.
Be aware that some syntax files define specific minlines rules. In Ruby/Java files, you should be able to call :echo ruby_minlines or :echo java_minlines respectively. This will not work with Python, PHP or JavaScript.
Finally, if you are ready to sacrifice a bit of performance for better ergonomics, you can add the following command to your .vimrc: autocmd BufEnter * :syntax sync fromstart
I use it to avoid annoying issues with syntax highlighting. It works great, but Vim will be extremely slow if you try to edit huge files...

Related

Syntax file sourced from the plugin is overwritten by Vim

I am creating a very simple plugin to make syntax highlighting better in Vim for baan syntax (basically an improved version of syntax/baan.vim).
This is my plugin directory.
One file inside ftdetect folder; baan.vim. It looks like this.
au BufRead,BufNewFile *.bc set filetype=baan
The file inside syntax folder; baan.vim. It is almost the same as baan.vim in syntax folder within Vim. With one line of change in syntax highlighting.
My problem is when I open any files with .bc extensions, two more syntax files are called; one before my own plugin syntax file, and other one is after.
bc.vim syntax file is called already from filetyp.vim, I guess. Because filetypes I want to set syntax is with extension .bc. This is the first issue. Second one is that I set filetype to 'baan' but Vim is looking and sourcing all baan.vim files. But once baan.vim is source from myplugin, it is still sourcing the one from Vim itself. How can I solve those issues elegantly without using /after directory?
This is normal. Consider the following.
$VIMRUNTIME/filetype.vim sources ftdetect/*.vim scripts near to the end. At this point setf bc was already executed and the first FileType event was triggered and processed. BTW. This is the reason why late set ft=baan works but setf baan no more. Shouldn't be a problem though, as :syn clear is executed in $VIMRUNTIME/syntax/synload.vim automatically. And no, you can't do anything with this unless you patch/replace filetype.vim.
synload.vim intentionally sources all matching files (:runtime!). This is the reason they respect b:current_syntax variable. The first to set it wins, others step aside by executing :finish at a top. Nonetheless, they all are sourced and get into :scriptnames. Note this also means that extending existing syntax with after/syntax (while not respecting b:current_syntax) is usually more preferable.

vim syntax highlighting weirdness

I have some specific settings for my latex highlighting and am using the indentLine plugin, which requires let g:indentLine_fileTypeExclude = ['tex', 'bib'] to avoid the conceal feature annoyance. Anyway, when I start vim with vim filename.tex my vimrc gets loaded properly, but when I simply call vim and then open a given tex file, it'll ignore the vimrc.
Any idea what's causing it? Also, let me know what information you need, as I am far from certain on what would be needed.
EDIT:
Okay so I've found that for both cases i'm in a [tex] environment, but if I'm in a [plaintex] environment then the weirdness doesn't happen. If that helps anyone.
2nd EDIT:
New development, it is only the first file that's opened that seems to ignore the exclusion for indentLine, the remainder are shown exactly as they ought to.
The plaintex is a separate filetype in Vim (cp. :help ft-plaintex), so you need to add it to the IndentLine config:
let g:indentLine_fileTypeExclude = ['tex', 'plaintex', 'bib']
Edit This now looks like a command ordering issue. It's hard to remotely troubleshoot this, as the exact plugins and their initialization order may be important. Please capture a full log of a Vim session with vim -V20vimlog. After quitting Vim, examine the vimlog log file for the ordering of commands (but it might be difficult to see what's happening in a potentially vast list of commands).
It might be sufficient to just reload the first file that has those problems, with :e!.

Import/Load list of compiler warnings/errors to highlight in buffers?

In vim you can start a build process using the :make command. Now I'd like to start the build process from outside of Vim (for example a nightly build) and load the compiler error/warning log, highlighting all the errors and warnings in the opened buffers.
Can Vim do this with built-in functionality or do I need a vimscript for that; and if so, which one?
You're looking for :cfile / :cgetfile:
:cf[ile][!] [errorfile] Read the error file and jump to the first error.
The file you're reading naturally must be in a format that can be parsed by the 'errorformat' option.
For Vimscript, there's also a setqflist() function.
Highlighting
Once the errors are properly parsed in the quickfix list, there are a couple of plugins that can highlight the locations, for example the cuteErrorMarker plugin.

Detect filetype in vim without valid file extension

I'm looking for a way to determine the filetype of a file in vim and set the syntax highlighting based on the filetype. The only catch is I cannot use the file extension for determining the filetype.
This is my scenario: I use vimdiff or gvimdiff as my P4DIFF tool, which shows the changes between the files in my local copy and the ones from the perforce server. Perforce seems to bring in the files from the perforce server into the /tmp directory and uses the PID to name the file, for example:
/tmp/tmp.24673.23
This was for a C++ source file.
The most frequent filetypes I encounter in the perforce repository are C/C++ sources and header files, Makefiles, python scripts, perl scripts, ruby scripts, and tcl scripts.
I've looked into using modeline, but most of the sources in our tree do not have this information embedded in the file.
This post mentions about a possible approach to search and identify a magic pattern. I could not find any consistent magic pattern that I could get a high success rate with.
Tried using the file binary on my linux box to see what results I get. It seems to identify C/C++ sources well, but fails for Makefiles and even python scripts (which don't have the hashbang)
One good thing is that, among the 2 files that are compared, the file on the right is from my local copy and hence has the correct file name with extension, thereby syntax highlighting is enabled correctly for the file on the right.
Is there a way I could leverage this to set the same syntax highlighting for the file displayed on the left ?
Any alternate solutions to this problem are also welcome.
This was an interesting puzzle. :)
aug SmartDiffType
au!
au VimEnter * :if &diff && len(&ft) | call setwinvar(2/winnr(),'&ft',&ft) | elseif &diff | let &ft=getwinvar(2/winnr(),'&ft') | endif
aug END
Notes:
Of the 4 lines above, you only need the au VimEnter line, but it is generally a good practice to put autocommands in some autocommand group with a reset (au!) at the top.
Autocommand on VimEnter because otherwise diff or the windows are not properly intialized yet
vimdiff might have been triggered with the old file on the right or the left of the split, so we consider both cases.
The 2/winnr() is a math trick to flip between 1 and 2 (2/2 = 1, 2/1=2)
Assuming that you have open only the 2 splits and the split on the left is your local file you can do the following
:windo let &ft = getwinvar(1, '&ft')
This will set the filetype to the value of the top left most window for all windows.
For more help see:
:h :windo
:h 'ft'
:h getwinvar(

Latex and Vim usage

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).

Resources