From 7f79e9eadd8e1bca62d16d2d67d8aab8d3dce0fe Mon Sep 17 00:00:00 2001 From: wsdjeg Date: Tue, 10 Jan 2017 00:27:52 +0800 Subject: [PATCH] Improve custom config loadding --- README.md | 6 ++++-- autoload/SpaceVim.vim | 39 +++++++++++++++++++++++++++-------- autoload/SpaceVim/plugins.vim | 25 +++++++++++----------- doc/SpaceVim.txt | 7 +++++++ 4 files changed, 53 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index f02c88609..c339a34aa 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,6 @@ ga('create', 'UA-89745542-1', 'auto'); ga('send', 'pageview'); - ### SpaceVim + [![Build Status](https://travis-ci.org/SpaceVim/SpaceVim.svg?branch=dev)](https://travis-ci.org/SpaceVim/SpaceVim) ![Version 0.1.0-dev](https://img.shields.io/badge/version-0.1.0--dev-yellow.svg?style=flat-square) [![MIT License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE) @@ -110,7 +110,9 @@ git clone https://github.com/SpaceVim/SpaceVim.git AppData\Local\nvim #### Modular configuration -SpaceVim will load custom configuration from `~/.local.vim` and `.local.vim` in current directory. +- SpaceVim will load custom configuration from `~/.local.vim` and `.local.vim` in current directory. +- SpaceVim support `~/.SpaceVim.d/init.vim` and `./SpaceVim.d/init.vim`. + here is an example: diff --git a/autoload/SpaceVim.vim b/autoload/SpaceVim.vim index e31d0b245..dad5c9ef6 100644 --- a/autoload/SpaceVim.vim +++ b/autoload/SpaceVim.vim @@ -120,6 +120,13 @@ let g:spacevim_disabled_plugins = [] " < let g:spacevim_custom_plugins = [] "" +" SpaceVim will load global config after local config if set to 1. by default +" it is 0, if you has local config, the global config will not be loaded. +" > +" let g:spacevim_force_global_config = 1 +" < +let g:spacevim_force_global_config = 0 +"" " enable/disable SpaceVim with powerline symbols. let g:spacevim_enable_powerline_fonts = 1 "" @@ -144,20 +151,34 @@ let g:spacevim_wildignore = '*/tmp/*,*.so,*.swp,*.zip,*.class,tags, \.git,.svn,.hg,.DS_Store' function! SpaceVim#loadCustomConfig() abort - let custom_confs = SpaceVim#util#globpath(getcwd(), '.local.vim') - let custom_glob_conf = expand('~/.local.vim') - if filereadable(custom_glob_conf) - exe 'source ' . custom_glob_conf + let custom_confs_old = SpaceVim#util#globpath(getcwd(), '.local.vim') + let custom_confs = SpaceVim#util#globpath(getcwd(), '.SpaceVim.d/init.vim') + let custom_glob_conf_old = expand('~/.local.vim') + let custom_glob_conf = expand('~/.SpaceVim.d/init.vim') + " the old value will be remove + if filereadable(custom_glob_conf_old) + exe 'source ' . custom_glob_conf_old endif - if isdirectory(expand('~/.SpaceVim.d/')) - set runtimepath^=~/.SpaceVim.d + if !empty(custom_confs_old) + exe 'source ' . custom_confs_old[0] endif if !empty(custom_confs) exe 'source ' . custom_confs[0] - endif - if isdirectory('.SpaceVim.d') - exe 'set rtp ^=' . expand('.SpaceVim.d') + if isdirectory('.SpaceVim.d') + exe 'set rtp ^=' . expand('.SpaceVim.d') + endif + if filereadable(custom_glob_conf) && g:spacevim_force_global_config + exe 'source ' . custom_glob_conf + if isdirectory(expand('~/.SpaceVim.d/')) + set runtimepath^=~/.SpaceVim.d + endif + endif + elseif filereadable(custom_glob_conf) + exe 'source ' . custom_glob_conf + if isdirectory(expand('~/.SpaceVim.d/')) + set runtimepath^=~/.SpaceVim.d + endif endif endfunction diff --git a/autoload/SpaceVim/plugins.vim b/autoload/SpaceVim/plugins.vim index b0a05d9b5..734b9de36 100644 --- a/autoload/SpaceVim/plugins.vim +++ b/autoload/SpaceVim/plugins.vim @@ -233,10 +233,13 @@ let s:plugins.ctrlp = [ if !has('nvim') call add(s:plugins.ctrlp, ['wsdjeg/ctrlp-unity3d-docs', { 'on_cmd' : 'CtrlPUnity3DDocs'}]) endif -function! SpaceVim#plugins#get(...) abort - -endfunction - +let s:plugins.github = [ + \ ['junegunn/vim-github-dashboard', { 'on_cmd':['GHD','GHA','GHActivity','GHDashboard']}], + \ ] +let s:plugins.vim = [ + \ ['Shougo/vimshell.vim', { 'on_cmd':['VimShell']}], + \ ['mattn/vim-terminal', { 'on_cmd':['Terminal']}], + \ ] function! SpaceVim#plugins#load() abort if zvim#plug#enable_plug() call zvim#plug#begin(g:spacevim_plugin_bundle_dir) @@ -244,14 +247,6 @@ function! SpaceVim#plugins#load() abort call s:load_plugins() - if count(g:spacevim_plugin_groups, 'github') "{{{ - call zvim#plug#add('junegunn/vim-github-dashboard', { 'on_cmd':['GHD','GHA','GHActivity','GHDashboard']}) - endif - - if count(g:spacevim_plugin_groups, 'vim') "{{{ - call zvim#plug#add('Shougo/vimshell.vim', { 'on_cmd':['VimShell']}) - call zvim#plug#add('mattn/vim-terminal', { 'on_cmd':['Terminal']}) - endif call zvim#plug#add('tpope/vim-scriptease') call zvim#plug#add('tpope/vim-fugitive') call zvim#plug#add('cohama/agit.vim', { 'on_cmd':['Agit','AgitFile']}) @@ -337,7 +332,7 @@ function! SpaceVim#plugins#load() abort call zvim#plug#add('scrooloose/nerdtree',{'on_cmd':'NERDTreeToggle'}) if zvim#plug#tap('nerdtree') call zvim#plug#defind_hooks('nerdtree') - function! OpenOrCloseNERDTree() + function! OpenOrCloseNERDTree() abort exec 'normal! A' endfunction noremap :NERDTreeToggle @@ -443,3 +438,7 @@ function! s:disable_plugins(plugin_list) abort endfor endfunction +function! SpaceVim#plugins#get(...) abort + +endfunction + diff --git a/doc/SpaceVim.txt b/doc/SpaceVim.txt index 8aee011d6..3f9e80612 100644 --- a/doc/SpaceVim.txt +++ b/doc/SpaceVim.txt @@ -117,6 +117,13 @@ Add custom plugins \ ] < + *g:spacevim_force_global_config* +SpaceVim will load global config after local config if set to 1. by default it +is 0, if you has local config, the global config will not be loaded. +> + let g:spacevim_force_global_config = 1 +< + *g:spacevim_enable_powerline_fonts* enable/disable SpaceVim with powerline symbols.