简体   繁体   English

如何在vim中覆盖〜/ .vim和〜/ .vimrc路径(但没有其他路径)?

[英]How can I override ~/.vim and ~/.vimrc paths (but no others) in vim?

Let's say I have a tarball of all my vim config - everything normally inside ~/.vim (plugins, autoload, colours, all that stuff), and a vimrc file. 假设我有一个所有vim配置的tarball - 一切都在〜/ .vim(插件,自动加载,颜色,所有东西)和vimrc文件中。 I extract this to a directory somewhere. 我将其解压缩到某个目录。 So in the directory where I am ($PWD), there is a "vim" folder and a "vimrc" file. 所以在我所在的目录($ PWD)中,有一个“vim”文件夹和一个“vimrc”文件。 (note: this directory will be read-only, so vim shouldn't try to write into it). (注意:这个目录是只读的,所以vim不应该尝试写入它)。

What command-line arguments or environment variables can I give to vim to ensure that all my plugins, syntax, etc is loaded as well as the vimrc, in the same order as they normally would if they were located in ~/.vim and ~/.vimrc 我可以向vim提供哪些命令行参数或环境变量,以确保加载所有插件,语法等以及vimrc,其顺序与它们位于〜/ .vim和〜时的顺序相同/.vimrc

As a bonus, I'd like to ignore the host computer's ~/.vimrc and ~/.vim if possible (but this is not mandatory). 作为奖励,如果可能的话,我想忽略主机的〜/ .vimrc和〜/ .vim(但这不是强制性的)。

If you're wondering why I don't just chuck the files in ~/.vimrc and ~/,vim, I'm trying to package up my own vim configuration and take it with me. 如果你想知道为什么我不只是把文件放在〜/ .vimrc和〜/,vim中,我正在尝试打包我自己的vim配置并随身携带它。 I don't want to clobber the vim config of the computer I'm using, I just want to start a vim session with my config. 我不想破坏我正在使用的计算机的vim配置,我只想用我的配置启动vim会话。

I have a portable .vim folder exactly as you described, this is how I have set it up: 我有一个与你描述完全相同的便携式.vim文件夹,这就是我设置它的方式:

  • Put your portable .vimrc file inside your .vim folder. 将便携式.vimrc文件放在 .vim文件夹中。

  • Add the following lines to the start of your portable .vim/.vimrc : .vim/.vimrc添加到便携式.vim/.vimrc的开头:

" set default 'runtimepath' (without ~/.vim folders)
let &runtimepath = printf('%s/vimfiles,%s,%s/vimfiles/after', $VIM, $VIMRUNTIME, $VIM)

" what is the name of the directory containing this file?
let s:portable = expand('<sfile>:p:h')

" add the directory to 'runtimepath'
let &runtimepath = printf('%s,%s,%s/after', s:portable, &runtimepath, s:portable)
  • Start vim by using: vim -u /path/to/portable/vim/.vimrc . 使用以下命令启动vim: vim -u /path/to/portable/vim/.vimrc

On Unix & Linux systems (and maybe Windows) Vim uses the $HOME environment variable to locate the .vimrc file and .vim directory. 在Unix和Linux系统(也许是Windows)上,Vim使用$ HOME环境变量来定位.vimrc文件和.vim目录。 So you can cd into the directory where you have your custom versions and start vim or gvim like this: 所以你可以进入你自定义版本的目录,然后像这样启动vim或gvim:

HOME=. vim files....

My solution isn't quite the same but could be adapted pretty easily. 我的解决方案并不完全相同,但可以很容易地进行调整。

I have my Vim setup on my workstation and it's shared through regular Windows file sharing. 我在工作站上安装了Vim,并通过常规Windows文件共享进行共享。 I have this batch file that I can launch from any other computer in the building (and there's an install of Vim on another network share since most workstations don't even have Vim installed). 我有这个批处理文件,我可以从建筑物中的任何其他计算机启动(并且由于大多数工作站甚至没有安装Vim,因此在另一个网络共享上安装了Vim)。 I just run this batch file and am in my happy place. 我只是运行这个批处理文件,我在我快乐的地方。

set MYWORK=\\my_pc\work
set RCBASE=%MYWORK%\personal\utilities\tom.

start \\server\software\vim\vim73\gvim.exe -u %RCBASE%vimrc -U %RCBASE%gvimrc

So basically the adaptation would put the batch file, shell script, or otherwise into the archive you're unpacking and launch the system vim with your local files. 因此,基本上,修改会将批处理文件,shell脚本或其他方式放入您正在解压缩的存档中,并使用本地文件启动系统vim。

This "vimrc File and Vim Runtime Directories" screencast might be useful, as well as the vim documentation for 'runtimepath' , which states the following: 这个“vimrc文件和Vim运行时目录”截屏可能很有用,以及'runtimepath'vim文档 ,其中说明了以下内容:

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).

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM