-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
355 lines (313 loc) · 9.7 KB
/
Copy pathvimrc
File metadata and controls
355 lines (313 loc) · 9.7 KB
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
set encoding=utf8
scriptencoding utf-8
if !1 | finish | endif
let s:RC = {'_': {}}
function! s:RC._SetEnv() abort
if !has('vim_starting') | return | endif
let g:skip_defaults_vim = 1
let $MYVIMFILES = globpath('~', self.IsWindows ? 'vimfiles' : '.vim')
let $VIMPLUGDIR = expand('$MYVIMFILES/bundle/')
let $VIMCACHEDIR = expand('$MYVIMFILES/.cache')
if exists('&pyxversion')
set pyxversion=3
endif
if self.IsWindows && isdirectory(expand('$SCOOP'))
let l:scoop = expand('$SCOOP/shims/')
let $PATH = l:scoop . ';' . $PATH
endif
endfunction
function! s:RC._SetStartingVimOptions() abort
if !has('vim_starting') | return | endif
set nobomb
set fileencoding=
set fileencodings=ucs-bom,utf8,sjis,cp932,eucjp,default,latin
"set fileformat=
set fileformats=unix,dos
set helplang=en,ja
set autoread
set novisualbell noerrorbells belloff=all
set clipboard& clipboard+=unnamed
set softtabstop=-1 shiftwidth=0 tabstop=2 expandtab
endfunction
function! s:RC._SetEditVimOptions() abort
set mouse=a
set modeline
set ignorecase smartcase
if exists('&tagcase')
set tagcase=match
endif
set virtualedit=block backspace=2
set completeopt=menuone,longest,preview
set nojoinspaces
set iminsert=0 formatoptions=cqrj nolinebreak
set copyindent preserveindent
if exists('&fixendofline')
set nofixendofline
endif
set nospell
set spelllang=en_us,cjk
if exists('&spelloptions')
set spelloptions=camel
endif
endfunction
function! s:RC._SetBufFileVimOptions() abort
set isfname& isfname-== isfname-=!
set hidden
set wildignorecase wildignore& wildignore+=*/.git/*,*/node_modules/*
set tags=tags;
endfunction
function! s:RC._SetDisplayVimOptions() abort
set list listchars=tab:>\ ,trail:- ambiwidth=double fillchars=
set noshowmatch matchtime=0
set hlsearch incsearch
set whichwrap=[,],<,>
set number
set ruler
set synmaxcol=0
set noequalalways scrolloff=0 splitright splitbelow
set sidescroll=1 sidescrolloff=1
set foldopen& foldopen-=block foldopen+=jump foldlevelstart=99
set foldlevel=99 foldminlines=0 foldmethod=indent
if exists('&breakindent')
set wrap breakindent
set breakindentopt& breakindentopt+=shift:4
else
set nowrap
endif
let &g:statusline =
\ ' %{pathshorten(getcwd())} %{expand(''%'')} %m%r%w %=%{join([&fenc,&ff])} '
set showtabline=2
if exists(':sign')
set signcolumn=yes
endif
endfunction
function! s:RC._SetCmdAndTermVimOptions() abort
set showcmd laststatus=2 cmdwinheight=10 cmdheight=2
set wildmenu wildmode=longest:full
set cmdwinheight=5
if has('vim_starting')
if !has('gui_running')
let &t_SI = "\<Esc>[5 q" "SI = INSERT mode
let &t_SR = "\<Esc>[4 q" "SR = REPLACE mode
let &t_EI = "\<Esc>[1 q" "EI = NORMAL mode (ELSE)
endif
endif
endfunction
function! s:RC._SetBackupUndoVimOptions() abort
set nobackup nowritebackup noswapfile
set history=100 viminfo-=!
let &viminfofile = expand('$MYVIMFILES/.viminfo')
if has('persistent_undo')
if !has('nvim')
let l:undodir = expand('$VIMCACHEDIR/undo/vim')
else
let l:undodir = expand('$VIMCACHEDIR/undo/nvim')
endif
if !isdirectory(l:undodir)
call mkdir(expand(l:undodir), 'p')
endif
set undofile
let &undodir = l:undodir
let &wildignore .= ',' . &undodir
endif
endfunction
function! s:RC._DefineGlobalVariables() abort
call s:SourceIfExists('$MYVIMFILES/globalvar.vim')
endfunction
function! s:RC._DefineLocalFunctions() abort
function! s:SID(...)
let l:id = matchstr(string(function('s:SID')), '\C\v\<SNR\>\d+_')
return a:0 < 1 ? l:id : l:id . a:1
endfunction
function! s:VimEnter() abort
if &filetype !=# ''
execute 'doautocmd filetype' &filetype
endif
endfunction
function! s:Splitn(str) abort
return split(a:str, '\v\r\n|\n|\r')
endfunction
function! s:WinSplit(cmd, name) abort
let l:wincmd = (winwidth(0) * 1.0 / winheight(0) <= 4.0 ? '' : 'vert ') . a:cmd
if empty(a:name)
execute l:wincmd
else
execute printf('%s %s', a:cmd, fnameescape(a:name))
endif
endfunction
function! s:IMode(...) abort
if pumvisible()
return get(a:000, 0, '')
elseif &l:omnifunc !=# ''
return "\<C-x>\<C-o>"
elseif !empty(tagfiles())
return "\<C-x>\<C-]>"
endif
return "\<C-p>"
endfunction
function! s:ScratchWindowWithName(name, args) abort
call s:WinSplit('new', a:name)
setlocal buftype=nofile bufhidden=wipe noswapfile
if len(a:args)
let l:arg = a:args[0]
if type(l:arg) is type('')
call append(line('$') - 1, s:Splitn(l:arg))
elseif type(l:arg) is type([])
call append(line('$') - 1, l:arg)
endif
endif
keepjumps normal! gg
nnoremap <buffer><silent><C-l> :<C-u>%d _ <Bar>redraw<CR>
endfunction
function! s:ScratchWindow(...) abort
call s:ScratchWindowWithName('', a:000)
endfunction
function! s:IncludeExpr(fname) abort
let l:suff = &l:suffixesadd
let l:file = fnamemodify(a:fname, ':e') ==# '' ? a:fname . suff : a:fname
let l:base = join(add(split(&l:path, ','), get(b:, 'base_path', '')), ',')
let l:ret = s:Splitn(globpath(l:base, l:file, 0))
if len(l:ret) == 0
let l:ret = glob('./**/' . l:file)
else
let l:ret += [l:file]
endif
return filereadable(l:ret[0]) ? l:ret[0] : v:fname
endfunction
function! s:GetFileFromUrl(url, file) abort
if executable('powershell') || executable('pwsh')
let l:powershell = executable('pwsh') ? 'pwsh' : 'powershell'
let l:powershell .= ' -NoLog -NoProfile -ExecutionPolicy RemoteSigned -Command '
let l:command = '(New-Object System.Net.WebClient).DownloadFile(''%s'', ''%s'')'
call system(l:powershell . shellescape(printf(l:command, a:url, a:file)))
elseif executable('curl')
let l:command = 'curl -fLo %s %s'
call system(printf(l:command, shellescape(a:file), a:url))
endif
endfunction
function! s:SourceIfExists(path) abort
let l:filepath = expand(a:path)
if filereadable(l:filepath)
source `=l:filepath`
return 1
endif
return 0
endfunction
function! s:GetSelectText() abort
let l:save = @@
silent normal! gvy
let [l:ret, @@] = [@@, l:save]
return l:ret
endfunction
function! s:IsInstalled(dirname) abort
if exists('g:plugs')
return has_key(g:plugs, a:dirname) || has_key(g:plugs, a:dirname . '.vim')
endif
return &runtimepath =~# '\v[\\/]' . a:dirname . ',?'
endfunction
function! s:FileTypeAutoCommand() abort
let l:filetype = expand('<amatch>')
setlocal formatoptions-=o
setlocal smartindent
setlocal complete-=i complete-=t
if &l:path ==# ''
setlocal path<
endif
if filereadable(expand('$MYVIMFILES/dict/' . l:filetype . '.txt'))
let &l:dict = glob('$MYVIMFILES/dict/' . l:filetype . '.txt')
let &l:complete .= ',k' . &l:dict
endif
endfunction
function s:DelEnv(env_name) abort
if !exists('$' . a:env_name)
return
endif
if has('perl')
silent! execute "perl delete $ENV{'" . a:env_name . "'}"
elseif has('ruby')
silent! execute "ruby ENV.delete('" . a:env_name . "')"
else
silent! execute 'unlet! $' . a:env_name
endif
endfunction
call extend(self._, {
\ 'SID': function('s:SID'),
\ 'IMode': function('s:IMode'),
\ 'ScratchWindowWithName': function('s:ScratchWindowWithName'),
\ 'ScratchWindow': function('s:ScratchWindow'),
\ 'IncludeExpr': function('s:IncludeExpr'),
\ 'GetFileFromUrl': function('s:GetFileFromUrl'),
\ 'SourceIfExists': function('s:SourceIfExists'),
\ 'GetSelectText': function('s:GetSelectText'),
\ 'IsInstalled': function('s:IsInstalled'),
\ 'DelEnv': function('s:DelEnv'),
\})
endfunction
function! s:RC._InitAutogroup() abort
augroup Vimrc
autocmd!
autocmd bufnewfile *.{bat,cmd}
\ setlocal fileencoding=cp932 fileformat=dos
autocmd bufnewfile,bufreadpost *.jade
\ setlocal filetype=pug
autocmd filetype *
\ call s:FileTypeAutoCommand()
autocmd vimenter *
\ call s:VimEnter()
augroup END
endfunction
function! s:RC.SetVimOptions() abort
call self._SetStartingVimOptions()
call self._SetEditVimOptions()
call self._SetBufFileVimOptions()
call self._SetDisplayVimOptions()
call self._SetCmdAndTermVimOptions()
call self._SetBackupUndoVimOptions()
endfunction
function! s:RC.SetPluginEnable() abort
if !has('vim_starting') | return | endif
call s:SourceIfExists('$MYVIMFILES/download.vim')
endfunction
function! s:RC.LoadPluginConfig() abort
call s:SourceIfExists('$MYVIMFILES/config/plugin.vim')
for l:config in split(globpath($MYVIMFILES, 'config/*.vim', 1), "\n")
if s:IsInstalled(matchstr(l:config, '\vconfig[\/]\zs[^\/]+\ze\.vim'))
source `=l:config`
endif
endfor
endfunction
function! s:RC.LoadKeyMap() abort
call s:SourceIfExists('$MYVIMFILES/mapping.vim')
endfunction
function! s:RC.LoadMenu() abort
call s:SourceIfExists('$MYVIMFILES/menu.vim')
endfunction
function! s:RC.LoadCommand() abort
call s:SourceIfExists('$MYVIMFILES/command.vim')
endfunction
function! s:RC.Init() abort
let self.IsWindows = has('win32')
let self.IsUnix = has('unix')
call self._DefineLocalFunctions()
call self._SetEnv()
call s:SourceIfExists('$MYVIMFILES/localconf.vim')
call self._DefineGlobalVariables()
call self._InitAutogroup()
call self.SetVimOptions()
return self
endfunction
function! s:RC.LoadLocalrc() abort
call s:SourceIfExists('$MYVIMFILES/localrc.vim')
endfunction
function! s:RC.Startup() abort
let g:VIMRC = s:RC.Init()
call s:RC.SetPluginEnable()
call s:RC.LoadPluginConfig()
syntax enable
call s:RC.LoadCommand()
call s:RC.LoadKeyMap()
call s:RC.LoadMenu()
call s:RC.LoadLocalrc()
endfunction
call s:RC.Startup()
set secure