├── plugin └── minPlug.vim └── README.md /plugin/minPlug.vim: -------------------------------------------------------------------------------- 1 | " minPlug 2 | " Maintainer: Jorengarenar 3 | " License: MIT 4 | 5 | if exists('g:loaded_minPlug') | finish | endif 6 | let s:cpo_save = &cpo | set cpo&vim 7 | 8 | let s:plugins = {} 9 | 10 | fu! s:install(b) abort 11 | let packDir = substitute(&packpath, ",.*", "", "")."/pack/plugins" 12 | let override = a:b ? "(git reset --hard HEAD && git clean -f -d); " : "" 13 | sil! call mkdir(packDir."/opt", 'p') 14 | let l:plugins = s:plugins 15 | if get(g:, "minPlug_updateSelf", 1) | let l:plugins["Jorengarenar/minPlug"] = "master" | endif 16 | for [plugin, branch] in items(l:plugins) 17 | if get(g:, "minPlug_echo", 0) | echo plugin | endif 18 | let name = substitute(plugin, ".*\/", "", "") 19 | let [ dir, url ] = [ packDir."/opt/".name, "https://github.com/".plugin ] 20 | call system("git clone --recurse --depth=1 -b ".branch." --single-branch ".url 21 | \ ." ".dir." 2> /dev/null || (cd ".dir." ; ".override."git pull)") 22 | exe "pa ".name 23 | endfor 24 | sil! helpt ALL 25 | for f in get(g:, "minPlug_singleFiles", []) 26 | let dir = exists("f[2]") ? f[2] : packDir."/start/singleFiles" 27 | if get(g:, "minPlug_echo", 0) | echo "file: "dir."/".f[0] | endif 28 | call system("curl --create-dirs -o ".dir."/".f[0]." -L ".f[1]) 29 | endfor 30 | ec "minPlug: DONE" 31 | endf 32 | 33 | fu! s:minPlug(b, plugin, ...) abort 34 | let s:plugins[a:plugin] = get(a:, 1, "master") 35 | if !a:b 36 | exe "sil! pa".get(g:, "minPlug_paBang", "!") substitute(a:plugin, ".*\/", "", "") 37 | endif 38 | endf 39 | 40 | com! -bang -bar MinPlugInstall call install(0) 41 | com! -bang -bar -nargs=+ MinPlug call minPlug(0, ) 42 | 43 | let g:loaded_minPlug = 1 44 | let &cpo = s:cpo_save | unlet s:cpo_save 45 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # minPlug 2 | 3 | Its function is simple: _download, update and enable using `:packadd!`_ 4 | 5 | It's limited only to GitHub repositories 6 | 7 | Best utlized with, nomen omen, minimal list of plugins 8 | 9 | 10 | <PACKDIR> in this README is a placeholder for 11 | substitute(&packpath, ",.*", "", "")."/pack/plugins" 12 | which by default equals to ~/.vim/pack/plugins. 13 | 14 | 15 | ## Installation 16 | 17 | Execute in shell: 18 | 19 | ```sh 20 | git clone https://github.com/Jorengarenar/minPlug.git /plugins/opt/minPlug/ 21 | ``` 22 | 23 | and in _vimrc_ add: 24 | 25 | ```vim 26 | packadd minPlug " initialize minPlug 27 | ``` 28 | 29 | If you want to have _minPlug_ **automatically installed**, add this to your _vimrc_: 30 | 31 | ```vim 32 | if empty(glob(substitute(&packpath, ",.*", "", "")."/pack/plugins/opt/minPlug")) " {{{ 33 | call system("git clone --depth=1 https://github.com/Jorengarenar/minPlug ". 34 | \ substitute(&packpath, ",.*", "", "")."/pack/plugins/opt/minPlug") 35 | autocmd VimEnter * silent! MinPlugInstall | echo "minPlug: INSTALLED" 36 | endif " }}} 37 | ``` 38 | 39 | ## Usage 40 | 41 | ### Add plugin 42 | 43 | After initialization of minPlug, use `MinPlug` in _vimrc_ in such fasion: 44 | 45 | ```vim 46 | MinPlug username/repo branch 47 | ``` 48 | 49 | If `branch` isn't provided, as defualt `master` will be used 50 | 51 | To disable plugin, simply comment out this line 52 | 53 | Practiacal example: `MinPlug Jorengarenar/miniSnip` 54 | 55 | ### Single files 56 | 57 | If you don't want to download whole repository just for one file (e.g. colorscheme), 58 | just add it to `g:minPlug_singleFiles` list variable in the following manner: 59 | ```vim 60 | let g:minPlug_singleFiles = [ 61 | \ [ "subdir/filename", "URL", "basedir" ], 62 | \ ] 63 | ``` 64 | 65 | `basedir` is optional and defaults to `/start/singleFiles`. 66 | 67 | File from `URL` will be saved as `filename` in `subdir` of `basedir` 68 | 69 | _That means it will be loaded even if entry was to be deleted from the list!_ 70 | 71 | Example: 72 | ```vim 73 | let g:minPlug_singleFiles = [ 74 | \ "[ colors/darkness.vim" , "https://raw.githubusercontent.com/Jorengarenar/vim-darkness/master/colors/darkness.vim" ], 75 | \ "[ ftplugin/sql-upper.vim", "https://git.io/JkQjr", "~/.vim" ], 76 | \ ] 77 | ``` 78 | 79 | _To use this feature you need to have [`curl`](https://curl.se/) installed!_ 80 | 81 | ### On-demand loading 82 | 83 | There is no on-demand loading in _minPlug_, but you can do: 84 | 85 | ```vim 86 | MinPlug! username/repo branch 87 | ``` 88 | 89 | This will only add plugin to list, so you can download it, but it won't start automatically 90 | 91 | Then you can use `autocmd` (or _ftplugin_) to load it on demand using `packadd` 92 | 93 | Example: 94 | 95 | ```vim 96 | MinPlug! Jorengarenar/fauxClip | autocmd filetype cpp packadd fauxClip 97 | ``` 98 | 99 | _**Please note, that this way is prone to bugs.**_ 100 | 101 | ### Download/update plugins 102 | 103 | ```vim 104 | :MinPlugInstall 105 | ``` 106 | 107 | ### Download/update plugins overriding local changes 108 | 109 | ```vim 110 | :MinPlugInstall! 111 | ``` 112 | 113 | ### Delete 114 | 115 | Remove `MinPlug username/repo` line from _vimrc_, then go to `/opt` and remove the directory of plugin 116 | 117 | --- 118 | 119 | ## Configuration 120 | 121 | * [`packpath`](https://vimhelp.org/options.txt.html#%27packpath%27) - plugins will be downloaded into `pack/plugins/opt` subdir of the first enrty in this option 122 | * `g:minPlug_updateSelf` - whether minPlug should update itself alongside other plugins 123 | * `g:minPlug_singleFiles` - list of files to download 124 | * `g:minPlug_echo` (default: 0) - displaying list of plugins during installation or not 125 | * `g:minPlug_paBang` (default: `!`) - if empty, `MinPlug` will load plugins with `:pa`, otherwise with `:pa!` (read [`:h packadd`](https://vimhelp.org/repeat.txt.html#:packadd)) 126 | 127 | #### Additional note 128 | 129 | If you added something to the `packpath` option, ensure that your desired destination is first in the list 130 | (use `^=`, e.g. `set packpath^=$XDG_DATA_HOME/vim`) 131 | --------------------------------------------------------------------------------