sponsor Vim development Vim logo Vim Book Ad

advanced Tip #180: Reload your filetype/syntax plugin

 tip karma   Rating -2/2, Viewed by 1218 

created:   December 14, 2001 3:33      complexity:   advanced
author:   Max Ischenko      as of Vim:   6.0

Ever tried to write/debug your own  filetype/syntax plugin?

It's an iterative process which involves editing plugin code and testing it on some
sample file. To see changes you made in your plugin simply do :e on sample file.
This will force Vim to reload all buffer-specific files, including your plugin.

 rate this tip  Life Changing Helpful Unfulfilling 

<<Simplify help buffer navigation | get the vim patched source >>

Additional Notes

Cory T. Echols, December 14, 2001 4:40
This tip really oversimplifies the issue.

Your plugin may be designed to only run once per buffer, no matter how many times that buffer has ":e" run on it.  Also, if you remove a mapping or option setting from your plugin, and then just call ":e" on your sample buffer, the mapping will still be there, as no commands were run to clear it out.

The absolutely most effective way I can think of to test your plugin is to edit it in one instance of vim, and another instance of vim for testing the plugin.  As you save changes to your plugin, you'll need to exit and restart the "test" instance of vim.  Luckily, vim has a very fast startup time :)

There may be other less brute-force methods of doing this.  If anyone has any suggestions, please add them.

[email protected], December 14, 2001 4:55
Another issue to keep in mind, especially if ever plan on sharing your
plugin with others is the convention of having a:

if exists("loaded_typecorr")
  finish
endif
let loaded_typecorr = 1

as is suggested by ':h write-plugin' an searching for 'NOT LOADING'.

And I quote:
"This also avoids that when the script is loaded twice it would cause error
messages for redefining functions and cause trouble for autocommands that are
added twice."
[email protected], January 23, 2002 20:21
What I do to reduce the number of times I have to restart vim when debugging is use the recommended multiple loading check with the additional check of a global debug variable specific to your plugin.  For example:

if exists ("plugin_name_loaded") && !exists ("g:plugin_name_debug_mode")
  finish
endif
let plugin_name_loaded = 1

----

This works as long as you are only adding new functions/mapping or changing existing functions/mappings (defined with the ! method).  But that's the case most of the time, so while debugging, you can just :so plugin_file without quitting the vim you are testing with. If you delete functions/maps, you'll have to restart as the previous note  mentioned.
If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to [email protected] after searching the archive. Help Bram help Uganda.
Sponsored by Web Concept Group Inc. SourceForge Logo