我有一个符号链接,它将我的 .vimrc 指向我的仓库中的那个。
Vim 加载得很好,但我不能让它在它被改变时自动获取。
我有典型的:
if has("autocmd")
autocmd! BufWritePost .vimrc source $MYVIMRC
endif
如果 vimrc 没有符号链接,则可以使用。
我有一个符号链接,它将我的 .vimrc 指向我的仓库中的那个。
Vim 加载得很好,但我不能让它在它被改变时自动获取。
我有典型的:
if has("autocmd")
autocmd! BufWritePost .vimrc source $MYVIMRC
endif
如果 vimrc 没有符号链接,则可以使用。
我有一个类似的设置,~/.vimrc
它只是一个指向 git 存储库的符号链接。以下自动命令适用于我:
autocmd! bufwritepost .vimrc source %
我一般不喜欢符号链接,Vim 也不喜欢它们。
我使用的布局可能与您的相似:
~/.vimrc
~/.vim/vimrc
有一个很大的区别:~/.vimrc
是一个真正的文件,而不是一个符号链接,它只包含一行:
runtime vimrc
执行我的真实~/.vim/vimrc
。因为它是一个 Vim 命令并且它不使用文件路径,所以该行在每个系统上都可以相同。
因为$MYVIMRC
指向一个真实的文件,所以:so $MYVIMRC
总是有效的。
我解决了这个问题,我的所有配置都保存在 dotfiles 文件夹 https://github.com/lis2/dotfiles
然后我有一个小而简单的 ruby 脚本,当我在配置中更改某些内容时我会运行它
#!/usr/bin/env ruby
require "fileutils"
config_hash = { "tmux.conf" => ".tmux.conf", "vimrc" => ".vimrc", "vim" => ".vim", "gitconfig" => ".gitconfig", "gitignore" => ".gitignore"}
config_hash.each do |k,v|
FileUtils.rm_rf(File.dirname(__FILE__) + "/../#{v}")
FileUtils.ln_s(File.dirname(__FILE__) + "/#{k}", File.dirname(__FILE__) + "/../#{v}")
end
我建议您构建相同的配置。在所有计算机(私人/工作)上,我只需克隆我的存储库,运行 symlink.rb,我的简单环境就可以工作了。
干杯!
我有 .vimrc 和 .gvimrc 符号链接到一个 git repo,就像你描述的那样。我正在运行 MacVim macOS。
我找到了progressively-slower-reloading-time-of-vimrc这个问题的一个很好的答案。
我对其进行了一些修改,以便在 vimrc 和 gvimrc 中的任何一个发生更改时重新加载它们。我已经使用它几个月了,没有任何问题。
这里是。你只需要这个并且只需要在 .vimrc 中。您不必向 .gvimrc 添加任何内容。
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Autoreload vimrc
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
augroup configsGroup
autocmd!
" Make changes effective after saving .vimrc. Beware that autocommands are
" duplicated if .vimrc gets sourced again, unless they are wrapped in an
" augroup and the autocommands are cleared first using 'autocmd!'
autocmd! bufwritepost *\<vimrc\> call OnSavingConfigs()
autocmd! bufwritepost *\<gvimrc\> call OnSavingConfigs()
augroup END
" Avoid infinite loops
if !exists("*OnSavingConfigs")
function! OnSavingConfigs()
" Clear previous mappings, they don't go away automatically when
" sourcing vimrc.
mapclear
source $MYGVIMRC
source $MYVIMRC
redraw
echo "Reloaded " . $MYVIMRC . " and " . $MYGVIMRC . "."
endfunction
endif