Re: sourcing vimrc files

2006-05-16 Thread Jared
On 5/14/2006 8:41 PM, Gerald Lai wrote:
 Encase your function like this:
 
 if !exists(*Source_vimrc)
   function Source_vimrc()
   ...
   endfunction
 endif

Thanks, Gerald.  This worked perfectly.

Also, thanks to everyone else for their suggestions.  I appreciate the
feedback and read up on the suggested commands, but this ended up being the
easiest.  :-)

--
Jared


Re: sourcing vimrc files

2006-05-15 Thread Thor Andreassen
On Sun, May 14, 2006 at 07:49:11PM -0500, Jared wrote:
 I'd like to map a hotkey to re-source my vimrc files (system + user).  I
 originally tried this simple approach:
 
 nmap buffer S-F9 :source $VIM\vimrcCR
   \ :source $VIM\_vimrcCR
   \ :source $HOME\_vimrcCR
 
 But that failed because source aborts when the file doesn't exist.

You could probably use :runtime instead of :source.

:help :runtime

[...]

-- 
with kind regards
Thor Andreassen


Re: sourcing vimrc files

2006-05-15 Thread Benji Fisher
On Sun, May 14, 2006 at 06:41:39PM -0700, Gerald Lai wrote:
 
 Encase your function like this:
 
 if !exists(*Source_vimrc)
   function Source_vimrc()
   ...
   endfunction
 endif
 
 The reason you're getting the error is because you're sourcing the file
 (vimrc) that produced/will override the function (Source_vimrc) you're
 using at the moment.
 
 A few words of advice to source your vimrc cleanly:
 
   1. Define your functions in vimrc with function! so that when
  sourced again, the functions will be overwritten.
 
   2. Keep your autocmds in an augroup so that if it's sourced again, you
  can delete the augroup and redefine it instead of adding more of
  the same autocmds.
 
   3. If you're using the FuncUndefined autocmd, delete those functions
  that have been defined before.

 Those are all good suggestions (although testing
exists(*Source_vimrc) seems a little complicated).  One more
possibility is to put all function definitions, along with anything else
that never needs to be re-done, below a few lines like these:

 Skip the rest of the file if it has already been re-loaded.
if exists(s:deja_vu)
  finish
endif
let s:deja_vu = 1

function Source_vimrc()  no need for the !, this should never be read twice.
...

 BTW, another post on this thread pointed out that your vimrc file
knows its own name.  As of vim 7.0, this name is also stored in the
$MYVIMRC environment variable.

HTH --Benji Fisher


sourcing vimrc files

2006-05-14 Thread Jared
I'd like to map a hotkey to re-source my vimrc files (system + user).  I
originally tried this simple approach:

nmap buffer S-F9 :source $VIM\vimrcCR
\ :source $VIM\_vimrcCR
\ :source $HOME\_vimrcCR

But that failed because source aborts when the file doesn't exist.  I then
modified it to a function call, like so:

function! Source_vimrc()
if filereadable($VIM.'\vimrc')
source $VIM\vimrc
endif
if filereadable($VIM.'\_vimrc')
echo test1
source $VIM\_vimrc
echo test2
endif
if filereadable($HOME.'\_vimrc')
source $HOME\_vimrc
endif
endfunction
nmap buffer S-F9 :call Source_vimrc()CR

Longer and more complicated, but now I can check to see if the file exists
before sourcing it.  However, this also causes a problem: when I try to
source the file containing this function, it gives me an error saying that
it cannot replace the function because it is currently in use.  If I remove
the !, it still gives me an error because it already exists.

Any ideas how to work around this?  Or if you have a different/better way of
doing this, I'm certainly open to suggestions.  :-)

This is on Windows XP.  Thanks.

--
Jared


Re: sourcing vimrc files

2006-05-14 Thread Gerald Lai

On Sun, 14 May 2006, Jared wrote:

[snip]

Longer and more complicated, but now I can check to see if the file exists
before sourcing it.  However, this also causes a problem: when I try to
source the file containing this function, it gives me an error saying that
it cannot replace the function because it is currently in use.  If I remove
the !, it still gives me an error because it already exists.

Any ideas how to work around this?  Or if you have a different/better way of
doing this, I'm certainly open to suggestions.  :-)

This is on Windows XP.  Thanks.


Encase your function like this:

if !exists(*Source_vimrc)
  function Source_vimrc()
  ...
  endfunction
endif

The reason you're getting the error is because you're sourcing the file
(vimrc) that produced/will override the function (Source_vimrc) you're
using at the moment.

A few words of advice to source your vimrc cleanly:

  1. Define your functions in vimrc with function! so that when
 sourced again, the functions will be overwritten.

  2. Keep your autocmds in an augroup so that if it's sourced again, you
 can delete the augroup and redefine it instead of adding more of
 the same autocmds.

  3. If you're using the FuncUndefined autocmd, delete those functions
 that have been defined before.

For examples 2  3,

 augroup vimrc
   delete augroup
   autocmd!
   ...
   silent! delfunction MyFuncInOtherFile
   autocmd FuncUndefined MyFuncInOtherFile source 
$HOME/.vim/autoload/MyFuncInOtherFile.vim
   ...
   autocmd ...
   ...
 augroup END

HTH :)
--
Gerald