/
dotfiles.vim
144 lines (124 loc) · 4.09 KB
/
dotfiles.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
"# wtf-file-dotfiles
colorscheme vyin
"## Templates
augroup skeletons
au!
au BufNewFile *.html call AddSkeleton("skeleton.html")
au BufNewFile *.sh call AddSkeleton("skeleton.sh")
au BufNewFile *.php call AddSkeleton("skeleton.php")
au BufNewFile *.gv call AddSkeleton("skeleton.gv")
au BufNewFile *.rest call AddSkeleton("skeleton.rest")
au BufNewFile *.go call AddGoSkeleton("skeleton.go")
au BufNewFile .editorconfig call AddSkeleton("skeleton.editorconfig")
au BufNewFile phpunit.xml call AddSkeleton("phpunit.xml")
augroup END
function! AddGoSkeleton(arquivo)
let filename = expand('%:t:r')
if(filename == 'main')
call AddSkeleton("main.go")
exec "normal! 3G"
elseif(filename[-5:] == '_test')
let foldername = expand('%:p:h:t')
exec "normal! Opackage ".foldername
normal! Goimport "testing"
normal! o
else
let foldername = expand('%:p:h:t')
exec "normal! Apackage ".foldername
endif
endfunction
function! AddSkeleton(arquivo)
execute "0r ".g:dotfiles_dir."/vim/skeletons/".a:arquivo
endfunction
"## Dicionários
let g:dict_dir = g:dotfiles_dir. "/vim/dicionarios"
augroup dicionarios
au!
au BufEnter * call AddDict(&ft)
au BufEnter *test.php execute "setlocal dictionary+=".g:dict_dir."/phpunit.dict"
augroup END
function! AddDict(arquivo)
execute "setl dictionary+=".g:dict_dir."/".a:arquivo.".dict"
endfunction
"## Todolist
augroup filetype_detect
au BufEnter,BufNewFile BACKLOG,DONE setfiletype todolist
augroup END
let g:todolist_dir = "~/TODOLIST"
let g:todolist_backlog = g:todolist_dir."/BACKLOG"
let g:todolist_done = g:todolist_dir."/DONE"
nnoremap <leader>o :call TodoListMenu()<CR>
command! TodoListVGrep execute "silent noa lvimgrep /\\C\\<TODO\\>/j ".g:todolist_backlog | lli
command! TodoList call TodoListSearchStatus({'TODO':'\C\<TODO\>','WAIT':'\C\<WAIT\>'})
command! TodoListFileBacklog call <SID>OpenBacklogFile()
command! TodoListFileDone execute "e ".g:todolist_done
function! s:OpenBacklogFile()
execute "e ".g:todolist_backlog
try
silent lvimgrep /\C\<TODO\>/j %
catch
redraw
echohl WarningMsg | echo "Sem TODO" | echohl None
endtry
endfunction
function! TodoListSearchStatus(regex)
let todo = []
let current_title = ''
try
execute "silent lvimgrep /\\(".join(values(a:regex), '\|')."\\)/j ".g:todolist_backlog
catch
redraw
echohl WarningMsg | echo "Sem ".join(keys(a:regex), ", ") | echohl None
return
endtry
let qf = getloclist(0)
let file = readfile(glob(g:todolist_backlog))
for line in qf
let lnum = line.lnum
let line.alnum = line.lnum
let line.lnum = ''
let line.acol = line.col
let line.col = ''
for key in keys(a:regex)
if(match(line.text, a:regex[key]) > 0)
let line.pattern=key
let line.text = substitute(line.text, a:regex[key], '', '')
break
endif
endfor
let line.text = substitute(line.text, '^\s*', '', '')
let line.text = substitute(line.text, '\-\s\[\s\]\s', '', '')
for indexLine in reverse(range(0, lnum-1))
if(match(file[indexLine], '\S') == 0)
let line.module = file[indexLine]
break
endif
endfor
endfor
call setloclist(0,qf)
lli
for line in qf
let line.lnum = line.alnum
let line.col = line.acol
let line.pattern = ''
endfor
call setloclist(0,qf)
let idx = input("Item: ", "", "customlist,TodoListll")
if(idx>0)
execute "silent ll ".idx
normal zO
endif
endfunction
function! TodoListll(ArgLead, CmdLine, CursorPos)
return map(range(1, len(getloclist(0))), 'string(v:val)')
endfunction
function! TodoListCommands(ArgLead, CmdLine, CursorPos)
return ['TodoList', 'TodoListFileBacklog', 'TodoListFileDone']
endfunction
function! TodoListMenu()
let cmd = input("> ", "\<c-d>", "customlist,TodoListCommands")
if(cmd=='')
return
endif
execute cmd
endfunction