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

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.

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 not recognizing some commands from vim-latex

I have vim-latex installed via Vundle and I'm trying to disable some annoying mapping that it sets up by default. From the docs I know that, for example, I can use the following command to unmap FEM:
call IUNMAP('FEM','tex')
But when I type that I get the error E117: Unknown function: IUNMAP.
I have installed vim-latex with Vundle by including Plugin 'LaTeX-Suite-aka-Vim-LaTeX' in my vimrc and I have just used the PluginUpdate command to update everything, which runs with no error, so I should have the latest version of the package.
Am I missing something here?
Actually, the problem you're having is related to where you're getting your vim-latex from.
With:
Plug 'LaTeX-Suite-aka-Vim-LaTeX'
You're getting it from here, which you'll notice hasn't been updated since 2010. Looking at the plugin/imaps.vim file in that repository, you'll see there's a definition for function IMAP(), but not for IUNMAP(), which was probably introduced after the last date that repository was synced...
Use this source instead:
Plug 'vim-latex/vim-latex'
Which will get it from here which is an official maintained location for this plug-in.
If you look at plugin/imaps.vim in that source tree, you'll notice function! IUNMAP is defined there.
Updating to the correct plug-in location should fix this problem for you (together with probably quite a few fixes from the last 10 years!)
The functions IMAP() and IUNMAP() are loaded by the vim-latex plug-in only after your vimrc is processed. So you need to execute them from a context where they're available.
Furthermore, in order to have your unmapping succeed, you need to actually execute it after the mapping was created, and mappings are typically created when the filetype is set.
The documentation mentions that these overriding rules should be done in specific files:
An important thing to note is that if you wish to over-ride macros created by Latex-Suite rather than merely create new macros, you should place the IMAP() (or IUNMAP()) calls in a script which gets sourced after the files in Latex-Suite.
A good place typically is as a file-type plugin file in the ~/.vim/after/ftplugin/ directory. [...]
For example, to delete a mapping, you can use
call IUNMAP('FEM', 'tex')
in ~/.vim/after/ftplugin/tex_macros.vim.
The documentation mentions that you should use a file in ftplugin after the filetype you use. Check :set ft? to confirm yours is indeed tex, in which case you can use tex.vim, tex_something.vim (like the suggested tex_macros.vim) or tex/something.vim (a subdirectory.)

How to enable YCM for MacVim only (while keep it disabled for terminal Vim)

I've been using Vim for a while but still get confused by configuration. I want to config my Vim in such a way that YCM (YouCompleteMe, an auto-complete plugin) only gets loaded if running in GUI mode (e.g. MacVim), while if terminal Vim (maybe misnomer, I mean text-based Vim launched from command line) runs, YCM won't be loaded.
This question actually can be generalized to "How to selectively load plugins depending on running mode?". I though it must has been considered elsewhere, but Google gets me little useful information.
if has("gui_running")
... enable gui stuff here
else
... enable terminal stuff here
endif
(see h: feature-list)
Put your GUI-only configuration in the file .gvimrc.
Console Vim sources .vimrc when it starts. GUI Vim sources .vimrc and then .gvimrc, so settings in .gvimrc can override settings in .vimrc. For more information, see :help gui-start.

How to make vim pathogen to reload plugins?

Is it possible to make vim to reload pathogen plugins without restarting vim?
I have opened vim with many files, then I add plugin to:
~/.vim/bundle
Since now I'd like to force vim to use the new plugin.
Pathogen just manipulates the 'runtimepath' option; the situation with plugin reloads is therefore the same as with the plain default plugin structure. (Other plugin managers may offer this kind of reload / dynamic enable functionality; I suppose you want to stick with Pathogen.)
To retroactively enable a plugin in a running Vim session, you need to :source all (usually that's only one) plugin scripts that have been added. For a plugin named foobar, that would be:
:source ~/.vim/bundle/foobar/plugin/foobar.vim
If you can get Pathogen to re-initialize the 'runtimepath' (or augment it yourself via :set rtp+=~/.vim/bundle/foobar), you can also use the shorter
:runtime plugin/foobar.vim
If you use a modern version of vim, you can use its built-in package manager, which has a convenient function to reload all plugins:
:packloadall
http://vimhelp.appspot.com/repeat.txt.html#%3Apackloadall
I was in the same boat before util I find an awesome plugin(vim-reload) to do these stuffs automatic in an amazing way.You should have a shot at this plugin.

share eclim -friendly .vimrc

I am trying to to use eclim for my daily development requirements. My .vimrc has some issues preventing few functionalities like code completion etc.
It would be great if anyone using eclim regularly share your .vimrc.
You can find my vim setup on github. I use eclim to do Android development.
See visualstudioinvoke.vim for how I launch Vim from eclim. This isn't necessary, but it's useful to start at the current line in the current file. It also sets up my eclim menu, bindings, and settings.
It's best to start the eclim server (by opening the "Eclim" eclipse tab) before you start gvim.
I have eclim's code completion mapped to Ctrl-Space.
You won't get any code completion for classes that aren't in the scope of the current file. To import, I have a menu option under Eclim > ImportMissing.
However, my vimrc might be pretty alien to you, so you might be better served whittling down your vimrc until you figure out what's breaking things. The default map for completions is Ctrl-x Ctrl-u. You can use :verb map <C-x> to search for maps that start the same way and it will show you where they're defined.
If you use SuperTab, try disabling it. SuperTab and eclim are both maintained by
Eric Van Dewoestine so they should be compatible, but you may have a SuperTab configuration problem.
You could also try updating all of your plugins.

Resources