Is it possible to reload compiler plugins in Vim? - 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

Related

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 make Vim Quickfix show errors in source files instead of the make file

So I am programming in C with VIM by using the make command to compile my code.
I would like to use the quickfix plugin to quickly move to the different compile errors but the only error that quickfix shows is the failed command in the make file.
I have failed to find any clues on google for this problem, is there something I could be missing to make this work?
The quickfix list (it's built in, not a plugin) parses the output of :make according to the rules in the 'errorformat' option, in order to extract file names, line numbers, and error messages.
Usually, you don't write those yourself, but you simply choose the appropriate compiler plugin. If your build uses GCC, you can set the compiler by
:compiler gcc
See :help compiler for details and a list of compiler plugins that ship with Vim.
I have finally solved the problem.
It turns out that if your shell is set to use FISH the output of the make command displays correctly but for some reason quickfix is unable to pick up any errors except for the failed part in the make file.
I solved the problem by switching vim to use bash instead by adding set shell=/usr/bin/bash to my .vimrc file.

How can I reload a VIM plugin after VIM was started?

I am modifying an installed VIM plugin and in another Terminal tab I am testing the results.
Each time I want to test the changes I have to restart VIM.
Is there any faster way to do this process? How can I reload a VIM plugin after VIM was started?
The plugin is installed via Vundle
I have tried to run :so % that is supposed to reload the .vimrc file but I still cannot see my changes.
If there weren't an inclusion guard (if ! exists('g:loaded_pluginname') ...), you could simply :runtime! plugin/pluginname.vim (or :source % if it's currently opened) and all plugin definitions would be re-read.
But as most plugins (correctly) use such a guard, you need to :unlet that variable first:
:unlet g:loaded_pluginname | runtime! plugin/pluginname.vim
My ReloadScript plugin can do this with one command if the guard name adheres to the canonical naming, and the scriptease plugin has such a command, too.
Edit: Some plugins use differently named guard variables, or other ways that prevent reloading. The plugins from mattn (like emmet.vim) are quite elaborate; maybe there's some special mechanism; I don't use that plugin. You could ask the author for advice, though.

Use code completion in vim as in sublime text

I would to have a autocompletion exactly as in sublime text but in vim.
I want this behaviour :
When I start to type a word, I want to have a box which suggest completions;
In the suggested completions, I want to have last words used;
I want to have functions finded through ctags;
I want to have standard functions for the language I'm using;
I want to have snippets;
There is a lot of plugins about autocompletion for vim and I'm lost.
Currently I'm using YouCompleteMe... It's very good, though I dunno whether it can be configured to sort words based on last usage. It has general fuzzy completion capabilities that will work on any file type (you may find fuzzy completion awesome), but it also contains semantic completion for C/C++/Objective-C/Objective-C++ through libclang.
Particularly, I aways compile the lastest clang, libc++ and VIM from sources to tune and set VIM to use my environment python/ruby/etc and get a decent C++11 support. I then, compile YouCompleteMe from sources too, though I first install it through a plugin manager. My current choice is VAM, but there're others like Vundle and Pathogen.
Try this method:
for plugin in plugins
try
install plugin
read doc
test plugin
catch
remove plugin
endtry
endfor
Also, make sure you read and understand :h ins-completion before hunting down plugins.

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