将 .vimrc 放入 vimfiles 目录中

发布于 2024-09-26 19:35:42 字数 455 浏览 3 评论 0原文

我想将我的 Vim 和 Emacs 配置置于版本控制之下,但我希望我的整个主文件夹都在那里(或者更确切地说,我愿意,但应该有 3 个独立的存储库)。使用 Emacs,这很容易;如果 ~/.emacs 不存在,则使用 ~/.emacs.d/init.el 作为初始化文件。所以我可以在 ~/.emacs.d/ 中有一个单独的 Git 存储库。对于 Vim,似乎 .vimrc 只能存在于主文件夹中,而不存在于 ~/vimfiles 中(相当于 ~/. emacs.d)。 是将 .vimrc 置于版本控制之下的最佳方式吗?

I want to keep my Vim and Emacs configurations under version control, but I don't want my entire home folder there (or rather, I do, but there should be 3 separate repositories). With Emacs it's easy; if ~/.emacs doesn't exist, then ~/.emacs.d/init.el is used as the init file. So I can have a separate Git repo in ~/.emacs.d/. With Vim, it seems .vimrc can only exist in home folder and not in ~/vimfiles (the equivalent to ~/.emacs.d). Is this the best way to put .vimrc under version control?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

最偏执的依靠 2024-10-03 19:35:42

只需将一个虚拟 .vimrc 放入 ~ 中,只需一行:

source ~/path/to/real/vimrc  

就像魅力一样

Just put a dummy .vimrc in ~ with just a single line:

source ~/path/to/real/vimrc  

Works like a charm

只有影子陪我不离不弃 2024-10-03 19:35:42

也许将您的 .vimrc 移动到 ~/.vim/ 并符号链接到 home 就可以了?

其他更加模块化的方法是将启动脚本移动到 ~/.vim/plugins/,也许在那里创建一个子目录,以及单个或多个初始化脚本:Vim 将执行 :runtime !启动时的plugin/**/*.vim

Perhaps moving your .vimrc to ~/.vim/ and symlinking to home will do?

Other, much more modular approach is to move your startup script to ~/.vim/plugins/, perhaps create a subdirectory there, and single or multiple init scripts: Vim will do a :runtime! plugin/**/*.vim when starting.

内心旳酸楚 2024-10-03 19:35:42

正如 @Progo 在他们的答案中建议的那样, ~/.vimrc 设置可以移动到 ~/.vim/plugin/00rc.vim 文件中的“插件”脚本中。

沿着这条路走下去时需要记住以下几点:

用户和插件都希望在插件之前加载 ~/.vimrc 中的设置,如 :help 中所述启动~/.vim 通常位于 'runtimepath' 的第一个,但如果用户在 ~/.vim/plugin 中有其他插件,则 .vimrc 替换必须按字典顺序排在第一位,以确保首先加载它,也许是 ~/.vim/plugin/00rc.vim

当 vim 启动过程从步骤 3“执行 Ex 命令”(其中 .vimrc 已被读取;再次参见 :helpstartup)移动到步骤 4“加载插件脚本',它运行 :runtime!插件/**/*.vim。该命令通过“runtimepath”查找与源匹配的文件,然后开始获取它们。这意味着如果 ~/.vim/plugin/00rc.vim 中的某些内容修改了 'runtimepath' 那么就已经太晚了,无法影响运行哪些插件。这种情况最常见于 pathogen ,在这种情况下,可以通过添加以下行来解决~/.vim/plugin/00rc.vim 的结尾:

" Since this "vimrc" is really run as a plugin, vim has already compiled the
" list of paths/plugins that it wil execute at startup.
" As a result, the pathogen plugins must be run manually.
runtime! bundle/*/plugin/**/*.vim
runtime! bundle/*/after/plugin/**/*.vim

最后,(再次如 :helpstartup 中所述),如果 ~/.vimrc< /code> 文件不存在,vim 将搜索其他文件,例如 ~/.exrc,因此如果它们的内容不需要,可能需要删除它们。

As @Progo suggests in their answer, ~/.vimrc settings can be moved into a "plugin" script within a file like ~/.vim/plugin/00rc.vim.

There are a couple of things to keep in mind when going down this road:

Users and plugins alike expect that the settings in ~/.vimrc have been loaded before plugins are as described in :help startup. ~/.vim is usually first in 'runtimepath', but if the user has other plugins in ~/.vim/plugin, the .vimrc replacement must be lexicographically first to ensure it is loaded first, perhaps ~/.vim/plugin/00rc.vim.

When the vim startup process moves from step 3 'Execute Ex commands' (where .vimrc would have been read; again, see :help startup) to step 4 'Load the plugin scripts', it runs :runtime! plugin/**/*.vim. This command looks through 'runtimepath' for matching files to source and then starts sourcing them. This means that if something in ~/.vim/plugin/00rc.vim modifies 'runtimepath' then it will have been too late to affect which plugins are run. This occurs most commonly with pathogen and in that case it can be worked around by adding the following lines to the end of ~/.vim/plugin/00rc.vim:

" Since this "vimrc" is really run as a plugin, vim has already compiled the
" list of paths/plugins that it wil execute at startup.
" As a result, the pathogen plugins must be run manually.
runtime! bundle/*/plugin/**/*.vim
runtime! bundle/*/after/plugin/**/*.vim

Finally, (again as explained in :help startup), if a ~/.vimrc file isn't present, vim will search for other files like ~/.exrc so it may be necessary to remove them if their contents are unwanted.

浪漫之都 2024-10-03 19:35:42

向该过程添加一个步骤,但我只有一个 bash 脚本 deploy.sh 在我的 vim 设置中。

#!/bin/bash

if [ -f ~/.vimrc ] && [ ! -L ~/.vimrc ]
then
    echo "Backing up existing ~/.vimrc to ~/.vimrc.bak"
    mv ~/.vimrc ~/.vimrc.bak
fi
if [ -L ~/.vimrc ]
then
    echo "Already have ~/.vimrc symlink, we're good"
else
    echo "Creating symlink ~/.vimrc, which points to ~/.vim/vimrc"
    ln -s ~/.vim/vimrc ~/.vimrc
fi

git submodule init
git submodule update

Adds a step to the process, but I just have a bash script deploy.sh in my vim settings.

#!/bin/bash

if [ -f ~/.vimrc ] && [ ! -L ~/.vimrc ]
then
    echo "Backing up existing ~/.vimrc to ~/.vimrc.bak"
    mv ~/.vimrc ~/.vimrc.bak
fi
if [ -L ~/.vimrc ]
then
    echo "Already have ~/.vimrc symlink, we're good"
else
    echo "Creating symlink ~/.vimrc, which points to ~/.vim/vimrc"
    ln -s ~/.vim/vimrc ~/.vimrc
fi

git submodule init
git submodule update
全部不再 2024-10-03 19:35:42

您可以在版本控制中保留备份,并在需要时将其部署(即移动)到您的主目录。您可以编写一个简单的脚本来管理所有这些处理,因此至少透明地来回移动它看起来不会像很多烦人的工作。

You could just keep a backup in version control and deploy it (i.e. move it) to your home directory when you need it. You could write an easy script to manage all this handling so at least transparently it won't seem like a lot of annoying work to move it back and forth.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文