關於使用github管理vim

轉自https://github.com/Aaronlong31/articles/blob/master/manager-vim-config-and-plugin-with-github.markdown

現在幾乎所有的vim插件都能在github上找到,所以用github管理很方便。 安裝vim後所有的額外配置文件都放在$HOME/.vim下,所以只同步這個目錄即可。

初始的vim 文件和目錄結構

~/.vim/
~/.vim/vimrc
~/.vim/.gitignore
~/.vimrc

其中~/.vimrc是~/.vim/vimrc的鏈接。創建方式如下:

ln -s ~/.vim/vimrc ~/.vimrc

使用 github

在github上創建一個repository,名爲dotvim,然後在本機執行以下命令:

cd ~/.vim
git init
git remote add [email protected]:{youraccountname}/dotvim.git
git push

使用 Pathogen 管理插件

插件地址: https://github.com/tpope/vim-pathogen 安裝方法:

mkdir -p ~/.vim/autoload/ ~/vim/bundle; \
curl -Sso ~/.vim/autoload/pathogen.vim \
    https://raw.github.com/tpope/vim-pathogen/master/autoload/pathogen.vim

然後下載pathogen.vim到autoload下。 修改 ~/.vim/vimrc,添加以下內容:

call pathogen#infect()
syntax on
filetype plugin indent on

使用 vundle 安裝插件

vundle可以自動幫你到github上下載plugin到bundle目錄下。 插件地址: https://github.com/gmarik/vundle 安裝方法:

cd ~/.vim
git submodule add https://github.com/gmarik/vundle.git bundle/vundle

這裏是將vundle作爲git的submodule,這樣你的github repository中就不會直接存放vundle的文件,只是有一個vundle的鏈接。 修改 ~/.vim/vimrc,添加以下內容:

set nocompatible
filetype off
if has("unix")
    set rtp+=~/.vim/bundle/vundle/
    call vundle#rc()
else 
    set rtp+=~/vimfiles/bundle/vundle/
    call vundle#rc('$HOME/vimfiles/bundle/')
endif
Bundle 'gmarik/vund'
Bundle 'plasticbo/vim-markdown' "optional
Bundle 'AutoComplPop' "optional
filetype on

如果想安裝插件,比如vim-markdown,插件地址:https://github.com/plasticboy/vim-markdown ,只需要在vimrc中添加以下一行:

Bundle 'plasticboy/vim-markdown'

plasticboy是用戶名,如果插件用戶名是vim-scripts,則可以省略用戶名。 然後執行

vim +BundleInstall

當提示Done!時,插件就都安裝到~/.vim/bundle中了。 這裏有個問題,vundle從github上下載插件時也是通過git命令的,但它是直接clone repository,這樣你push你的.vim目錄時就會把插件也push上去了。所以要在.gitignore文件中禁止提交插件目錄bundle,但作爲submodule存在的bundle/vundle目錄還是要push的,修改.gitignore如下:

bundle/
!bundle/vundle

for windows

  1. $HOME下的vim目錄是vimfiles,所以以上的.vim都要換成vimfiles。
  2. 安裝vundle參考:https://github.com/gmarik/vundle/wiki/Vundle-for-Windows
  3. vim讀取用戶自定義的vim配置文件是$HOME.vimrc,但windows下不能創建鏈接,所以需要修改.vimrc加入以下內容:

    source $VIM\_vimrc
    source ~\vimfiles\vimrc
===============

PS:我自己沒有使用pathogen,直接用的vundle。

另外,osx登陸github的命令

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章