-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
346 lines (282 loc) · 9.02 KB
/
vimrc
File metadata and controls
346 lines (282 loc) · 9.02 KB
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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
" ---------------------------- Modeline and Notes ---------------------------- {
" vim: foldlevel=0 foldmarker={,} foldmethod=marker
" vim: foldtext=deisufunc#DotVimsFoldText()
" ____ _ ____ _
" | _ \ ___(_) ___| _ _ __ _(_)_ __ ___ _ __ ___
" | | | |/ _ \ \___ \| | | |____\ \ / / | '_ ` _ \| '__/ __|
" | |_| | __/ |___) | |_| |_____\ V /| | | | | | | | | (__
" |____/ \___|_|____/ \__,_| \_/ |_|_| |_| |_|_| \___|
"
" DeiSu's personal vimrc.
" Copyright © 2014-2015 DeiSu. All Rights Reserved.
" }
" ------------------------------- Environment -------------------------------- {
" don't bother with vi compatibility
set nocompatible
" use zsh
set shell=/bin/zsh
" }
" ---------------------------------- Before ---------------------------------- {
" preferences
let g:deisu_preferences = {}
" complete method
" 1: ycm: YouCompleteMe + UltiSnips
" 2: neocomplete: neocomplete.vim + neosnippets
" 3: neocomplcache (if doesn't have lua): neocomplcache.vim + neosnippets
let g:deisu_preferences.complete_method = 'ycm'
" color scheme
let g:deisu_preferences.color_scheme = 'solarized'
" load additional preferences
if filereadable(expand("~/.vimrc.before"))
source ~/.vimrc.before
endif
" pick completers
call deisufunc#PickSnippetEngine()
call deisufunc#PickAutocompleter()
" }
" --------------------------------- General ---------------------------------- {
filetype plugin indent on
set history=1000 " store lots of :cmdline and search history
set clipboard=unnamed " make vim use the system default clipboard
set cmdheight=2 " number of screen lines to use for the cmd line
set visualbell
set ttyscroll=3
set title " show file name in titlebar
" the new regex engine is so slow, use the old one
" consider removing this in the future when the new regex engine becomes faster
if v:version >= 704
set regexpengine=1
endif
" let vim use system default clipboard
if has('unnamedplus')
set clipboard=unnamedplus,unnamed
else
set clipboard=unnamed
endif
" mouse: only enable mouse in MacVimApp
if deisufunc#IsMacVimApp()
set mouse=a
else
set mouse=
endif
set mousehide " hide mouse when typing
" buffer
set autoread " automatically read files changed outside vim
set autowrite " automatically save before make/exec command
set hidden " allows hide buffers with unsaved changes
" better rendering
set ttyfast " send more characters to the screen for redrawing
set lazyredraw " don't redraw screen while executing a macro
set synmaxcol=256 " don't syntax highlight things after column 256
" vertical/horizontal scroll off
set scrolloff=3 " at least 3 lines above and below cursor
set sidescrolloff=7
set sidescroll=1
" the longest option makes completion insert the longest prefix of all
" the possible matches
set completeopt=menu,menuone,longest
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" time out on both key codes and mappings
set timeout
set timeoutlen=500
set ttimeout
set ttimeoutlen=10
" tmux will send xterm-style keys when its xterm-keys option is on
if deisufunc#Istmux()
execute "set <xUp>=\e[1;*A"
execute "set <xDown>=\e[1;*B"
execute "set <xRight>=\e[1;*C"
execute "set <xLeft>=\e[1;*D"
endif
" write all buffers when losing focus and read new changes automatically
augroup auto_write_and_read
autocmd!
autocmd FocusLost * silent! wall
autocmd CursorHold,CursorHoldI,FocusGained,BufEnter * checktime
augroup END
" }
" --------------------------------- Backups ---------------------------------- {
" undo
set undofile " store undo states even when files are closed
set undodir=~/.vim/tmp/undo// " where to save undo histories
set undolevels=1000 " use many levels of undo
set undoreload=10000 " number of lines to save for undo
" backup
set backup " backups are nice
set backupdir=~/.vim/tmp/backup//
" swap
set noswapfile " no swap files
set directory=~/.vim/tmp/swap//
" make backup folders automatically if they don't exist
if !isdirectory(expand(&undodir))
call mkdir(expand(&undodir), "p")
endif
if !isdirectory(expand(&backupdir))
call mkdir(expand(&backupdir), "p")
endif
if !isdirectory(expand(&directory))
call mkdir(expand(&directory), "p")
endif
" }
" --------------------------------- Editing ---------------------------------- {
" set filetype
augroup set_filetype
autocmd!
autocmd BufNewFile,BufReadPost *.md set filetype=markdown
autocmd BufNewFile,BufReadPost *.snippets set filetype=snippets
autocmd BufNewFile,BufReadPost *vimrc* set filetype=vim
augroup END
" encoding
set encoding=utf-8
set termencoding=utf-8
" spelling
set nospell
set spelllang=en
" set spell base on filetype
augroup set_spell_base_on_filetype
autocmd!
autocmd BufRead,BufNewFile *.markdown,*.md,*.txt setlocal spell
augroup END
" set comment string base on filetype
augroup set_comment_string_base_on_filetype
autocmd!
autocmd FileType c,cpp,h,mql4 setlocal commentstring=//\ %s
augroup END
" jump to the last known cursor position
augroup jump_to_the_last_known_cursor_position
autocmd!
autocmd BufReadPost *
\ if line("'\"") > 1 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
augroup END
" abbreviations
iabbrev @@ brucedsu@gmail.com
" }
" -------------------------------- Formatting -------------------------------- {
" wrap
set nowrap " don't wrap long lines
" set wrap base on filetype
augroup set_wrap_base_on_filetype
autocmd!
autocmd FileType markdown,md setlocal wrap linebreak
augroup END
" indentation
set expandtab " use spaces instead of tabs
set tabstop=4
set softtabstop=4
set shiftwidth=4
set autoindent " auto indent new lines
set smartindent
set smarttab
" set indentation base on filetype
augroup set_indentation_base_on_filetype
autocmd!
autocmd FileType make,asm setlocal noexpandtab tabstop=8 softtabstop=8 shiftwidth=8
autocmd FileType css,ruby,vim setlocal expandtab tabstop=2 softtabstop=2 shiftwidth=2
autocmd FileType python setl nosmartindent
augroup END
" toggle paste
set pastetoggle=<F4>
" folding
set foldmethod=syntax
set foldlevelstart=99
set foldtext=deisufunc#BaseFoldText()
" set folding base on filetype
augroup set_folding_base_on_filetype
autocmd!
autocmd FileType html,php setlocal foldmethod=indent
augroup END
" preserve folding state
set viewoptions-=options
augroup preserve_folding_state
autocmd!
autocmd BufWritePost *
\| if expand('%') != '' && &buftype !~ 'nofile'
\| mkview
\| endif
autocmd BufRead *
\| if expand('%') != '' && &buftype !~ 'nofile'
\| silent loadview
\| endif
augroup END
" remove all trailing spaces before saving
augroup remove_trailing_spaces
autocmd!
autocmd BufWritePre * :call deisufunc#Preserve("%s/\\s\\+$//e")
augroup END
" don't insert comment prefix when I hit enter at the end of a commented line
augroup remove_comment_prefix_when_hit_enter
autocmd!
autocmd FileType * setlocal formatoptions-=c formatoptions-=r formatoptions-=o
augroup END
" }
" ------------------------------ User Interface ------------------------------ {
syntax on
set showcmd " show incomplete cmds down the bottom
set noshowmode " don't show mode at the bottom
set showmatch
set laststatus=2
" wildmenu
set wildmenu
set wildmode=list:longest,full
set wildignorecase
set wildignore=*.git/*,*tmp/*
set wildignore+=*DS_Store*
set wildignore+=*.pdf,*.zip
set wildignore+=*.png,*.jpg,*.gif
set wildignore+=*.so,*.o,*.a,*.obj,*.swp,*.pyc,*.pyo,*.class
" number and ruler
set number
set relativenumber
set ruler
" colorcolumn
if exists('&colorcolumn')
set colorcolumn=80
" filetype based color column
augroup set_colorcolumn_base_on_filetype
autocmd!
autocmd Filetype python setlocal colorcolumn=79
augroup END
endif
" list
set nolist
set listchars=tab:▸\ ,trail:▫,eol:¬,extends:❯,precedes:❮
" highlight current cursor position
augroup highlight_cursor_position
autocmd!
autocmd WinLeave * set nocursorline nocursorcolumn
autocmd WinEnter * set cursorline cursorcolumn
augroup END
set cursorline cursorcolumn
" search
set ignorecase
set smartcase
set incsearch
set hlsearch
" window
set splitright
set splitbelow
" }
" --------------------------------- Mappings --------------------------------- {
" leaders
let mapleader = ","
let maplocalleader = "\\"
if filereadable(expand("~/.vimrc.mappings"))
source ~/.vimrc.mappings
endif
" }
" --------------------------------- Plugins ---------------------------------- {
if filereadable(expand("~/.vimrc.plugins"))
source ~/.vimrc.plugins
endif
" set color scheme after load plugins
set background=dark
call deisufunc#SetColorScheme(g:deisu_preferences.color_scheme)
" }
" ---------------------------------- After ----------------------------------- {
if filereadable(expand("~/.vimrc.after"))
source ~/.vimrc.after
endif
" }