/
view.vim
296 lines (257 loc) · 8.38 KB
/
view.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
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
if !exists('g:env')
finish
endif
syntax enable on
set number
if g:env.is_gui
set background=light
else
set background=dark
endif
set t_Co=256
if g:plug.is_installed('solarized.vim') && $TERM_PROGRAM ==# "Apple_Terminal"
colorscheme solarized
elseif g:plug.is_installed('seoul256')
colorscheme seoul256
elseif g:plug.is_installed('hybrid')
colorscheme hybrid
endif
if g:env.is_gui
set background=dark
if g:plug.is_installed('seoul256')
colorscheme seoul256
endif
endif
" StatusLine {{{1
set laststatus=2
highlight BlackWhite ctermfg=black ctermbg=white cterm=none guifg=black guibg=white gui=none
highlight WhiteBlack ctermfg=white ctermbg=black cterm=none guifg=white guibg=black gui=none
function! MakeStatusLine()
let line = ''
let line .= '[%n] '
let line .= '%f'
let line .= ' %m'
let line .= '%<'
let line .= '%='
let line .= '%#BlackWhite#'
let line .= '%y'
let line .= "[%{(&fenc!=#''?&fenc:&enc).(&bomb?'(BOM)':'')}:"
let line .= "%{&ff.(&bin?'(BIN'.(&eol?'':'-noeol').')':'')}]"
let line .= '%r'
let line .= '%h'
let line .= '%w'
let line .= ' %l/%LL %2vC'
let line .= ' %3p%%'
if g:env.vimrc.statusline_manually == g:true
return line
else
return ''
endif
endfunction
function! MakeBigStatusLine()
if g:env.vimrc.statusline_manually == g:true
set statusline=
set statusline+=%#BlackWhite#
set statusline+=[%n]:
if filereadable(expand('%'))
set statusline+=%{GetBufname(bufnr('%'),'s')}
else
set statusline+=%F
endif
set statusline+=\ %m
set statusline+=%#StatusLine#
set statusline+=%=
set statusline+=%#BlackWhite#
if exists('*TrailingSpaceWarning')
"set statusline+=%{TrailingSpaceWarning()}
endif
set statusline+=%y%{'['.(&fenc!=''?&fenc:&enc).':'.&ff.']'}
set statusline+=%r
set statusline+=%h
set statusline+=%w
if exists('*GetFileSize')
set statusline+=[%{GetFileSize()}]
endif
if exists('*GetCharacterCode')
set statusline+=[%{GetCharacterCode()}]
endif
set statusline+=\ %4l/%4LL,%3cC\ %3p%%
if exists('*WordCount')
set statusline+=\ [WC=%{WordCount()}]
endif
if exists('*GetDate')
set statusline+=\ (%{GetDate()})
endif
endif
endfunction
if !g:plug.is_installed('lightline.vim')
call MakeBigStatusLine()
if g:env.vimrc.statusline_manually == g:true
" Refresh Manually StatusLine
augroup automatically-statusline
autocmd!
autocmd BufEnter * call MakeBigStatusLine()
augroup END
endif
augroup minimal-statusline
autocmd!
autocmd WinEnter,CursorMoved * if winwidth(0) < &columns | set statusline=%!MakeStatusLine() | endif
augroup END
endif
" Tabpages {{{1
set showtabline=2
set tabline=%!MakeTabLine()
function! s:tabpage_label(n) "{{{3
let n = a:n
let bufnrs = tabpagebuflist(n)
let curbufnr = bufnrs[tabpagewinnr(n) - 1]
let hi = n == tabpagenr() ? 'TabLineSel' : 'TabLine'
let label = ''
let no = len(bufnrs)
if no == 1
let no = ''
endif
let mod = len(filter(bufnrs, 'getbufvar(v:val, "&modified")')) ? '+' : ''
let sp = (no . mod) ==# '' ? '' : ' '
let fname = GetBufname(curbufnr, 's')
if no !=# ''
let label .= '%#' . hi . 'Number#' . no
endif
let label .= '%#' . hi . '#'
let label .= fname . sp . mod
return '%' . a:n . 'T' . label . '%T%#TabLineFill#'
endfunction
function! MakeTabLine() "{{{3
let titles = map(range(1, tabpagenr('$')), 's:tabpage_label(v:val)')
let sep = ' | '
let tabs = join(titles, sep) . sep . '%#TabLineFill#%T'
"hi TabLineFill ctermfg=white
let info = '%#TabLineFill#'
let info .= fnamemodify(getcwd(), ':~') . ' '
return tabs . '%=' . info
endfunction
function! GuiTabLabel() "{{{3
let label = ''
let bufnrlist = tabpagebuflist(v:lnum)
" Append the tab number
"let label .= v:lnum.': '
" Append the buffer name
let name = bufname(bufnrlist[tabpagewinnr(v:lnum) - 1])
if name == ''
" give a name to no-name documents
if &buftype=='quickfix'
let name = '[Quickfix List]'
else
let name = '[No Name]'
endif
else
" get only the file name
let name = fnamemodify(name,":t")
endif
"let label .= name
let label .= GetBufname('%', 't')
" Append the number of windows in the tab page
let wincount = tabpagewinnr(v:lnum, '$')
" Add '+' if one of the buffers in the tab page is modified
for bufnr in l:bufnrlist
if getbufvar(bufnr, "&modified")
let l:label .= ' +'
break
endif
endfor
let wincount = wincount == 1 ? '' : wincount . ' '
""return label . ' [' . wincount . ']'
return wincount . label
endfunction "}}}
" Emphasize statusline in the insert mode {{{1
if !g:plug.is_installed('lightline.vim')
augroup colorize-statusline-insert
autocmd!
autocmd InsertEnter * call s:colorize_statusline_insert('Enter')
autocmd InsertLeave * call s:colorize_statusline_insert('Leave')
augroup END
function! ReverseHighlight(hi)
let hl = a:hi
let hl = substitute(hl, 'fg', 'swp', 'g')
let hl = substitute(hl, 'bg', 'fg', 'g')
let hl = substitute(hl, 'swp', 'bg', 'g')
return hl
endfunction
function! GetHighlight(hi)
redir => hl
silent execute 'highlight ' . a:hi
redir END
return substitute(hl, '.*xxx ', '', '')
endfunction
let s:hi_insert = 'highlight StatusLine ' . ReverseHighlight(GetHighlight('ModeMsg'))
let s:slhlcmd = ''
function! s:colorize_statusline_insert(mode)
if a:mode == 'Enter'
let s:slhlcmd = 'highlight StatusLine ' . GetHighlight('StatusLine')
silent execute s:hi_insert
elseif a:mode == 'Leave'
highlight clear StatusLine
silent execute s:slhlcmd
endif
endfunction
endif
" Cursor line/column {{{1
set cursorline
augroup auto-cursorcolumn-appear
autocmd!
autocmd CursorMoved,CursorMovedI * call s:auto_cursorcolumn('CursorMoved')
autocmd CursorHold,CursorHoldI * call s:auto_cursorcolumn('CursorHold')
autocmd BufEnter * call s:auto_cursorcolumn('WinEnter')
autocmd BufLeave * call s:auto_cursorcolumn('WinLeave')
let s:cursorcolumn_lock = 0
function! s:auto_cursorcolumn(event)
if a:event ==# 'WinEnter'
setlocal cursorcolumn
let s:cursorcolumn_lock = 2
elseif a:event ==# 'WinLeave'
setlocal nocursorcolumn
elseif a:event ==# 'CursorMoved'
setlocal nocursorcolumn
if s:cursorcolumn_lock
if 1 < s:cursorcolumn_lock
let s:cursorcolumn_lock = 1
else
setlocal nocursorcolumn
let s:cursorcolumn_lock = 0
endif
endif
elseif a:event ==# 'CursorHold'
setlocal cursorcolumn
let s:cursorcolumn_lock = 1
endif
endfunction
augroup END
augroup multi-window-toggle-cursor "{{{1
autocmd!
autocmd WinEnter * setlocal cursorline
autocmd WinLeave * setlocal nocursorline nocursorcolumn
augroup END
augroup cursor-highlight-emphasis "{{{1
autocmd!
autocmd CursorMoved,CursorMovedI,WinLeave * hi! link CursorLine CursorLine | hi! link CursorColumn CursorColumn
autocmd CursorHold,CursorHoldI * hi! link CursorLine Visual | hi! link CursorColumn Visual
augroup END
" ZEN-KAKU
" Display zenkaku-space {{{1
augroup hilight-idegraphic-space
autocmd!
"autocmd VimEnter,ColorScheme * highlight IdeographicSpace term=underline ctermbg=DarkGreen guibg=DarkGreen
"autocmd WinEnter * match IdeographicSpace / /
autocmd VimEnter,ColorScheme * call <SID>hl_trailing_spaces()
autocmd VimEnter,ColorScheme * call <SID>hl_zenkaku_space()
augroup END
function! s:hl_trailing_spaces()
highlight! link TrailingSpaces Error
syntax match TrailingSpaces containedin=ALL /\s\+$/
endfunction
function! s:hl_zenkaku_space()
highlight! link ZenkakuSpace Error
syntax match ZenkakuSpace containedin=ALL / /
endfunction
" __END__ {{{1
" vim:fdm=marker expandtab fdc=3: