Search code examples
vimzsh

Is sourcing files from Vim (vs Shell) command line possible?


New to all this stuff. Been sourcing .vimrc file with no problems from within Vim's command line for a while with no problems. Recently installed code-minimap via cargo (as opposed to package manager due to limited permissions on account) and added the plugin to my .vimrc file (using vim plug for manager). At this point it didn't work (was saying 'minimap: this plugin requires code-minimap installed' when opening anything with vim). I found that I'm supposed to add the directory of the code-minimap binary to my shell rc file, which is .zshrc and after doing so I sourced .zshrc from vim's command line. Immediately got these errors:

Error detected while processing /student/myaccount/.zshrc: line 1: E488: Trailing characters: Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc.: # Enable Powerlevel10k instant prompt. Should stay close to the top of ~/.zshrc. line 2: E488: Trailing characters: Initialization code that may require console input (password prompts, [y/n]: # Initialization code that may require console input (password prompts, [y/n] line 3: E488: Trailing characters: confirmations, etc.) must go above this block; everything else may go below.: # confirmations, etc.) must go above this block; everything else may go below. line 4: E121: Undefined variable: r line 118: E171: Missing :endif

My zsh shell stills works and so do all the oh-my-zsh plugins AND so does minimap.vim. The syntax is correct as far as I can tell, nothing in the zshrc file should be causing any errors. Can upload if needed. If I source my file from a terminal shell (bash, or zsh in my case) there's no error messages.

So is it the vim command line that's incapable of sourcing anything other than it's own rc file, or is my .zshrc file syntax incorrect?

Figured I'd try to see if it's limited to .zshrc so sourced .bashrc and same problem. Errors galore even though there's nothing wrong with the syntax.

Asked professor gpt and he had this to say

However, when you open your .zshrc file in Vim and try to source it from Vim's command line (by entering :source ~/.zshrc within Vim), the file is being sourced in a different context. Vim runs commands in its own internal environment, which may not have all the same settings and configurations as your regular shell environment.

But I don't know enough to take his word on this. So is there anything wrong with my zshrc file or is it just the manner in which I'm attempting to source it in that's the issue?


Solution

  • I sourced .zshrc from vim's command line

    Vim and shell are different languages, so no, that’s not supposed to work.

    If you normally start Vim from a context where .zshrc is sourced (e.g. directly from your zsh shell in a terminal), then all you have to do to apply the changes is restart Vim from a fresh shell instance (or a non-fresh one where you’ve run source ~/.zshrc).