如何在vim中覆盖〜/ .vim和〜/ .vimrc路径(但没有其他路径)? [英] How can I override ~/.vim and ~/.vimrc paths (but no others) in vim?

查看:268
本文介绍了如何在vim中覆盖〜/ .vim和〜/ .vimrc路径(但没有其他路径)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个所有我的vim配置文件 - 一切正常的〜/ .vim(插件,自动加载,颜色,所有东西)和一个vimrc文件。我把这个提取到某个目录。所以在我的目录($ PWD),有一个vim文件夹和一个vimrc文件。 (注意:这个目录将是只读的,因此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. I extract this to a directory somewhere. So in the directory where I am ($PWD), there is a "vim" folder and a "vimrc" file. (note: this directory will be read-only, so vim shouldn't try to write into it).

我可以给什么命令行参数或环境变量vim以确保我所有的插件,语法等加载以及vimrc,按照他们通常情况下,如果他们位于〜/ .vim和〜/ .vimrc

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

作为一个奖励,我想忽略主机的〜/ .vimrc和〜/ .vim如果可能(但这不是强制性的)。

As a bonus, I'd like to ignore the host computer's ~/.vimrc and ~/.vim if possible (but this is not mandatory).

如果你想知道为什么我不只是把文件夹在〜/ .vimrc和〜/,vim,我试图打包我自己的vim配置,并带我。我不想破坏我正在使用的计算机的vim配置,我只是想用 配置启动一个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. 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 文件夹就像你所说的,这是我如何设置:

I have a portable .vim folder exactly as you described, this is how I have set it up:


  • .vimrc 档案 code> .vim 文件夹。

.vim / .vimrc :

Add the following lines to the start of your portable .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)




  • vim使用: vim -u /path/to/portable/vim/.vimrc

    • Start vim by using: vim -u /path/to/portable/vim/.vimrc.
    • 这篇关于如何在vim中覆盖〜/ .vim和〜/ .vimrc路径(但没有其他路径)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆