Latex and Vim usage - vim

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

Related

Is it possible to reload compiler plugins in Vim?

I am creating a small compiler plugin in Vim and I'm finding very slow to debug it.
It seems like there are ways to debug the errorformat but some times I just want to force Vim to reload my compiler plugin that I created in ~/.vim/after/compiler/
It doesn't look like I can just source the file as it fails because of CompilerSet. Is there any other way of reloading a compiler plugin?
Simply running :compiler {name} should reload your full compiler script.
See :help :compiler with the details of how a compiler plug-in is loaded.
An alternative is to source the compiler plug-in file directly. In order to handle the :CompilerSet command, you can either define the user command yourself before you run the plug-in file, or use a snippet in your plug-in file itself to define it if not defined already.
Many of the compiler plug-ins shipped with Vim include this snippet at the top:
if exists(":CompilerSet") != 2 " older Vim always used :setlocal
command -nargs=* CompilerSet setlocal <args>
endif
So apparently that's all you need...
But using :compiler {name} each time to fully source it should be a better approach, assuming that's a possibility to you.
(Tangentially) I find tpopeā€™s scriptease plugin to have many benefits when working on a vim plugin (and also when writing answers to vim questions where I have to dig deep into runtime files).
Highlights:
:PP is both a pretty-printer and a repl
:Runtime helps reload files
:Breakadd is much smarter
:Vedit and cousins open up files on the runtime path

vim snippet default snippet file issue

I installed Vundle, got the snippetMate running. But when vim launched, the snippet it loaded is _.snippets. With my Understanding, it is the default for snippet. However, i want to use other snippet such as sh.snippets and tex.snippets. I try to run the SnippetMateOpenFile in Vim to locate the snippets file It doesn't appear. I checked and see that all of the snippet file is there.
Yes, the _.snippets contains the global snippets. In order to use the other ones, the correct filetype has to be set. The snippet plugin reuses the same mechanism that Vim uses for syntax highlighting and settings (like indent) that are specific to a certain programming language. Usually, filetype detection works automatically; you can check with
:verbose setlocal filetype?
This needs to print sh for shell scripts, to use sh.snippets. If it doesn't, you have to fix / enable filetype detection (see :help filetype-detect), or, for a one-time fix, set it manually:
:setf sh
(I'm not sure about your particular snippet plugin; I guess it's snipMate, but there are multiple variants around.)
I found out what happened. the snippets won't recognize the snippet files rightaway. So i saved and exit the text and reopen vim again. It works, yet seems like there must be a certain tag in order for vim to recognize the format of the file.

How to get the value of minlines in 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...

Vim response quite slow

If I open a file containing 5,000 lines of code and continue to input, I found that my vim became very slow, it displays my input after about 1s.
It even won't become any better after I start up with --noplugin. But after switching my .vimrc file, everything gets fine again. The .vimrc file is written by myself and after checking for some time, I still can't locate the error. I have clear all the key maps, but the problem still exists.
So can you give my any advise or tell my how to debug in vim? I found there is a debug option but can't get how to work.
You can use the --startuptime option when start vim:
--startuptime {fname} *--startuptime*
During startup write timing messages to the file {fname}.
This can be used to find out where time is spent while loading
your .vimrc, plugins and opening the first file.
When {fname} already exists new messages are appended.
(Only available when compiled with the |+startuptime|
feature).
Take following steps to diagnose the problem:
type vim --startuptime log.txt main.java in bash to start vim
type :tabe log.txt in vim to view the log.
The reason for slowness is often the not set or wrong set ruby_path on compile time of vim (see also discussion on google vim/ruby google group). It is easier to set it in vimrc, because you can change it without recompiling vim. You can set the path through the g:ruby_path variable in your .vimrc file. Don't copy and paste both, use the right one.
If you setup RBENV you have to use this one:
" ruby path if you are using rbenv
let g:ruby_path = system('echo $HOME/.rbenv/shims')
If you setup RVM you have to use this one:
" ruby path if you are using RVM
let g:ruby_path = system('rvm current')
You can also use the vim-rbenv plugin, which sets the path too.
For me the part on loading ruby specific functions in vim got 10 times faster.
If you are using jruby, than the start up slowliness can be even bigger. See examples for fixing it here.
If running vim 7.4,
put this in your .vimrc
set regexpengine=1
vim 7.4 has a new regex engine that appear not to work well in some situations. Previous version vim 7.3 used the old engine ( set regexpengine=1 ).
The "slow response" from syntax highlighting problem affects the vim help files as well ( and .vimrc file too ).
Something like this is usually caused by syntax colouring. Try with :syntax off.
Add these lines to your ~/.vimrc or ~/.config/nvim/init.vim:
set lazyredraw " don't redraw everytime
set synmaxcol=128 " avoid slow rendering for long lines
syntax sync minlines=64 " faster syntax hl
Also if you're using tmux, consider adding this to your ~/.tmux.conf:
set -sg escape-time 10

How can I configure VIM so that files with extension .less are edited with zen-coding?

How can I configure VIM so that files with extension .less are edited with zen-coding?
I can use within the zencoding notepad + + on windows normally. But now I want to use the same way inside vim.
ZenCoding is probably activated on a per-filetype basis, if that's the case, just type :set filetype=css.
If you want this setting to stick, add this line to your .vimrc:
autocmd BufRead,BufNewFile *.less set filetype=css
If you want to retain the normal features that go with .less files (if any) you can do :set ft=less.css but some plugins don't like that.
I first tried to write a comment, but found then something that could be an answer.
So I think the question is: How can I configure VIM so that files with extension .less are edited with zen-coding?
At the official site for zen-coding, there are lists of editors that support zen-coding:
Official
third-party
Unofficial
There for VIM, the following sites are mentioned:
Sparkup
Zen Coding for VIM
I have read into both, and both seem to expand shortcuts to HTML code, not to less-code. But perhaps I have misunderstood the question.
I didn't know you could use Zencoding for css. I use it in Vim for html.It s great!I started using Less and I was wondering an hour ago ,If something like this existed. I guess it's something to work on.

Resources