forked from rafi/vim-config
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
159 lines (139 loc) · 4.19 KB
/
vimrc
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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
" .-. .-. .-. .-. .-. .-. .-.
" `._.' `._.' `._.' `._.' `._.' `._.' `._.'
"
" https://github.com/rafi/vim-config
" Runtime and Plugins
" -------------------------------------------------
if &compatible
set nocompatible
endif
" Set main configuration directory, and where cache is stored.
let $VIMPATH = fnamemodify(resolve(expand('<sfile>:p')), ':h:h')
let $VARPATH = expand(($XDG_CACHE_HOME ? $XDG_CACHE_HOME : '~/.cache').'/vim')
let g:dein#install_max_processes = 16
let g:dein#install_progress_type = 'echo'
let g:dein#enable_notification = 0
let g:dein#install_log_filename = $VARPATH.'/dein.log'
function! s:dein_check_ruby() abort
call system("ruby -e 'require \"json\"; require \"yaml\"'")
return (v:shell_error == 0) ? 1 : 0
endfunction
function! s:dein_check_yaml2json()
try
let result = system('yaml2json', "---\ntest: 1")
if v:shell_error != 0
return 0
endif
let result = json_decode(result)
return result.test
catch
endtry
return 0
endfunction
function! s:dein_load_yaml(filename) abort
if executable('yaml2json') && exists('*json_decode') &&
\ s:dein_check_yaml2json()
" Decode YAML using the CLI tool yaml2json
" See: https://github.com/koraa/large-yaml2json-json2yaml
let g:denite_plugins = json_decode(
\ system('yaml2json', readfile(a:filename)))
elseif executable('ruby') && exists('*json_decode') && s:dein_check_ruby()
let g:denite_plugins = json_decode(
\ system("ruby -e 'require \"json\"; require \"yaml\"; ".
\ "print JSON.generate YAML.load \$stdin.read'",
\ readfile(a:filename)))
else
" Fallback to use python3 and PyYAML
python3 << endpython
import vim, yaml
with open(vim.eval('a:filename'), 'r') as f:
vim.vars['denite_plugins'] = yaml.load(f.read())
endpython
endif
for plugin in g:denite_plugins
call dein#add(plugin['repo'], extend(plugin, {}, 'keep'))
endfor
unlet g:denite_plugins
endfunction
function! s:source_file(path, ...) abort
let use_global = get(a:000, 0, ! has('vim_starting'))
let abspath = resolve(expand($VIMPATH.'/config/'.a:path))
if ! use_global
execute 'source' fnameescape(abspath)
return
endif
let content = map(readfile(abspath),
\ "substitute(v:val, '^\\W*\\zsset\\ze\\W', 'setglobal', '')")
let tempfile = tempname()
try
call writefile(content, tempfile)
execute printf('source %s', fnameescape(tempfile))
finally
if filereadable(tempfile)
call delete(tempfile)
endif
endtry
endfunction
" Set augroup
augroup MyAutoCmd
autocmd!
autocmd CursorHold *? syntax sync minlines=300
augroup END
" Initialize base requirements
if has('vim_starting')
call s:source_file('init.vim')
if has('nvim')
" Neovim settings
call s:source_file('neovim.vim')
elseif ! has('gui_running') && ! has('win32') && ! has('win64')
" Linux terminal settings
call s:source_file('terminal.vim')
endif
endif
" Initialize dein.vim (package manager)
let s:path = expand('$VARPATH/dein')
let s:plugins_path = expand('$VIMPATH/config/plugins.yaml')
let s:user_plugins_path = expand('$VIMPATH/config/local.plugins.yaml')
if dein#load_state(s:path)
call dein#begin(s:path, [expand('<sfile>'), s:plugins_path])
try
call s:dein_load_yaml(s:plugins_path)
if filereadable(s:user_plugins_path)
call s:dein_load_yaml(s:user_plugins_path)
endif
catch /.*/
echoerr v:exception
echomsg 'Error loading config/plugins.yaml...'
echomsg 'Caught: ' v:exception
echoerr 'Please run: pip3 install --user PyYAML'
endtry
if isdirectory(expand('$VIMPATH/dev'))
call dein#local(expand('$VIMPATH/dev'), {'frozen': 1, 'merged': 0})
endif
call dein#end()
call dein#save_state()
if dein#check_install()
if ! has('nvim')
set nomore
endif
call dein#install()
endif
endif
call s:source_file('plugins/all.vim')
filetype plugin indent on
syntax enable
if ! has('vim_starting')
call dein#call_hook('source')
call dein#call_hook('post_source')
endif
" Loading configuration modules
call s:source_file('general.vim')
call s:source_file('filetype.vim')
call s:source_file('mappings.vim')
call s:source_file('theme.vim')
" Load user custom local settings
if filereadable(expand('$VIMPATH/config/local.vim'))
call s:source_file('local.vim')
endif
set secure
" vim: set ts=2 sw=2 tw=80 noet :