Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I unset a variable in Vim?

Tags:

vim

I have a plugin that sets a global variable and checks it each time the plugin is loaded to avoid loading itself multiple times. I would like to allow reloading of the plugin (allow reloading of the plugin) without altering the plugin itself. The plugin simply checks to see that it's variable exists (i.e. exists('g:var_name'))—is there a way to unset said variable so that the exists() check returns false?

p.s. I don't want to alter the plugin itself because I use pathogen with git submodules pointed at the plugin's repo.

like image 519
Drew Stephens Avatar asked Apr 22 '11 13:04

Drew Stephens


2 Answers

I found the Vim documentation for vimscript, which has a section on variables:

To delete a variable use the ":unlet" command. Example:

:unlet s:count 
like image 177
Drew Stephens Avatar answered Sep 20 '22 09:09

Drew Stephens


You should be able to :unlet g:var_name.

The problem with this is that if the functions defined in the plugin are not defined with function! then you're going to get lots of errors when the plugin is sourced for a second time. The plugin may also be doing initial setup that could get fouled up by running it twice.

In general, if the plugin author has added a loaded trap it's probably there for a reason.

like image 30
Randy Morris Avatar answered Sep 20 '22 09:09

Randy Morris