mirror of
https://github.com/m42e/vim-plug-config.git
synced 2025-12-12 11:21:13 +00:00
inital commit
This commit is contained in:
17
README.md
Normal file
17
README.md
Normal file
@@ -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 <pluginname>` and it will either open an existing one (first one found) or it will create one in the first directory. Autocomplete is supported, too.
|
||||||
|
|
||||||
64
plugin/vim-plug-config.vim
Normal file
64
plugin/vim-plug-config.vim
Normal file
@@ -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(<f-args>)
|
||||||
Reference in New Issue
Block a user