Configuration 如何在vim中覆盖~/.vim和~/.vimrc路径(但不覆盖其他路径)?
假设我有一个关于我所有vim配置的tarball-通常在~/.vim中的所有东西(插件、自动加载、颜色等等),还有一个vimrc文件。我将其解压缩到某个目录中。所以在我所在的目录($PWD)中,有一个“vim”文件夹和一个“vimrc”文件。(注意:这个目录将是只读的,所以vim不应该尝试写入它) 我可以向vim提供哪些命令行参数或环境变量,以确保我的所有插件、语法等与vimrc一起加载,加载顺序与位于~/.vim和~/.vimrc中时的顺序相同 作为奖励,如果可能的话,我想忽略主机的~/.vimrc和~/.vim(但这不是强制性的) 如果你想知道为什么我不把文件扔进~/.vimrc和~/.vim中,我正在尝试打包我自己的vim配置并随身携带。我不想破坏我正在使用的计算机的vim配置,我只想用我的配置启动一个vim会话。在Unix和Linux系统(可能还有Windows)上,vim使用$HOME环境变量来定位.vimrc文件和.vim目录。因此,您可以将cd刻录到拥有自定义版本的目录中,然后像这样启动vim或gvim:Configuration 如何在vim中覆盖~/.vim和~/.vimrc路径(但不覆盖其他路径)?,configuration,vim,Configuration,Vim,假设我有一个关于我所有vim配置的tarball-通常在~/.vim中的所有东西(插件、自动加载、颜色等等),还有一个vimrc文件。我将其解压缩到某个目录中。所以在我所在的目录($PWD)中,有一个“vim”文件夹和一个“vimrc”文件。(注意:这个目录将是只读的,所以vim不应该尝试写入它) 我可以向vim提供哪些命令行参数或环境变量,以确保我的所有插件、语法等与vimrc一起加载,加载顺序与位于~/.vim和~/.vimrc中时的顺序相同 作为奖励,如果可能的话,我想忽略主机的~/.vi
HOME=. vim files....
这可能是有用的,也可能是有用的,其中说明了以下内容:
This is a list of directories which will be searched for runtime files:
filetype.vim filetypes by file name |new-filetype|
scripts.vim filetypes by file contents |new-filetype-scripts|
autoload/ automatically loaded scripts |autoload-functions|
colors/ color scheme files |:colorscheme|
compiler/ compiler files |:compiler|
doc/ documentation |write-local-help|
ftplugin/ filetype plugins |write-filetype-plugin|
indent/ indent scripts |indent-expression|
keymap/ key mapping files |mbyte-keymap|
lang/ menu translations |:menutrans|
menu.vim GUI menus |menu.vim|
plugin/ plugin scripts |write-plugin|
print/ files for printing |postscript-print-encoding|
spell/ spell checking files |spell|
syntax/ syntax files |mysyntaxfile|
tutor/ files for vimtutor |tutor|
And any other file searched for with the |:runtime| command.
The defaults for most systems are setup to search five locations:
1. In your home directory, for your personal preferences.
2. In a system-wide Vim directory, for preferences from the system
administrator.
3. In $VIMRUNTIME, for files distributed with Vim.
*after-directory*
4. In the "after" directory in the system-wide Vim directory. This is
for the system administrator to overrule or add to the distributed
defaults (rarely needed)
5. In the "after" directory in your home directory. This is for
personal preferences to overrule or add to the distributed defaults
or system-wide settings (rarely needed).
我有一个便携式
.vim
文件夹,与您描述的完全一样,我是这样设置的:
- 将便携式
文件放入.vimrc
文件夹中.vim
- 将以下行添加到便携式
的开头:.vim/.vimrc
- 使用以下命令启动vim:vim-u/path/to/portable/vim/.vimrc
- 我的解决方案并不完全相同,但可以很容易地进行调整
我在我的工作站上安装了Vim,并通过常规的Windows文件共享来共享。我有一个批处理文件,可以从大楼中的任何其他计算机启动(还有一个Vim安装在另一个网络共享上,因为大多数工作站甚至没有安装Vim)。我只是运行这个批处理文件,我很高兴
set MYWORK=\\my_pc\work
set RCBASE=%MYWORK%\personal\utilities\tom.
start \\server\software\vim\vim73\gvim.exe -u %RCBASE%vimrc -U %RCBASE%gvimrc
因此,基本上,自适应会将批处理文件、shell脚本或其他内容放入正在解包的归档文件中,并使用本地文件启动系统vim。我过去使用过以下方法,但自动加载函数似乎不起作用(当从我的vimrc调用它们时):
vim--cmd“set runtimepath+=$(dirname$0)/vim,$VIMRUNTIME“-u“$(dirname$0)”/vimrc“$@”
好主意,但有两个问题:(1)这会破坏使用(比如:e~/Docs/whatever.txt)打开文件的过程。(2)我忘了提到这一点,但工作目录必须是只读的(我会更新问题).vim在无法写入~/.viminfo时会抱怨。这解决了我在不同目录和不同vimrc文件中运行不同版本vim的问题。谢谢!谢谢。我确实尝试过设置runtimepath,但它似乎无法加载病原体函数(它位于autoload中,我认为这会造成麻烦)。原来它只是因为其他原因而退出(cp模式处于启用状态)。我的最终脚本设置$VIM_BASE,我的skelton vimrc将$VIM_BASE添加到运行时路径,然后源代码生成真正的vimrc。expand中似乎缺少一个
。我认为应该是让s:portable=expand(':p:h'))
。它只对我起作用。Vim 7.3set nocompatible应该是第一行。似乎-u将其作为默认值禁用。而不是使用s:portable
(在Vim上7.4
)env.variable。
set MYWORK=\\my_pc\work
set RCBASE=%MYWORK%\personal\utilities\tom.
start \\server\software\vim\vim73\gvim.exe -u %RCBASE%vimrc -U %RCBASE%gvimrc