Tuesday, August 21, 2018

Understanding automatic vimrc sourcing

-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEkUUNUzSmpIgOY04949f1rn+jWuUFAlt759UACgkQ49f1rn+j
WuWfCQ/+PIzibFaXB4wBLa6eFQFkuu1H1xb0kngvrxjHSX9/EptV4MQMtvKoUbSE
qUvYmPbOL9KnMeK8L6AOSZ0GPCj/k0obKlmm/FtFAD9tamvS/LAjGykmXAg7k6d1
SrNmWExN5ytuwYW1kkPOR5uat8Cc+hJhi2WaaN6WKlu7edQ1gplf6ka08dJjuYoR
/bwxWMTidtolPf1la3lQwn2OptxhsXcmzNqTjcf6U0aCwR8EnIizeVFvt8XMTWMD
z5cgCqtuKdVRVPzlENrFXy3L4gkRFQzTK991p57J8YaiqPs9r9XaAmWTevkJBwaN
b25qmWHLPPUu6aOWDLFExORrTpU0p0tVWRO7LK1ijGSxx2pXe1M+NoqintqAGrut
dylQkDUDzlYr1f5L5/Ac128JxYvx3gpNNjAsgd8hcMu1v7wye5WxJ4MOCRznOvMz
G3ri0ANhftNa/ijBLbaev7dgJSvZTRU/PjkDUr20MZpTjd8M/nXRjk23QjpAXcZ6
uQRrBTpjzBWY4Nesjiy+ojM22F2387lMfccFB9cUEbd11CuG24D74oMGLgL5ptJo
0uL4X9GP/78qAa6dGGQOyb4uXLqcS7IekpOs8YrsCQw1MUmN1tu0p+jo6DfwtQS2
vJ9eEREdPOY894FZd1qrze8nZ7TOkT1GEtxVBnzSrOudbNqPp1M=
=3Us0
-----END PGP SIGNATURE-----
Hello,

* What I want:

Be able to do :w after editing $MYVIRC and have vim source the new
version of config. Basically, just execute `source %` automatically.

* What I have tried (all examples are launched with `vim -u testvimrc`):

So, this works without any error, as supposed:
> set nocompatible
> filetype plugin indent on
> syntax on
>
> augroup vimrc
> autocmd!
> autocmd BufWritePost testvimrc source testvimrc | echom "Reloaded"
> augroup END

However, if I try wrapping it in a function, E127 occurs:
> set nocompatible
> filetype plugin indent on
> syntax on
>
> augroup vimrc
> autocmd!
> autocmd BufWritePost testvimrc call s:ReloadRC("testvimrc")
> augroup END
>
> function! s:ReloadRC(rc)
> exec 'source ' . a:rc | echom "Reloaded " . a:rc
> endfunction

Whenever I do :w, I see:
> E127: Cannot redefine function <SNR>1_ReloadRC: It is in use

But at the same time it doesn't abort and I see:
> Reloaded testvimrc
, so it looks like the new vimrc gets sourced regardless?..

* My questions:
1) Why doesn't this work if wrapped into a function, but does, if
written out directly?
2) Why, if an error occurs, I still see "Reloaded testvimrc"?
3) Does it have anything to do with reentrancy?
4) Is it possible to make it work through calling a function (since I
would want to do the same for gvimrc (as well as vimrc), and don't want
to have repetitive code, instead using a reusable function code)?

Thank you in advance.
--
Regards,
Oleksii Vilchanskyi
PGP:0x8D3A0E046BDE941F2A53867CE3FD952D48C0B338

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment