0

At some point which I cannot pinpoint, sourcing $MYVIMRC on the fly stopped working.

I tried the solution given here

Vim doesn't source $MYVIMRC

by typing the following on my terminal: export VIMINIT='source ~/.vimrc'

That didn't work.

Changes to my vimrc file are reflected once I restart Vim, but not reflected without doing so. Please help.

  • 1
    It’s $MYVIMRC, not $MYVIRC. What’s the output of :echo $MYVIMRC and is your vimrc at that location? – Rich Oct 14 '22 at 12:12
  • 3
    Just to be clear: the normal behavior is that your vimrc is only sourced once, on startup. You can source it manually or automatically by running certain commands. Perhaps How to debug my vimrc will be helpful – D. Ben Knoble Oct 14 '22 at 13:25
  • 1
    @D.BenKnoble I think they’re saying that :so $MYVIMRC doesn’t source the file, but it’s a bit unclear. @Alvaro: could you please clarify? – Rich Oct 14 '22 at 17:58
  • 1
    @Rich that is correct. Or, at least, :source $MYVIMRC is not displaying the behaviour I have come to expect, which is reflecting the changes I make to vimrc on the fly.

    and :echo $MYVIMRC shows /home/alvaro/.vimrc, as expected. Apologies for the typo on the main post

    – Alvaro Neto Oct 15 '22 at 04:48
  • 1
    It doesn't seem likely in this case, but it's worth investigating: I saw this once where I had somehow ended up with a vimrc in two different locations and i was editing one that was not being sourced. I don't remember how I did it but I was quite irritated with myself when I figured it out. – MDeBusk Oct 15 '22 at 07:00
  • 2
    Some things to try: 1. What changes are you making? 2. What happens if you replace the entire contents of your file with echom "test"? 3. Does it work if you type in the actual file path instead of $MYVIMRC? 4. Does it work if you copy the file to a different location and source that? – Rich Oct 15 '22 at 07:41
  • 1
    @MDeBusk just checked, this doesn't seem to be the issue.

    @Rich I am adding new mappings, i.e. nnoremap <leader>m, which, again, works when Vim is restarted, but not otherwise. To your second question, once I source it, test is printed to messages (as you may have predicted). So this pin-points the issue (but I still don't know how to solve it).

    1. Had tried it before, didn't work; 4. No, the same behaviour: changes are reflected only after restarting.

    Apologies for my delay in replying to you both.

    – Alvaro Neto Oct 17 '22 at 14:54
  • @AlvaroNeto I'm guessing this issue is long-fixed by now, but just for the record, it sounds like something in your vimrc is causing the lines you've added never to be executed when you re-source the file. Hard to say what that could be without seeing the entire file. As D. Ben Knoble suggested at the time, the techniques described here will help you track down the issue: https://vi.stackexchange.com/q/2003/343 – Rich Nov 20 '23 at 09:17
  • @Rich not so much. I had given up at the time, I will give it another shot some time soon. This is appreciated and bookmarked. – Alvaro Neto Nov 24 '23 at 12:57

0 Answers0