-
Notifications
You must be signed in to change notification settings - Fork 1
/
shame.vim
341 lines (282 loc) · 9.3 KB
/
shame.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
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
scriptencoding utf-8
" This file is for:
" 1. not decided where to put the code
" 2. ugly codes that need refactor
Plug 'junegunn/gv.vim'
Plug 'bluz71/vim-nightfly-guicolors'
":1 Only on: Mac OS
if system('uname') =~# 'Darwin'
set clipboard=unnamed,unnamedplus " Use the OS clipboard by default
endif
" endfold
set rulerformat=%50(%=%f\ %y%m%r%w\ %l,%c%V\ %P%)
" set linebreak " Define line break
":1 FileType: Coffeescript
function! g:CoffeeFoldText()
let l:line = getline(v:foldstart)
let l:trimmed = substitute(l:line, '^\s*\(.\{-}\)\s*$', '\1', '')
let l:leading_spaces = stridx(l:line, l:trimmed)
let l:prefix = repeat(' ', l:leading_spaces)
let l:size = strlen(l:trimmed)
let l:trimmed = strpart(l:trimmed, 4, l:size - 4)
return l:prefix . '▸ ' . l:trimmed
endfunction
autocmd vimrc FileType coffee setlocal foldmethod=marker foldmarker=#\:,endfold foldtext=g:CoffeeFoldText()
autocmd vimrc BufEnter *.js.coffee if &filetype == 'coffee' |nmap <F9> :w<CR>:!coffee "%" --nodejs <CR>| endif
autocmd vimrc BufEnter *.js.coffee if &filetype == 'coffee' |nmap <F5> :w<CR>:!coffee -c -b -p "%" > "%:r"<CR>| endif
autocmd vimrc BufEnter *.js.coffee if &filetype == 'coffee' |nmap <C-s> :w<CR>:!coffee -c -b -p "%" > "%:r"<CR>| endif
autocmd vimrc BufEnter *.js.coffee if &filetype == 'coffee' |imap <C-s> <ESC>:w<CR>:!coffee -c -b -p "%" > "%:r"<CR>| endif
":1 FileType: Java
autocmd vimrc FileType java setlocal foldmethod=marker foldmarker=BEGIN\ CUT\ HERE,END\ CUT\ HERE
autocmd vimrc BufEnter * if &filetype == 'java' |nmap <F5> :w<CR>:!javac "%"; java "%:t:r"; rm -f "%:r.class" "%:rHarness.class"<CR>| endif
autocmd vimrc BufEnter * if &filetype == 'java' |nmap <S-F5> :w<CR>:!javac "%"; java "%:t:r" < input.txt; rm -f "%:r.class" "%:rHarness.class"<CR>| endif
" use tab. tabsize = 2
autocmd vimrc FileType java
\ setlocal tabstop=2 softtabstop=2 shiftwidth=2 noexpandtab
":1 FileType: PHP
":2 PHPFoldExpr
function! g:PHPFoldExpr()
":3 Variable reset
if v:lnum == 1
let s:fold = 0 " fold level
let s:fold_1_start = ''
endif
" endfold
":3 +1 | <indent> function start
if getline(v:lnum) =~? '^\s\{4\}public function '
let s:fold = 1
let s:fold_1_start = 'public function'
return '>1'
endif
if getline(v:lnum) =~? '^\s\{4\}private function '
let s:fold = 1
let s:fold_1_start = 'private function'
return '>1'
endif
if getline(v:lnum) =~? '^\s\{4\}public static function '
let s:fold = 1
let s:fold_1_start = 'public static function'
return '>1'
endif
if getline(v:lnum) =~? '^\s\{4\}final public function '
let s:fold = 1
let s:fold_1_start = 'final public function'
return '>1'
endif
if getline(v:lnum) =~? '^\s\{4\}function '
let s:fold = 1
let s:fold_1_start = 'function'
return '>1'
endif
":3 -1 | <indent> function close (type change)
if getline(v:lnum) =~# '^\s\{4\}}'
if getline(v:lnum + 2) =~# '^\s\{4\}public function '
if s:fold_1_start !=# 'public function'
let s:fold = 0
return '<1'
endif
endif
endif
if getline(v:lnum) =~# '^\s\{4\}}'
if getline(v:lnum + 2) =~# '^\s\{4\}private function '
if s:fold_1_start !=# 'private function'
let s:fold = 0
return '<1'
endif
endif
endif
if getline(v:lnum) =~# '^\s\{4\}}'
if getline(v:lnum + 2) =~# '^\s\{4\}public static function '
if s:fold_1_start !=# 'public static function'
let s:fold = 0
return '<1'
endif
endif
endif
if getline(v:lnum) =~# '^\s\{4\}}'
if getline(v:lnum + 2) =~# '^\s\{4\}final public function '
if s:fold_1_start !=# 'final public function'
let s:fold = 0
return '<1'
endif
endif
endif
if getline(v:lnum) =~# '^\s\{4\}}'
if getline(v:lnum + 2) =~# '^\s\{4\}function '
if s:fold_1_start !=# 'function'
let s:fold = 0
return '<1'
endif
endif
endif
":3 -1 | <indent> function close (next is comment)
if getline(v:lnum) =~# '^\s\{4\}}'
if getline(v:lnum + 1) =~# ''
if getline(v:lnum + 2) =~# '//'
if s:fold ==# 1 && s:fold_1_start !=# '1_title'
let s:fold = 0
return '<1'
endif
endif
endif
endif
":3 -1 | <indent> function close (last)
if getline(v:lnum) =~# '^\s\{4\}}'
if getline(v:lnum + 1) =~# '^}'
let s:fold = 1
return '<1'
endif
endif
":3 +1 | // title
if getline(v:lnum) =~# '^\s\{4,\}// [A-Z0-9\e]'
if s:fold == 0
let s:fold_1_start = '1_title'
return '>1'
endif
endif
":3 -1 | // endfold
if getline(v:lnum) =~# '^\s\{4\}// endfold'
let s:fold = 0
return '<1'
endif
" endfold
":3 +2 | // title
if getline(v:lnum) =~# '^\s\{8,\}// [A-Z0-9\e]'
if s:fold == 0
return '>1'
endif
if s:fold == 1
return '>2'
endif
endif
":3 -2 | // endfold
if getline(v:lnum) =~# '^\s\{8,\}// endfold'
if s:fold == 1
return '<2'
endif
if s:fold == 2
return '<3'
endif
endif
" endfold
return '='
endfunction
" endfold
":2 PHPFoldText
function! g:PHPFoldText()
let l:line = getline(v:foldstart)
return l:line
let l:trimmed = substitute(l:line, '^\s*\(.\{-}\)\s*$', '\1', '')
let l:leading_spaces = stridx(l:line, l:trimmed)
let l:prefix = repeat(' ', l:leading_spaces)
let l:size = strlen(l:trimmed)
let l:trimmed = strpart(l:trimmed, 4, l:size - 4)
return l:prefix . '▸ ' . l:line
return l:prefix . '▸ ' . l:trimmed
endfunction
" endfold
autocmd vimrc FileType php setlocal foldmethod=expr foldexpr=g:PHPFoldExpr() foldtext=g:PHPFoldText()
autocmd vimrc BufEnter * if &filetype == 'php' |nmap <F5> :w<CR>:!time php "%"<CR>|endif
autocmd vimrc BufEnter * if &filetype == 'php' |nmap <F9> :w<CR>:!php -l '%'<CR>| endif
" Highlight `#Regular-word`
autocmd vimrc FileType php syn match Comment "\#[a-zA-Z0-9_-]\+"hs=s+0,he=e+0 containedin=phpStringSingle contained
" no tab use. tab = 4 space
autocmd vimrc FileType php
\ setlocal tabstop=4 softtabstop=4 shiftwidth=4 expandtab
":1 FileType: Sass
function! g:SassFoldText()
return getline(v:foldstart)
endfunction
function! g:SassFoldExpr()
let l:line = getline(v:lnum)
":2 +1 | selector
if l:line =~# '^[^ ]' && getline(v:lnum + 1) =~# '^ '
return '>1'
endif
":2 -1 | \n\n
if l:line =~# '^$' && getline(v:lnum + 1) =~# '^$'
return '<1'
endif
":2 -1 | // endfold
if l:line =~# '^// endfold'
return '<1'
endif
" endfold
":2 +2 | ..selector
" ..x
" ....x
if l:line =~# '^ [^ ]' && getline(v:lnum + 1) =~# '^ '
return '>2'
endif
": 2 + | ..// endfold
" ..// endfold
if l:line =~# '^ // endfold'
return '<2'
endif
":2 -2 | ....(last)
" ....x
" |
" x
if l:line =~# '^ ' && getline(v:lnum + 1) =~# '^$' && getline(v:lnum + 2) =~# '^[^ ]'
return '<2'
endif
" endfold
return '='
endfunction
autocmd vimrc FileType sass setlocal foldmethod=expr foldexpr=g:SassFoldExpr() foldtext=g:SassFoldText()
autocmd vimrc FileType sass setlocal iskeyword-=#,-
autocmd vimrc FileType sass setlocal iskeyword+=$
":1 FileType: Help
autocmd vimrc FileType help nnoremap <buffer> <CR> <C-]>
autocmd vimrc FileType help nnoremap <buffer> <BS> <C-T>
" endfold
":1 Filetype detection
autocmd vimrc BufEnter *.gitignore setlocal filetype=gitconfig
autocmd vimrc BufEnter *.conf setlocal filetype=dosini
" endfold
" Identify the syntax hightlighting group used at the cursor
map <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
":1 Markdown: simple todo-list manager
function! MarkdownToggle()
let l:line = getline('.')
" GitHub task friendly todo-list
if match(l:line, '^\s*- \[ \]') == 0
let l:line = substitute(l:line, '^\(\s*\)- \[ \]s*', '\1- \[x\]', '')
elseif match(l:line, '^\s*- \[x\]') == 0
let l:line = substitute(l:line, '^\(\s*\)- \[x\]s*', '\1- \[ \]', '')
" Simple todo-list
elseif match(l:line, '^\s*- +') == 0
let l:line = substitute(l:line, '^\(\s*\)- +\s*', '\1- ✓ ', '')
elseif match(l:line, '^\(\s*\)- ✓') == 0
let l:line = substitute(l:line, '^\(\s*\)- ✓\s*', '\1- ✗ ', '')
elseif match(l:line, '^\(\s*\)- ✗') == 0
let l:line = substitute(l:line, '^\(\s*\)- ✗\s*', '\1- ', '')
elseif match(l:line, '^\s*-') == 0
let l:line = substitute(l:line, '^\(\s*\)-\s*', '\1- + ', '')
endif
call setline('.', l:line)
endfunction
nmap <C-d> :call MarkdownToggle()<CR>
vmap <C-d> :call MarkdownToggle()<CR>
autocmd vimrc FileType markdown syn match TodoLine '^\s*\-\(\n\s\+[^- ].*\)*'
autocmd vimrc FileType markdown syn match OpenLine '^\s*\- +.*\(\n\s\+[^- ].*\)*'
autocmd vimrc FileType markdown syn match DoneLine '^\s*\- ✓.*\(\n\s\+[^- ].*\)*'
autocmd vimrc FileType markdown syn match SkipLine '^\s*\- ✗.*\(\n\s\+[^- ].*\)*'
autocmd vimrc FileType markdown syn match DoneLine '^\s*\- \[x\].*\(\n\s\+[^- ].*\)*'
autocmd vimrc FileType markdown hi def link TodoLine Normal
autocmd vimrc FileType markdown hi def link OpenLine String
autocmd vimrc FileType markdown hi def link DoneLine htmlTagName
autocmd vimrc FileType markdown hi def link SkipLine Comment
" endfold
":1 SourcePrint
function! g:SourcePrint()
set background=light
TOhtml
w! ~/vim-source.html
bdelete!
!open ~/vim-source.html
set background=dark
endfunction
command! SourcePrint :call g:SourcePrint()