-
Notifications
You must be signed in to change notification settings - Fork 0
/
.vimrc
327 lines (285 loc) · 7.01 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
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
"Basic settings------
"Enable filetype plugin
filetype plugin on
filetype indent on
"1 tab = 4 spaces
set shiftwidth=4
set tabstop=4
"Be smart when using tabs
"set smarttab
set expandtab
" enable backspace
set backspace=indent,eol,start
set number
filetype on
syntax on
set incsearch
set hlsearch
colorscheme grb256
if has("gui_running")
if has("gui_gtk2")
set guifont=Monaco\ 11
elseif has("gui_photon")
set guifont=Monaco:s11
else
set guifont=Monaco:h19
endif
endif
set cursorline
"
"Mappings-----------
"Uppercase the current word
"inoremap <c-u> <esc>vUa
"nnoremap <c-u> vU
"Lowercase the current word
inoremap <c-l> <esc>vua
nnoremap <c-l> vu
"delete current line in insert mode
inoremap <c-d> <esc>ddi
"automatically insert \v whenever search
nnoremap / /\v
"Leader
let mapleader = ","
"highlight trailing whitespace as an error
nnoremap <leader>w :match Error / $/<cr>
nnoremap <leader>W :match none<cr>
nnoremap <leader>" viw<esc>a"<esc>hbi"<esc>lel
nnoremap <leader>' viw<esc>a'<esc>hbi'<esc>lel
" navigvation
nnoremap gl g$
"Move to beginning or ending of the word
nnoremap <leader>h ^
nnoremap <leader>l $
inoremap <leader>h <esc>^i
inoremap <leader>l <esc>$a
" YCM
nnoremap <leader>gl :YcmCompleter GoToDeclaration<CR>
nnoremap <leader>gf :YcmCompleter GoToDefinition<CR>
nnoremap <leader>gg :YcmCompleter GoToDefinitionElseDeclaration<CR>
"exit insert mode
inoremap jk <esc>
inoremap <nop> <esc>
"move between tabs
nnoremap <leader>t] :tabnext<cr>
nnoremap <leader>t[ :tabprevious<cr>
nnoremap <leader>tf :tabfirst<cr>
nnoremap <leader>tl :tablast<cr>
nnoremap <leader>ev :vsplit $MYVIMRC<cr>
nnoremap <leader>sv :source $MYVIMRC<cr>
noremap <leader>p vi(
noremap <leader>cb vi{
"copy from clipboard
nnoremap <c-v> "+p
"copy to clipboard
vnoremap <c-c> "+y
nnoremap <c-z> :redo<cr>
nnoremap <c-t> :NERDTreeToggle<cr>
nnoremap <c-s> :TagbarToggle<cr>
"
nnoremap <leader>rp :execute "!python "."'".expand("%:p")."'"<cr>
"
" autocmd --------
autocmd BufNewFile *.py call AddAuthorInfo()
" ------
" customized function -------
function! AddAuthorInfo()
call append(0,'#!/usr/bin/python')
call append(1, '#-*-coding:utf-8 -*-')
call append(2, '#Author : Zodiac')
call append(3, '#Version : 1.0')
call append(4, '#Filename : '.expand("%:t"))
call append(5, 'from __future__ import print_function')
call append(6, '')
call append(7, 'def main():')
call append(8, ' pass')
call append(9, '')
call append(10, 'if __name__ == "__main__":')
call append(11, ' main()')
endfunction
" -------
"abbreviations
iabbrev adn and
iabbrev waht what
iabbrev tehn then
iabbrev taht that
"
"operator-pending mappings
onoremap in( :<c-u>normal! f(vi(<cr>
onoremap il( :<c-u>normal! F)vi(<cr>
onoremap in{ :<c-u>normal! f{vi{<cr>
onoremap il{ :<c-u>normal! F}vi{<cr>
"
"author and email
iabbrev ssig "author:Zodiac email:[email protected]
"Vimscript file settings-----------
augroup filetype_vim
autocmd!
autocmd FileType vim setlocal foldmethod=marker
augroup END
"
"Vundle settings----
"For vundle
set nocompatible
filetype off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
"vim-scripts repos
Plugin 'bash-support.vim'
Plugin 'perl-support.vim'
"Plugin 'Shougo/neocomplcache.git'
"Plugin 'Shougo/neosnippet.git'
Plugin 'Valloric/YouCompleteMe'
"Plugin 'davidhalter/jedi-vim'
Plugin 'rdnetto/YCM-Generator'
Plugin 'scrooloose/nerdtree'
Plugin 'matrix.vim--Yang'
Plugin 'Pydiction'
Plugin 'pythoncomplete'
Plugin 'xml.vim'
Plugin 'Lokaltog/vim-powerline'
Plugin 'scrooloose/nerdcommenter'
Plugin 'Tagbar'
Plugin 'godlygeek/tabular'
Plugin 'plasticboy/vim-markdown'
Plugin 'dense-analysis/ale'
Plugin 'JamshedVesuna/vim-markdown-preview'
call vundle#end()
filetype plugin indent on
"
"Pydiction
"pydiction 1.2 python auto complete
"filetype plugin on
let g:pydiction_location = $HOME.'/.vim/bundle/Pydiction/complete-dict'
"default g:pydiction_menu_height == 15
"let g:pydiction_menu_height = 20
"
"Poweline-----
set rtp+=~/.vim/bundle/powerline/powerline/bindings/vim
let t_Co=256
"set nocompatible
set laststatus=2
set encoding=utf-8
let g:Powerline_symbols = 'fancy'
set fillchars+=stl:\ ,stlnc:\
"
" Youcompletemy-----
let g:ycm_python_binary_path = 'python'
let g:ycm_python_interpreter_path = ''
let g:ycm_python_sys_path = []
let g:ycm_extra_conf_vim_data = [
\ 'g:ycm_python_interpreter_path',
\ 'g:ycm_python_sys_path'
\]
let g:ycm_global_ycm_extra_conf = '~/global_extra_conf.py'
"
"Toggling-------
"foldcolumn
nnoremap <leader>f :call FoldColumnToggle()<cr>
function! FoldColumnToggle()
if &foldcolumn
setlocal foldcolumn=0
else
setlocal foldcolumn=4
endif
endfunction
"toggle quickfix
nnoremap <leader>q :call QuickfixToggle()<cr>
let g:quickfix_is_open = 0
function! QuickfixToggle()
if g:quickfix_is_open
cclose
let g:quickfix_is_open = 0
execute g:quickfix_return_to_window . "wincmd w"
else
let g:quickfix_return_to_window = winnr()
copen
let g:quickfix_is_open = 1
endif
endfunction
"Toggle Menu and Toobar
set guioptions-=m
set guioptions-=T
map <silent><F2> :call ToggleMenuBar()<cr>
function! ToggleMenuBar()
if &guioptions =~# 'T'
set guioptions-=T
set guioptions-=m
else
set guioptions+=T
set guioptions+=m
endif
endfunction
"
"Python_Folding---
if exists("b:did_ftplugin")
finish
endif
let b:did_ftplugin = 1
map <buffer> <S-e> :w<CR>:!/usr/bin/env python % <CR>
map <buffer> gd /def <C-R><C-W><CR>
set foldmethod=expr
set foldexpr=PythonFoldExpr(v:lnum)
set foldtext=PythonFoldText()
map <buffer> f za
map <buffer> F :call ToggleFold()<CR>
let b:folded = 1
function! ToggleFold()
if( b:folded == 0 )
exec "normal! zM"
let b:folded = 1
else
exec "normal! zR"
let b:folded = 0
endif
endfunction
function! PythonFoldText()
let size = 1 + v:foldend - v:foldstart
if size < 10
let size = " " . size
endif
if size < 100
let size = " " . size
endif
if size < 1000
let size = " " . size
endif
if match(getline(v:foldstart), '"""') >= 0
let text = substitute(getline(v:foldstart), '"""', '', 'g' ) . ' '
elseif match(getline(v:foldstart), "'''") >= 0
let text = substitute(getline(v:foldstart), "'''", '', 'g' ) . ' '
else
let text = getline(v:foldstart)
endif
return size . ' lines:'. text . ' '
endfunction
function! PythonFoldExpr(lnum)
if indent( nextnonblank(a:lnum) ) == 0
return 0
endif
if getline(a:lnum-1) =~ '^\(class\|def\)\s'
return 1
endif
if getline(a:lnum) =~ '^\s*$'
return "="
endif
if indent(a:lnum) == 0
return 0
endif
return '='
endfunction
" In case folding breaks down
function! ReFold()
set foldmethod=expr
set foldexpr=0
set foldnestmax=1
set foldmethod=expr
set foldexpr=PythonFoldExpr(v:lnum)
set foldtext=PythonFoldText()
echo
endfunction
"
"Markdown Previw----
let vim_markdown_preview_github=1
let vim_markdown_preview_toggle=2
"----