-
Notifications
You must be signed in to change notification settings - Fork 2
/
.vimrc
363 lines (288 loc) · 10.9 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
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
" General "{{{
set nocompatible " be iMproved
scriptencoding utf-8 " utf-8 all the way
set encoding=utf-8
set history=256 " Number of things to remember in history.
set timeoutlen=250 " Time to wait after ESC (default causes an annoying delay)
set clipboard+=unnamed " Yanks go on clipboard instead.
set pastetoggle=<F10> " toggle between paste and normal: for 'safer' pasting from keyboard
set shiftround " round indent to multiple of 'shiftwidth'
set tags=.git/tags;$HOME " consider the repo tags first, then
" walk directory tree upto $HOME looking for tags
" note `;` sets the stop folder. :h file-search
" This should be interesting...
inoremap jk <Esc>
inoremap kj <Esc>
set modeline
set modelines=5 " default numbers of lines to read for modeline instructions
" Append modeline after last line in buffer.
" Use substitute() instead of printf() to handle '%%s' modeline in LaTeX
" files.
function! AppendModeline()
let l:modeline = printf(" vim: set ts=%d sw=%d tw=%d %set :",
\ &tabstop, &shiftwidth, &textwidth, &expandtab ? '' : 'no')
let l:modeline = substitute(&commentstring, "%s", l:modeline, "")
call append(line("$"), l:modeline)
endfunction
nnoremap <silent> <Leader>ml :call AppendModeline()<CR>
set autowrite " Writes on make/shell commands
set autoread
set nobackup
set nowritebackup
set directory=/tmp// " prepend(^=) $HOME/.tmp/ to default path; use full path as backup filename(//)
set noswapfile "
set hidden " The current buffer can be put to the background without writing to disk
set hlsearch " highlight search
set ignorecase " be case insensitive when searching
set smartcase " be case sensitive when input has a capital letter
set incsearch " show matches while typing
let g:is_posix = 1 " vim's default is archaic bourne shell, bring it up to the 90s
let mapleader = ','
let maplocalleader = ' ' " Tab as a local leader
let g:netrw_banner = 0 " do not show Netrw help banner
" "}}}
" Formatting "{{{
set fo+=o " Automatically insert the current comment leader after hitting 'o' or 'O' in Normal mode.
set fo-=r " Do not automatically insert a comment leader after an enter
set fo-=t " Do no auto-wrap text using textwidth (does not apply to comments)
set nowrap
set textwidth=0 " Don't wrap lines by default
set tabstop=2 " tab size eql 2 spaces
set softtabstop=2
set shiftwidth=2 " default shift width for indents
set expandtab " replace tabs with ${tabstop} spaces
set smarttab "
set backspace=indent
set backspace+=eol
set backspace+=start
set autoindent
set cindent
set indentkeys-=0# " do not break indent on #
set cinkeys-=0#
set cinoptions=:s,ps,ts,cs
set cinwords=if,else,while,do
set cinwords+=for,switch,case
" "}}}
" Visual "{{{
syntax on " enable syntax
" set synmaxcol=250 " limit syntax highlighting to 128 columns
set mouse=a "enable mouse in GUI mode
set mousehide " Hide mouse after chars typed
set number " line numbers
if exists('+relativenumber')
set relativenumber " relative numbering
endif
set showmatch " Show matching brackets.
set matchtime=2 " Bracket blinking.
set wildmode=longest,list " At command line, complete longest common string, then list alternatives.
set completeopt+=preview
set novisualbell " No blinking
set noerrorbells " No noise.
set vb t_vb= " disable any beeps or flashes on error
set laststatus=2 " always show status line.
set shortmess=atI " shortens messages
set showcmd " display an incomplete command in statusline
set foldenable " Turn on folding
set foldmethod=marker " Fold on the marker
set foldlevel=100 " Don't autofold anything (but I can still fold manually)
set foldopen=block,hor,tag " what movements open folds
set foldopen+=percent,mark
set foldopen+=quickfix
set virtualedit=block
set splitbelow
set splitright
" display unprintable characters f12 - switches
set nolist
set listchars=tab:\ ·,eol:¬
set listchars+=trail:·
set listchars+=extends:»,precedes:«
map <silent> <F12> :set invlist<CR>
if has('gui_running')
set guioptions=cMg " console dialogs, do not show menu and toolbar
" Fonts
" :set guifont=* " to launch a GUI dialog
if has('mac')
set guifont=Andale\ Mono:h13
else
set guifont=Terminus:h16
end
if has('mac')
set noantialias
" set fullscreen
set fuoptions=maxvert,maxhorz ",background:#00AAaaaa
endif
endif
" "}}}
" Key mappings " {{{
" Duplication
nnoremap <leader>c mz"dyy"dp`z
vnoremap <leader>c "dymz"dP`z
" Tabs
map <C-h> :tabprev<CR>
map <C-l> :tabnext<CR>
" Buffers
nnoremap <localleader>- :bd<CR>
nnoremap <localleader>-- :bd!<CR>
" Split line(opposite to S-J joining line)
nnoremap <C-J> gEa<CR><ESC>ew
" copy filename
map <silent> <leader>. :let @+=expand('%:p').':'.line('.')<CR>
map <silent> <leader>/ :let @+=expand('%:p:h')<CR>
" copy path
map <S-CR> A<CR><ESC>
map <leader>E :Explore<CR>
map <leader>EE :Vexplore!<CR><C-W>=
" Make Control-direction switch between windows (like C-W h, etc)
nmap <silent> <C-k> <C-W><C-k>
nmap <silent> <C-j> <C-W><C-j>
nmap <silent> <C-H> <C-W><C-h>
nmap <silent> <C-L> <C-W><C-l>
" vertical paragraph-movement
nmap <C-K> {
nmap <C-J> }
" quick vert split
nnoremap <leader>V :vnew<CR>
" when pasting copy pasted text back to
" buffer instead replacing with owerride
xnoremap p pgvy
if has('mac')
if has('gui_running')
set macmeta
end
" map(range(1,9), 'exec "imap <D-".v:val."> <C-o>".v:val."gt"')
" map(range(1,9), 'exec " map <D-".v:val."> ".v:val."gt"')
" Copy whole line
nnoremap <silent> <D-c> yy
" close/delete buffer when closing window
map <silent> <D-w> :bdelete<CR>
endif
" Control+S and Control+Q are flow-control characters: disable them in your terminal settings.
" $ stty -ixon -ixoff
noremap <C-S> :update<CR>
vnoremap <C-S> <C-C>:update<CR>
inoremap <C-S> <C-O>:update<CR>
"
" generate HTML version current buffer using current color scheme
map <leader>2h :runtime! syntax/2html.vim<CR>
" nohilight
nnoremap <leader>n :nohlsearch<CR>
" edit vimrc
nnoremap <leader>v :tabe ~/dotfiles/.vimrc<CR>
nnoremap <Leader>vr :source $MYVIMRC<CR>
" make
nnoremap <leader>m :make<CR>
nnoremap <leader>mi :make install<CR>
nnoremap <leader>mc :make clean<CR>
" eXecute
nnoremap <leader>x :!./%<CR>
" logbook
nnoremap <leader>l :vsplit ~/log.md<CR>
" latex
nnoremap <leader>p :!pdflatex %<CR>
let g:tex_comment_nospell=1
" " }}}
" AutoCommands " {{{
au BufRead,BufNewFile {*.go} setl ft=go tabstop=2 softtabstop=2 noexpandtab smarttab
au BufRead,BufNewFile {Gemfile,Rakefile,Capfile,*.rake,config.ru} setl ft=ruby tabstop=2 softtabstop=2 shiftwidth=2 expandtab smarttab
au BufRead,BufNewFile {*.py} setl ft=python tabstop=4 softtabstop=4 shiftwidth=4 expandtab smarttab
au BufRead,BufNewFile {*.tex} setl ft=tex spell spelllang=en
au BufRead,BufNewFile {*.local} setl ft=sh
au BufRead,BufNewFile {*.md,*.mkd,*.markdown} setl ft=markdown
au BufRead,BufNewFile {*.scala} setl ft=scala
au! BufReadPost {COMMIT_EDITMSG,*/COMMIT_EDITMSG} setl ft=gitcommit noml| norm 1G
au! BufWritePost {*.snippet,*.snippets} call ReloadAllSnippets()
" open help in vertical split
au BufWinEnter *.txt if &ft == 'help' | wincmd H | nmap q :q<CR> | endif
" " }}}
" Scripts and Plugins " {{{
filetype off
runtime macros/matchit.vim
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'VundleVim/Vundle.vim'
Plugin 'rhysd/vim-clang-format'
let g:clang_format#style_options = {
\ "BasedOnStyle" : "llvm",
\ "AllowShortIfStatementsOnASingleLine" : "true",
\ "Standard" : "C++17"}
" map to <Leader>cf in C++ code
autocmd FileType c,cpp,objc nnoremap <buffer><Leader>cf :<C-u>ClangFormat<CR>
autocmd FileType c,cpp,objc vnoremap <buffer><Leader>cf :ClangFormat<CR>
autocmd FileType c,cpp,objc set colorcolumn=80
" For vimdiff
Plugin 'vim-scripts/diffchar.vim'
let g:DiffUnit="Word1"
" Colorscheme
Plugin 'altercation/vim-colors-solarized'
" Syntax highlight
Plugin 'sheerun/vim-polyglot'
" Syntax checking
" Plugin 'vim-syntastic/syntastic'
" set statusline+=%#warningmsg#
" set statusline+=%{SyntasticStatuslineFlag()}
" set statusline+=%*
let g:syntastic_always_populate_loc_list = 1
let g:syntastic_auto_loc_list = 1
let g:syntastic_check_on_open = 1
let g:syntastic_check_on_wq = 0
let g:syntastic_python_flake8_args='--ignore=E501,E225'
" Git integration
Plugin 'tpope/vim-git'
Plugin 'tpope/vim-fugitive'
nnoremap <leader>W :Gwrite<CR>
nnoremap <leader>C :Gcommit -v<CR>
nnoremap <leader>S :Gstatus \| 7<CR>
nnoremap <leader>P :Gpush<CR>
nnoremap <leader>gl :Glog<CR>
" FuzzyFinder "{{{
if v:version > 702
Plugin 'L9'
Plugin 'FuzzyFinder'
let g:fuf_modesDisable = []
nnoremap <leader>h :FufHelp<CR>
nnoremap <leader>1 :FufTagWithCursorWord<CR>
nnoremap <leader>11 :FufTag<CR>
nnoremap <leader>2 :FufFileWithCurrentBufferDir<CR>
nnoremap <leader>22 :FufFile<CR>
nnoremap <leader>3 :FufBuffer<CR>
nnoremap <leader>4 :FufDirWithCurrentBufferDir<CR>
nnoremap <leader>44 :FufDir<CR>
nnoremap <leader>5 :FufBufferTag<CR>
nnoremap <leader>55 :FufBufferTagAll<CR>
nnoremap <leader>6 :FufMruFile<CR>
nnoremap <leader>7 :FufLine<CR>
nnoremap <leader>8 :FufChangeList<CR>
nnoremap <leader>9 :FufTaggedFile<CR>
nnoremap <leader>r :FufRenewCache<CR>
let fuf_keyOpen = '<C-l>'
let fuf_keyOpenTabpage = '<CR>'
endif
" " }}}
Plugin 'kien/ctrlp.vim'
let g:ctrlp_map = '<leader>t'
let g:ctrlp_max_height = 30
let g:ctrlp_match_window_bottom=1
let g:ctrlp_max_height = 20
let g:ctrlp_match_window_reversed = 1
let g:ctrlp_switch_buffer = 'e'
call vundle#end() " required
syntax enable
set background=dark
colorscheme solarized
filetype plugin indent on " Automatically detect file types.
" Customized statusline
set statusline=%f\ -\ FileType:\ %y%=
set statusline+=%c,%l/%L\ %P
set statusline+=\ %{fugitive#statusline()}
" " }}}
" CMSSW Customizations " {{{
if $CMSSW_BASE != ''
" This enables opening headers in CMSSW files via gf
set path+=$CMSSW_BASE/src
set path+=$CMSSW_RELEASE_BASE/src
" easy scram build
nnoremap <leader>b :!pushd $CMSSW_BASE/src && scram b && popd<CR>
" autocomplete takes too long scanning includes
set complete-=i
endif
" "}}}