Wikia

Vim Tips Wiki

Changes: How to initialize plugins

Edit

Back to page

(Remove html character entities)
(Change <tt> to <code>, perhaps also minor tweak.)
 
Line 4: Line 4:
 
|previous=410
 
|previous=410
 
|next=413
 
|next=413
|created=January 23, 2003
+
|created=2003
 
|complexity=basic
 
|complexity=basic
 
|author=Charles E. Campbell, Jr.
 
|author=Charles E. Campbell, Jr.
Line 20: Line 20:
 
c. Via a command. Like (b), the vimrc is sourced prior to the plugin being sourced, so the command isn't available yet.
 
c. Via a command. Like (b), the vimrc is sourced prior to the plugin being sourced, so the command isn't available yet.
   
Solution: put in <tt>.vim/after/plugin</tt> a file of the same name as the plugin you're initializing. In that file put
+
Solution: put in <code>.vim/after/plugin</code> a file of the same name as the plugin you're initializing. In that file put
 
<pre>
 
<pre>
 
Maps : norm TheInitializationMap
 
Maps : norm TheInitializationMap
Line 27: Line 27:
 
</pre>
 
</pre>
   
For example, the <<tt>HiMtchBrkt.vim</tt>> script which supports the highlighting of matching brackets as you move onto a bracket is not on by default. Normally it requires one to type <tt>\[i</tt> to start it. However, if you'd like to have the script to start enabled, then put
+
For example, the <<code>HiMtchBrkt.vim</code>> script which supports the highlighting of matching brackets as you move onto a bracket is not on by default. Normally it requires one to type <code>\[i</code> to start it. However, if you'd like to have the script to start enabled, then put
 
<pre>
 
<pre>
 
norm \[i
 
norm \[i
 
</pre>
 
</pre>
   
into the file <tt>.vim/after/plugin/HiMtchBrkt.vim</tt>.
+
into the file <code>.vim/after/plugin/HiMtchBrkt.vim</code>.
   
 
Windows users: Change .vim to _vimfiles and / to \ in the tip above.
 
Windows users: Change .vim to _vimfiles and / to \ in the tip above.
Line 40: Line 40:
 
execute "SeeTab"
 
execute "SeeTab"
   
in my <tt>after\plugin\SeeTab.vim</tt> file with the original <tt>SeeTab.vim</tt> file in <tt>plugin\SeeTab.vim</tt>.
+
in my <code>after\plugin\SeeTab.vim</code> file with the original <code>SeeTab.vim</code> file in <code>plugin\SeeTab.vim</code>.
   
 
This works ok while gvim is open, but I get an error message when exiting:
 
This works ok while gvim is open, but I get an error message when exiting:

Latest revision as of 05:29, July 13, 2012

Tip 411 Printable Monobook Previous Next

created 2003 · complexity basic · author Charles E. Campbell, Jr. · version 6.0


Plugins have three basic ways of being initialized:

a. Via some variable that the plugin script uses; the initialization here is obvious -- set the desired variables in your vimrc (or use an appropriate autocmd to do so).

b. Via a map or function call. The problem here is that vimrc is sourced prior to plugin sourcing, so the map or function call isn't available yet.

c. Via a command. Like (b), the vimrc is sourced prior to the plugin being sourced, so the command isn't available yet.

Solution: put in .vim/after/plugin a file of the same name as the plugin you're initializing. In that file put

Maps         : norm TheInitializationMap
Function call: call TheInitializationFunction()
Command      : TheInitializationCommand

For example, the <HiMtchBrkt.vim> script which supports the highlighting of matching brackets as you move onto a bracket is not on by default. Normally it requires one to type \[i to start it. However, if you'd like to have the script to start enabled, then put

norm \[i

into the file .vim/after/plugin/HiMtchBrkt.vim.

Windows users: Change .vim to _vimfiles and / to \ in the tip above.

CommentsEdit

I've successfully used this approach to have SeeTab.vim automatically load by putting in the line:

execute "SeeTab"

in my after\plugin\SeeTab.vim file with the original SeeTab.vim file in plugin\SeeTab.vim.

This works ok while gvim is open, but I get an error message when exiting:

"E254: Cannot allocate color ."

How can I make this error not show up?

If I don't auto-load using the execute line, but instead type in the "SeeTab" command after gvim starts, then the error does not appear when exiting.

I'm using gvim 6.3 on WinXP. I'm also using blockhl.vim if that might be causing any conflicts.


Around Wikia's network

Random Wiki