-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
250 lines (218 loc) · 6.18 KB
/
vimrc
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
" by shacon
"---------------general-------------
set nocompatible
set encoding=UTF-8
filetype on
filetype plugin indent on
set spell
set mouse=a
set number
set cursorline
set cursorcolumn
set showcmd
set showmatch
set nowrap
set nobackup
set wildmenu
set history=1000
set tabstop=4 shiftwidth=4 expandtab smarttab
set autoindent smartindent cindent
set hlsearch incsearch ignorecase smartcase
syntax enable
set list
set listchars=tab:>-,trail:-
set ttimeoutlen=0
set autoread
au FocusGained,BufEnter * silent! checktime
function! SetColorColumn()
if &filetype =~# '\v^(c|cpp|h|python)$'
set colorcolumn=80,120
else
set colorcolumn=
endif
endfunction
autocmd BufEnter * call SetColorColumn()
autocmd FileType * call SetColorColumn()
highlight ColorColumn ctermbg=242 guibg=Grey40
"---------------keybinds------------
nnoremap <SPACE> <Nop>
let mapleader=" "
nmap <leader>w :w!<cr>
map <Left> <Nop>
map <Right> <Nop>
map <Up> <Nop>
map <Down> <Nop>
map <leader>h ^
map <leader>l $
map <leader>k <C-U>
map <leader>j <C-D>
map <Esc>h <c-w>h
map <Esc>j <c-w>j
map <Esc>k <c-w>k
map <Esc>l <c-w>l
inoremap jj <Esc>:w<CR>
nnoremap <Esc>x :bdelete<CR>
inoremap <Esc>x <Esc>:bdelete<CR>
noremap <leader>y :w !wl-copy<CR><CR>
noremap <leader>p :r !wl-paste<CR>
" reload vim
nnoremap <leader>r :source $MYVIMRC<cr>
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | execute "normal! g'\"" | endif
nmap <leader><leader>l :call CycleLineNumbers()<CR>
function! CycleLineNumbers()
if (&number == 1 && &relativenumber == 0)
set relativenumber
else
set number
set norelativenumber
endif
endfunc
"----------------comment----------------
let g:py_header_comment = [
\ '"""',
\ '%DESC%.',
\ '',
\ '@history',
\ ' %DATE% %AUTHOR% Created.',
\ '',
\ 'Copyright (c) %YEAR%~ %AUTHOR%.',
\ '"""',
\'',
\''
\]
let g:c_header_comment = [
\ '/**',
\ ' * %DESC%.',
\ ' *',
\ ' * @history',
\ ' * %DATE% %AUTHOR% created.',
\ ' *',
\ ' * Copyright (c) %YEAR%~ %AUTHOR%',
\ ' */',
\ '',
\ ''
\]
let g:py_function_comment = [
\ '"""%DESC%',
\ '',
\ 'Args',
\ ' name <type> (shape) [io] desc.',
\ ' name <type> (shape) [io] desc (0, 10].',
\ ' name <type> (shape) [io] desc {value: desc, value: desc}.',
\ '',
\ 'Returns',
\ ' <type>: desc',
\ '"""',
\ ''
\]
let g:c_function_comment = [
\ '/**',
\ ' * %DESC%.',
\ ' *',
\ ' * @param name <type> (shape) [io] desc.',
\ ' * @param name <type> (shape) [io] desc (0, 10].',
\ ' * @param name <type> (shape) [io] desc {value: desc, value: desc}.',
\ ' * @return <type> desc.',
\ ' */',
\ ''
\]
function! GetHeaderCommentTemplate()
if &filetype == 'python'
return g:py_header_comment
elseif &filetype == 'c' || &filetype == 'cpp'
return g:c_header_comment
else
return []
endif
endfunction
function! GetFunctionCommentTemplate()
if &filetype == 'python'
return g:py_function_comment
elseif &filetype == 'c' || &filetype == 'cpp'
return g:c_function_comment
else
return []
endif
endfunction
function! InsertHeaderComment()
let template = GetHeaderCommentTemplate()
if empty(template)
echo 'No template defined for this file type.'
return
endif
let author = $USER
let date = strftime('%Y-%m-%d')
let year = strftime('%Y')
let desc = input('Header description: ')
let template = substitute(join(template, "\n"), '%DESC%', desc, 'g')
let template = substitute(template, '%AUTHOR%', author, 'g')
let template = substitute(template, '%DATE%', date, 'g')
let template = substitute(template, '%YEAR%', year, 'g')
call append(0, split(template, "\n"))
endfunction
function! InsertFunctionComment()
let template = GetFunctionCommentTemplate()
if empty(template)
echo 'No function comment template defined for this file type.'
return
endif
let func_name = expand('<cword>')
let desc = input('Function description: ')
let template = substitute(join(template, "\n"), '%DESC%', desc, 'g')
if &filetype == 'python'
let indent = matchstr(getline('.'), '^[ \t]*')
let template_lines = split(template, "\n")
let template_lines = map(template_lines, 'v:val == "" ? v:val : indent . v:val')
let template = join(template_lines, "\n")
call append(line('.'), template_lines)
else
call append(line('.') - 1, split(template, "\n"))
endif
endfunction
autocmd FileType * nnoremap <Esc><C-h> :call InsertHeaderComment()<ESC>
autocmd FileType * nnoremap <Esc><C-i> :call InsertFunctionComment()<ESC>
"----------------fold-----------------
set foldenable
set foldmethod=indent
set foldlevel=99
let g:FoldMethod = 0
map <leader>zz :call ToggleFold()<cr>
fun! ToggleFold()
if g:FoldMethod == 0
exe "normal! zM"
let g:FoldMethod = 1
else
exe "normal! zR"
let g:FoldMethod = 0
endif
endfun
"----------------fcitx----------------
if exists('g:fcitx_auto')
finish
endif
let g:fcitx_auto = 1
let s:r_status = 1
let s:f_status = system("fcitx-remote")
let s:cmd = s:f_status == 1 || s:f_status == 2 ? "fcitx-remote" : "fcitx5-remote"
function s:fcitx2en()
let l:lang = system(s:cmd)
if l:lang == 2
call system(printf("%s -c", s:cmd))
let s:r_status = 2
else
let s:r_status = 1
endif
endfunction
function s:fcitx2back()
if s:r_status == 1
call system(printf("%s -c", s:cmd))
else
call system(printf("%s -o", s:cmd))
endif
endfunction
autocmd InsertLeave * call <SID>fcitx2en()
autocmd InsertEnter * call <SID>fcitx2back()
"----------------pro----------------
if filereadable(expand($HOME . '/.vimrc.pro'))
source $HOME/.vimrc.pro
endif