forked from SpaceVim/SpaceVim
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.vim
194 lines (187 loc) · 5.34 KB
/
functions.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
"Detect OS
function! OSX()
return has('macunix')
endfunction
function! LINUX()
return has('unix') && !has('macunix') && !has('win32unix')
endfunction
function! WINDOWS()
return (has('win16') || has('win32') || has('win64'))
endfunction
function! OnmiConfigForJsp()
let pos1 = search("</script>","nb",line("w0"))
let pos2 = search("<script","nb",line("w0"))
let pos3 = search("</script>","n",line("w$"))
let pos0 = line('.')
if pos1 < pos2 && pos2 < pos0 && pos0 < pos3
set omnifunc=javascriptcomplete#CompleteJS
return "\<esc>a."
else
set omnifunc=javacomplete#Complete
return "\<esc>a."
endif
endf
function! ToggleNumber()
let s:isThereNumber = &nu
let s:isThereRelativeNumber = &relativenumber
if s:isThereNumber && s:isThereRelativeNumber
set paste!
set nonumber
set norelativenumber
else
set paste!
set number
set relativenumber
endif
endf
function! ToggleBG()
let s:tbg = &background
" Inversion
if s:tbg == "dark"
set background=light
else
set background=dark
endif
endfunction
function! BracketsFunc()
let line = getline('.')
let col = col('.')
if line[col - 2] == "]"
return "{}\<esc>i"
else
return "{\<cr>}\<esc>O"
endif
endf
function! XmlFileTypeInit()
set omnifunc=xmlcomplete#CompleteTags
if filereadable("AndroidManifest.xml")
set dict+=~/.vim/bundle/vim-dict/dict/android_xml.dic
endif
endf
function! WSDAutoComplete(char)
if(getline(".")=~?'^\s*.*\/\/')==0
let line = getline('.')
let col = col('.')
if a:char == "."
return a:char."\<c-x>\<c-o>\<c-p>"
elseif line[col - 2] == " "||line[col -2] == "("||line[col - 2] == ","
return a:char."\<c-x>\<c-o>\<c-p>"
elseif line[col - 3] == " "&&line[col - 2] =="@"
return a:char."\<c-x>\<c-o>\<c-p>"
else
return a:char
endif
else
"bug exists
normal! ma
let commentcol = searchpos('//','b',line('.'))[1]
normal! `a
if commentcol == 0
return a:char."\<c-x>\<c-o>\<c-p>"
else
return "\<Right>".a:char
endif
endif
endf
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endf
function! CloseBracket()
if match(getline(line('.') + 1), '\s*}') < 0
return "\<CR>}"
else
return "\<Esc>j0f}a"
endif
endf
function! QuoteDelim(char)
let line = getline('.')
let col = col('.')
if line[col - 2] == "\\"
"Inserting a quoted quotation mark into the string
return a:char
elseif line[col - 1] == a:char
"Escaping out of the string
return "\<Right>"
else
"Starting a string
return a:char.a:char."\<Esc>i"
endif
endf
function! JspFileTypeInit()
set tags+=/home/wsdjeg/others/openjdk-8-src/tags
set omnifunc=javacomplete#Complete
inoremap . <c-r>=OnmiConfigForJsp()<cr>
nnoremap <F4> :JCimportAdd<cr>
inoremap <F4> <esc>:JCimportAddI<cr>
endfunction
function! MyTagfunc() abort
mark H
let s:MyTagfunc_flag = 1
UniteWithCursorWord -immediately tag
endfunction
function! MyTagfuncBack() abort
if exists('s:MyTagfunc_flag')&&s:MyTagfunc_flag
exe "normal! `H"
let s:MyTagfunc_flag =0
endif
endfunction
function! MyLeaderTabfunc() abort
if g:spacevim_autocomplete_method == 'deoplete'
if g:spacevim_enable_javacomplete2_py
return deoplete#mappings#manual_complete(['javacomplete2'])
else
return deoplete#mappings#manual_complete(['omni'])
endif
elseif g:spacevim_autocomplete_method == 'neocomplete'
return neocomplete#start_manual_complete(['omni'])
endif
endfunction
func! Openpluginrepo()
try
exec "normal! ".'"ayi'."'"
exec 'OpenBrowser https://github.com/'.@a
catch
echohl WarningMsg | echomsg "can not open the web of current plugin" | echohl None
endtry
endf
func! Update_current_plugin()
try
let a_save = @a
let @a=''
normal! "ayi'
let plug_name = match(@a, '/') >= 0 ? split(@a, '/')[1] : @a
finally
let @a = a_save
endtry
call dein#update([plug_name])
endf
func! Show_Log_for_current_plugin()
try
let a_save = @a
let @a=''
normal! "ayi'
let plug = match(@a, '/') >= 0 ? @a : 'vim-scripts/'.@a
finally
let @a = a_save
endtry
call unite#start([['output/shellcmd',
\ 'git --no-pager -C ~/.cache/vimfiles/repos/github.com/'
\ . plug
\ . ' log -n 15 --oneline']], {'log': 1, 'wrap': 1,'start_insert':0})
exe "nnoremap <buffer><CR> :call <SID>Opencommit('". plug ."', strpart(split(getline('.'),'[33m')[1],0,7))<CR>"
endf
fu! s:Opencommit(repo,commit)
exe "OpenBrowser https://github.com/" . a:repo ."/commit/". a:commit
endf
fu! UpdateStarredRepos()
let repos = github#api#users#GetStarred('wsdjeg')
for repo in repos
let description = repo.full_name . repeat(' ', 40 - len(repo.full_name)) . repo.description
let cmd = "OpenBrowser " . repo.html_url
call add(g:unite_source_menu_menus.MyStarredrepos.command_candidates, [description,cmd])
endfor
endf