Wikia

Vim Tips Wiki

Reload your filetype/syntax plugin

Talk0
1,613pages on
this wiki
Revision as of 13:46, August 30, 2010 by Peterodding (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Tip 180 Printable Monobook Previous Next

created December 14, 2001 · complexity advanced · author Max Ischenko · version 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.

CommentsEdit

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.


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


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.


Alternative: reload.vim plug-inEdit

The reload.vim plug-in (script#3148) performs automatic reloading of most types of Vim scripts, i.e. (file-type) plug-ins, auto-load/syntax/indent scripts and color schemes.

Around Wikia's network

Random Wiki