-
Notifications
You must be signed in to change notification settings - Fork 0
/
dein.vim
137 lines (116 loc) · 4.24 KB
/
dein.vim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
" Set main configuration directory as parent directory ~/config/nvim
let $VIM_PATH =
\ get(g:, 'etc_vim_path',
\ exists('*stdpath') ? stdpath('config') :
\ ! empty($MYVIMRC) ? fnamemodify(expand($MYVIMRC), ':h') :
\ ! empty($VIMCONFIG) ? expand($VIMCONFIG) :
\ ! empty($VIM_PATH) ? expand($VIM_PATH) :
\ fnamemodify(resolve(expand('<sfile>:p')), ':h:h')
\ )
" Set data/cache directory as $XDG_CACHE_HOME/nvim ~/.cache/nvim
if has('nvim')
let $DATA_PATH =
\ expand(($XDG_CACHE_HOME ? $XDG_CACHE_HOME : '~/.cache') . '/nvim')
else
let $DATA_PATH =
\ expand(($XDG_CACHE_HOME ? $XDG_CACHE_HOME : '~/.cache') . '/vim')
endif
" Collection of plugins list config file-paths
" ~/.config/nvim/modules/a.toml
" ~/.config/nvim/modules/b.toml ...
let s:modules_config_paths = split(globpath('$VIM_PATH/modules', '*'), '\n')
function! s:main()
if has('vim_starting')
" When using VIMINIT trick for exotic MYVIMRC locations, add path now.
if &runtimepath !~# $VIM_PATH
set runtimepath^=$VIM_PATH
endif
" Ensure data directories
for s:path in [
\ $DATA_PATH,
\ $DATA_PATH . '/undo',
\ $DATA_PATH . '/backup',
\ $DATA_PATH . '/session']
if ! isdirectory(s:path)
call mkdir(s:path, 'p')
endif
endfor
" Python interpreter settings
if has('nvim')
" Try using pyenv virtualenv called 'neovim'
let l:virtualenv = ''
if ! empty($PYENV_ROOT)
let l:virtualenv = $PYENV_ROOT . '/versions/neovim/bin/python'
endif
if empty(l:virtualenv) || ! filereadable(l:virtualenv)
" Fallback to old virtualenv location
let l:virtualenv = $DATA_PATH . '/venv/neovim3/bin/python'
endif
if filereadable(l:virtualenv)
let g:python3_host_prog = l:virtualenv
endif
elseif has('pythonx')
if has('python3')
set pyxversion=3
elseif has('python')
set pyxversion=2
endif
endif
endif
" Initializes chosen package manager
call s:use_dein()
endfunction
function! s:use_dein()
let l:cache_path = $DATA_PATH . '/dein'
if has('vim_starting')
" Use dein as a plugin manager
let g:dein#auto_recache = 1
let g:dein#install_max_processes = 12
let g:dein#install_progress_type = 'title'
let g:dein#enable_notification = 1
let g:dein#install_log_filename = $DATA_PATH . '/dein.log'
" Add dein to vim's runtimepath
if &runtimepath !~# '/dein.vim'
let s:dein_dir = l:cache_path . '/repos/github.com/Shougo/dein.vim'
" Clone dein if first-time setup
if ! isdirectory(s:dein_dir)
execute '!git clone https://github.com/Shougo/dein.vim' s:dein_dir
if v:shell_error
call s:error('dein installation has failed! is git installed?')
finish
endif
endif
execute 'set runtimepath+='.substitute(
\ fnamemodify(s:dein_dir, ':p') , '/$', '', '')
endif
endif
" Initialize dein.vim (package manager)
if dein#min#load_state(l:cache_path)
" Start propagating file paths and plugin presets
call dein#begin(l:cache_path, extend([expand('<sfile>')], s:modules_config_paths))
for l:repo_toml in s:modules_config_paths
call dein#load_toml(l:repo_toml)
endfor
call dein#end()
" Save cached state for faster startups
if ! g:dein#_is_sudo
call dein#save_state()
endif
" Update or install plugins if a change detected
if dein#check_install()
if ! has('nvim')
set nomore
endif
call dein#install()
endif
endif
filetype plugin indent on
" Only enable syntax when vim is starting
if has('vim_starting')
syntax enable
endif
" Trigger source event hooks
call dein#call_hook('source')
call dein#call_hook('post_source')
endfunction
call s:main()