From e3cd9e77b5f3fc2c3363b4f7436df39421d58aca Mon Sep 17 00:00:00 2001 From: Matthias Bilger Date: Sat, 24 Jul 2021 19:30:34 +0200 Subject: [PATCH] inital commit --- README.md | 17 ++++++++++ plugin/vim-plug-config.vim | 64 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 81 insertions(+) create mode 100644 README.md create mode 100644 plugin/vim-plug-config.vim diff --git a/README.md b/README.md new file mode 100644 index 0000000..0ac9b4d --- /dev/null +++ b/README.md @@ -0,0 +1,17 @@ +# vim-plug-config + +A simple plugin which allows to manage the configuration per plugin in combination with vim.plug. +The advantage is, that it will load configs automatically if available and the plugin is loaded. Works also with lazy loaded plugins. + +## Configuration + +You have to define at lease path where configs are located. All the paths will be searched, new configs will be created in the first path. + +```vim +let g:plug_config_dirs = ['~/.nvim/pluginconfigs', '~/git/vim-plugin-configs'] +``` + +## Create or Edit + +Just call `PlugConfig ` and it will either open an existing one (first one found) or it will create one in the first directory. Autocomplete is supported, too. + diff --git a/plugin/vim-plug-config.vim b/plugin/vim-plug-config.vim new file mode 100644 index 0000000..dda3e90 --- /dev/null +++ b/plugin/vim-plug-config.vim @@ -0,0 +1,64 @@ +if exists("g:vim_plug_config") || &cp || v:version < 700 + finish +endif +let g:vim_plug_config = 1 + +function! s:get_config_path(name, create) + " uniform name, remove vim prefix + let l:pluginconfig = tolower(a:name).'.vim' + if !exists('s:config_dirs') + let s:config_dirs = get(g:, 'plug_config_dirs', [split(&rtp, ',')[0] . '/configs']) + endif + " look in paths for file, else use first one as default + for path in s:config_dirs + let l:file = glob(path.'/'.l:pluginconfig) + if filereadable(l:file) + return l:file + endif + endfor + if a:create && len(s:config_dirs) > 0 + if !isdirectory(s:config_dirs[0]) + try + call mkdir(s:config_dirs[0], 'p') + catch + return '' + endtry + endif + return s:config_dirs[0].'/'.l:pluginconfig + else + return '' + endif +endfunction + +function! s:edit_config(name) + let l:file = s:get_config_path(a:name, 1) + exe 'tabedit ' . l:file +endfunction + +function! s:load_config(name) + let l:file = s:get_config_path(a:name, 0) + if l:file != '' && filereadable(l:file) + exe 'source ' . l:file + let g:plugs_configs[a:name] = l:file + endif +endfunction + +function! s:load_all_configs() + let g:plugs_configs = {} + for plug in keys(g:plugs) + if has_key(g:plugs[plug], 'on') || has_key(g:plugs[plug], 'for') + execute 'autocmd User ' . plug . ' call s:load_config("' . plug . '")' + else + call s:load_config(plug) + endif + endfor +endfunction + +function! s:names(...) + return sort(keys(g:plugs)) +endfunction + +call s:load_all_configs() +let s:plug_names = keys(g:plugs) + +command! -nargs=1 -bar -complete=customlist,s:names PlugConfig call s:edit_config()