-
Notifications
You must be signed in to change notification settings - Fork 4
/
.vimrc
314 lines (234 loc) · 7.48 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
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" General
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Be IMproved
set nocompatible
" Set backspace
set backspace=eol,start,indent
" Lines folding
set foldenable
set foldnestmax=1
set foldmethod=syntax
" Enable filetypes
filetype plugin indent on
" Set fileencodings
set fileencodings=ucs-bom,utf-8,gbk,big5
" Set complete options
set completeopt=longest,menu
" Set wild menu & mode
set wildmenu
set wildmode=longest:full,full
" Set key codes timeout
set ttimeoutlen=100
" Use absolute paths in sessions
set sessionoptions-=curdir
" Set current working directory automatically
" autocmd BufEnter * silent! lcd %:p:h
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Backup
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable backup
set backup
" Set backup directory
set backupdir=~/.vim/backup
if !isdirectory($HOME . "/.vim/backup")
call mkdir($HOME . "/.vim/backup", "p", 0700)
endif
" Set swap file directory
set directory=~/.vim/swap,/tmp
if !isdirectory($HOME . "/.vim/swap")
call mkdir($HOME . "/.vim/swap", "p", 0700)
endif
" Keep more backups for one file
autocmd BufWritePre * let &backupext = strftime(".%y%m%d%H%M")
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Colors
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set colorscheme
colorscheme desert
" Enable syntax highlight
syntax on
" Set the highlight color for search
highlight Search term=reverse ctermfg=black ctermbg=yellow guifg=black guibg=yellow
" Set the highlight color for special keys like tabs and spaces
highlight SpecialKey ctermfg=darkgray guifg=darkgray
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Interface
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Show ruler
set ruler
" Dynamic title
set title
" Display line number
set number
" Always have a status line
set laststatus=2
" Allow to display incomplete line
set display=lastline
" Set the strings to use in the 'list' mode
set listchars=tab:>-,trail:·,extends:>,precedes:<,space:·
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Search
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Enable magic matching
set magic
" Show matching bracets
set showmatch
" Highlight search things
set hlsearch
" Ignore case when searching
set smartcase
set ignorecase
" Incremental match when searching
set incsearch
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Indent
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Auto indent
set autoindent
" Smart indet
set smartindent
" Use hard tabs
set tabstop=8
set noexpandtab
set shiftwidth=8
" Break long lines
"set textwidth=78
" Set auto-formating
set formatoptions+=mM
" Config C-indenting
set cinoptions=:0,l1,t0,g0,(0
" set textwidth for mail
autocmd FileType mail set textwidth=72
" Use soft tabs for python
autocmd FileType python set expandtab shiftwidth=4 softtabstop=4
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Source code tagging
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Autoload tags
set tags=tags;
" Use GLOBAL tags
set cscopeprg=gtags-cscope
" Use both GLOBAL and ctags
set cscopetag
" Search GLOBAL database first
set cscopetagorder=0
" Use quickfix window to show search results
set cscopequickfix=s-,g-,d-,c-,t-,e-,f-,i-
" Find the database file and load it automatically
function! LoadDatabase()
let db = findfile("GTAGS", ".;")
if (!empty(db))
set nocscopeverbose " suppress 'duplicate connection' error
exe "cs add " . db
set cscopeverbose
endif
endfunction
autocmd BufEnter *.c,*.cc,*.cpp,*.h call LoadDatabase()
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Mappings
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Tab navigation
nnoremap tp :tabprevious<CR>
nnoremap tn :tabnext<CR>
nnoremap to :tabnew<CR>
nnoremap tc :tabclose<CR>
nnoremap gf <C-W>gf
" Move among windows
nnoremap <C-h> <C-W>h
nnoremap <C-j> <C-W>j
nnoremap <C-k> <C-W>k
nnoremap <C-l> <C-W>l
" Fuzzy finder
nnoremap <Leader>f :FzfFiles<CR>
nnoremap <Leader>b :FzfBuffers<CR>
nnoremap <Leader>m :FzfHistory<CR>
nnoremap <Leader>g :FzfGitFiles<CR>
" GLOBAL key mappings
nnoremap <C-\>s :scs find s <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>g :scs find g <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>d :scs find d <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>c :scs find c <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>t :scs find t <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>e :scs find e <C-R>=expand("<cword>")<CR><CR>
nnoremap <C-\>f :scs find f <C-R>=expand("<cfile>")<CR><CR>
nnoremap <C-\>i :scs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
" Display lines upward and downward
nnoremap <Up> gk
nnoremap <Down> gj
" Tagbar toggle
nnoremap <silent> <F2> :TagbarToggle<CR>
" Searching tool
nnoremap <F3> :Ag! <C-R>=expand("<cword>")<CR> ./
" Paste toggle
set pastetoggle=<F4>
" Save & Make
nnoremap <F5> :w<CR>:make!<CR>
" Save & Run
au FileType go nn <F6> :w<CR>:!go run %<CR>
au FileType python nn <F6> :w<CR>:!python %<CR>
au FileType c nn <F6> :w<CR>:make! %< CC=gcc CFLAGS="-g -Wall"<CR>:!./%<<CR>
" Quickfix window
nnoremap <silent> <F7> :botright copen<CR>
nnoremap <silent> <F8> :cclose<CR>
" NERDTree toggle
nnoremap <silent> <F9> :NERDTreeToggle<CR>
" Line numbers toggle
nnoremap <silent> <F10> :set number!<CR>
" Use <space> to toggle fold
nnoremap <silent> <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
" Use xsel to access the X clipboard
if $DISPLAY != '' && executable('xsel')
nnoremap <silent> "*y :'[,']w !xsel -i -p -l /dev/null<CR>
nnoremap <silent> "*p :r!xsel -p<CR>
nnoremap <silent> "+y :'[,']w !xsel -i -b -l /dev/null<CR>
nnoremap <silent> "+p :r!xsel -b<CR>
endif
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Plugins
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Set Tagbar width
let tagbar_width = 32
" Fzf command prefix
let fzf_command_prefix = 'Fzf'
" Vim-go plugin settings
let go_fmt_fail_silently = 1
let go_highlight_functions = 1
let go_highlight_methods = 1
let go_highlight_structs = 1
let go_highlight_operators = 1
let go_highlight_build_constraints = 1
" Add extra spaces when (un)commenting
let NERDSpaceDelims = 1
" Use context to decide completion type
let SuperTabDefaultCompletionType = "context"
" Start interactive EasyAlign in visual mode (e.g. vipga)
xmap ga <Plug>(EasyAlign)
" Start interactive EasyAlign for a motion/text object (e.g. gaip)
nmap ga <Plug>(EasyAlign)
" Plugin manager
if empty(glob('~/.vim/autoload/plug.vim'))
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall | source $MYVIMRC
endif
call plug#begin('~/.vim/bundle')
Plug 'vim-scripts/OmniCppComplete'
Plug 'benjifisher/matchit.zip'
Plug 'editorconfig/editorconfig-vim'
Plug 'ervandew/supertab'
Plug 'junegunn/vim-easy-align'
Plug 'lilydjwg/fcitx.vim'
Plug 'Lokaltog/vim-easymotion'
Plug 'majutsushi/tagbar'
Plug 'rking/ag.vim'
Plug 'scrooloose/nerdcommenter'
Plug 'scrooloose/nerdtree'
Plug 'SirVer/ultisnips' | Plug 'honza/vim-snippets'
Plug 'vim-airline/vim-airline'
Plug 'fatih/vim-go', { 'for': 'go' }
Plug 'nathanaelkane/vim-indent-guides', { 'for': 'python' }
Plug 'plasticboy/vim-markdown', { 'for': 'markdown' }
Plug 'junegunn/fzf.vim'
Plug 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
call plug#end()