Vim Tips Wiki
(Move categories to tip template)
(Remove html character entities)
Line 12: Line 12:
 
|category2=
 
|category2=
 
}}
 
}}
If you find yourself always re <tt>:so</tt> ing your vimrc after you changed it, have the following autocmd in your vimrc:
+
If you find yourself always re <tt>:so</tt> ing your [[vimrc]] after you changed it, have the following autocmd in your vimrc:
   
 
<pre>
 
<pre>
Line 25: Line 25:
   
 
----
 
----
expand('&lt;sfile&gt;') helps to find the .vimrc name.
+
expand('<sfile>') helps to find the .vimrc name.
   
 
For example, since I switch between Windows and Linux, my .vimrc contains:
 
For example, since I switch between Windows and Linux, my .vimrc contains:
exec 'cab vimrc' . expand('&lt;sfile&gt;')
+
exec 'cab vimrc' . expand('<sfile>')
   
 
----
 
----

Revision as of 09:35, 29 September 2008

Tip 879 Printable Monobook Previous Next

created February 19, 2005 · complexity basic · author Anon · version 5.7


If you find yourself always re :so ing your vimrc after you changed it, have the following autocmd in your vimrc:

autocmd! bufwritepost .vimrc source %

Comments

I did this and it seems to work. However I get a lot of errors (E174) saying command already exists for each line in my vimrc.


When you define functions in vimrc, use "function!". Some other commands should also have "!" appended, which means to overwrite the existing command.


expand('<sfile>') helps to find the .vimrc name.

For example, since I switch between Windows and Linux, my .vimrc contains:

exec 'cab vimrc' . expand('<sfile>')

Even better, put in your .vimrc:

autocmd BufWritePost .vimrc source %

And in your .gvimrc:

autocmd BufWritePost .vimrc source % source ~/.gvimrc
autocmd BufWritePost .gvimrc source %

The gvimrc part still has ~/.gvimrc hard-coded, though.