-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvimrc
315 lines (260 loc) · 7.7 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
set nocompatible
" Setup vim-plug plugins
if filereadable(expand('~/.vim/autoload/plug.vim'))
let g:plug_home=expand('~/.vim/plugged')
if has('win32unix') && executable('cygpath')
" Use mixed path on Cygwin so that Windows git works
let g:plug_home = split(system('cygpath -m ' . g:plug_home), "\r*\n")[0]
endif
call plug#begin()
" Plugins
Plug 'inkarkat/vim-ingo-library'
Plug 'inkarkat/vim-mark'
Plug 'luochen1990/rainbow'
let g:rainbow_active = 1
Plug 'tpope/vim-fugitive'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-repeat'
" Plug 'tpope/vim-sleuth'
Plug 'Raimondi/yaifa'
let g:yaifa_max_lines = 6*1024
let g:yaifa_shiftwidth = 2
let g:yaifa_tabstop = 2
let g:yaifa_expandtab = 1
Plug 'unblevable/quick-scope'
Plug 'svermeulen/vim-yoink'
Plug 'kien/ctrlp.vim'
let g:ctrlp_map = '<leader>p'
if v:version >= 802
Plug 'psliwka/vim-smoothie'
endif
set nocscopeverbose
Plug 'joe-skb7/cscope-maps'
Plug 'junegunn/gv.vim'
call plug#end()
function! IsPluginLoaded(name)
return has_key(g:plugs, a:name)
endfunction
else
function! IsPluginLoaded(name)
return 0
endfunction
endif
" Setup Vundle plugins
if 0 && isdirectory(expand('~/.vim/bundle/Vundle.vim'))
filetype off
set rtp+=expand('~/.vim/bundle/Vundle.vim')
let vimdir = '~/.vim/bundle'
if has('win32unix')
" Use mixed path on Cygwin so that Windows git works
let vimdir = substitute(system('cygpath -m ' . vimdir), '\n\+$', '', '')
endif
call vundle#begin(vimdir)
Plugin 'VundleVim/Vundle.vim'
" Plugins
Plugin 'git://github.com/inkarkat/vim-ingo-library'
Plugin 'git://github.com/inkarkat/vim-mark'
Plugin 'git://github.com/luochen1990/rainbow'
let g:rainbow_active = 1
call vundle#end()
endif
filetype plugin on
"filetype indent off " Builtin indents are weird...
syntax enable
set title
set showcmd
set nonumber
set showmatch
set nodigraph
set wrap
set background=dark
set complete-=i " Too slow...
set history=10000
" Scroll options
set scrolloff=3
set sidescrolloff=5
" Search tags from current directory up first, then from file's directory
set tags=tags;/,./tags;/
" Search options
set hlsearch
set noincsearch
set nowrapscan
" Silence
set noerrorbells
set visualbell
set t_vb=
" Speedup rendering
set lazyredraw
set ttyfast
set lazyredraw
set list
set listchars=precedes:<,extends:>,tab:▸\ ,trail:▫
" Disable backup files
set nobackup
" Dictionary (install wamerican)
set dictionary=/usr/share/dict/words
" Special keys
if &term == "cygwin"
set t_kD=[3~
endif
set backspace=indent,eol,start
" Autocomplete menu
set wildmenu
set wildignore+=*.swp,*~,*.o,*.obj,*.py[co],*.class
" Nicer status line
set ruler
set laststatus=2
highlight StatusLine cterm=bold ctermfg=white ctermbg=blue
" Highlight current line
set cursorline
" Highlight 80 columns
au BufReadPost,BufNewFile *
\ if &ft=~'^\(c\|cpp\|java\|python\|perl\|vim\|sh\)$' |
\ set colorcolumn=80 | endif
" Enable mouse
if has('mouse')
set mouse=a
endif
function! MyToggleNumbering()
if &number && &relativenumber
set nonumber
set norelativenumber
elseif &number && ! &relativenumber
set relativenumber
elseif ! &number && &relativenumber
set number
else " ! &number && ! &relativenumber
set number
endif
endfunction
function! MyToggleLTPairs()
if !exists("g:ToggleLTPairs")
let g:ToggleLTPairs = 0
endif
let g:ToggleLTPairs = ! g:ToggleLTPairs
if g:ToggleLTPairs
set matchpairs+=<:>
else
set matchpairs-=<:>
endif
endfunction
" File explorer
let g:netrw_banner=0
let g:netrw_liststyle= 3
let g:netrw_preview=1
let g:netrw_alto=0
" Use syntax folds
set foldmethod=manual
"set foldmethod=syntax " Better but too slow...
set foldminlines=3
" Better leader
let mapleader = " "
" Custom bindings
inoremap <C-H> <Left>
inoremap <C-J> <Down>
inoremap <C-K> <Up>
inoremap <C-L> <Right>
" Save current buffer
nnoremap <F2> :w!<CR>
inoremap <F2> <Esc>:w!<CR>a
" Toggle line numbers
nnoremap <F1> :call MyToggleNumbering()<CR>
" Toggle case-sensitive search
nnoremap <Leader>i :set ic!<CR>
" Navigate errors/vimgrep results
nnoremap <F3> :cprev<CR>
inoremap <F3> <Esc>:cprev<CR>
nnoremap <F4> :cnext<CR>
inoremap <F4> <Esc>:cnext<CR>
" Navigate buffers
nnoremap <F5> :prev<CR>
inoremap <F5> <Esc>:prev<CR>a
nnoremap <F6> :next<CR>
inoremap <F6> <Esc>:next<CR>a
" Navigate windows
nnoremap <F7> <C-W>k<C-W>_
inoremap <F7> <Esc><C-W>k<C-W>_a
nnoremap <F8> <C-W>j<C-W>_
inoremap <F8> <Esc><C-W>j<C-W>_a
nnoremap <S-F7> <C-W>h<C-W>\|
inoremap <S-F7> <Esc><C-W>h<C-W>\|a
nnoremap <S-F8> <C-W>l<C-W>\|
inoremap <S-F8> <Esc><C-W>l<C-W>\|a
nnoremap <C-W>M <C-W>\| <C-W>_
nnoremap <C-W>m <C-W>=
" Navigate tabs
nnoremap <C-F7> :tabprev<CR>
inoremap <C-F7> <Esc>:tabprev<CR>
nnoremap <C-F8> :tabnext<CR>
inoremap <C-F8> <Esc>:tabnext<CR>
" Save and exit
nnoremap <F10> <Esc>:x<CR>
inoremap <F10> <Esc>:x<CR>
nnoremap <S-F10> <Esc>:xa<CR>
inoremap <S-F10> <Esc>:xa<CR>
" Discard and exit
nnoremap <F11> <Esc>:q!<CR>
inoremap <F11> <Esc>:q!<CR>
nnoremap <S-F11> <Esc>:qa!<CR>
inoremap <S-F11> <Esc>:qa!<CR>
" Alias for Esc
inoremap jj <Esc>
" Alias to toggle hlsearch
nnoremap <Leader><Space> :set hlsearch!<CR>
" Alias for YRShow
nnoremap <Leader>y :YRShow<CR>
" Edit binary using xxd-format
augroup Binary
au!
au BufReadPre *.bin,*.o,*.obj,*.exe let &bin=1
au BufReadPost *.bin,*.o,*.obj,*.exe if &bin | exe '%!xxd' | set ft=xxd | endif
au BufWritePre *.bin,*.o,*.obj,*.exe if &bin | exe '%!xxd -r' | endif
au BufWritePost *.bin,*.o,*.obj,*.exe if &bin | exe '%!xxd' | set nomod | endif
augroup END
" Abbreviations
iabbrev binsh #!/bin/sh<CR><C-O>:s/^#//e<CR><CR>set -eu<CR>set -x<CR>
iabbrev binpl #!/usr/bin/env perl<CR><C-O>:s/^#//e<CR><CR>use strict;<CR>use warnings;<CR>
iabbrev binpy #!/usr/bin/env python3<CR><C-O>:s/^#//e<CR><CR>import sys<CR>import re<CR>
iabbrev helloworldc #include <stdio.h><CR>#include <string.h><CR>#include <stdlib.h><CR><CR>int main() {<CR><C-O>d0 printf("Hello world!\n");<CR><C-O>d0 return 0;<CR>}
iabbrev leetcodecc #include <stdio.h><CR>#include <string.h><CR>#include <stdlib.h><CR>#include <assert.h><CR>#include <limits.h><CR><CR>#include <vector><CR>#include <string><CR>#include <set><CR>#include <map><CR>#include <unordered_map><CR>#include <unordered_set><CR>#include <numeric><CR><CR>using namespace std;<CR><CR>int main() {<CR><C-O>d0 Solution sol;<CR><C-O>d0 return 0;<CR>}
" CtrlP aliases
if IsPluginLoaded('ctrlp.vim')
nnoremap <Leader>h :call SwitchHeader()<CR>
nnoremap <Leader>o :CtrlPMRUFiles<CR>
" CtrlP-based header switching (https://github.com/kien/ctrlp.vim/issues/412)
function! SwitchHeader(...)
let l:ext = expand('%:e')
if l:ext == 'h' || l:ext == 'hpp' || l:ext == 'hh'
let l:ext = 'c'
elseif l:ext == 'c' || l:ext == 'cpp' || l:ext == 'cc'
let l:ext = 'h'
else
let l:ext = ''
endif
let g:ctrlp_default_input = expand('%:t:r') . "." . l:ext
call ctrlp#init(0)
let l:split = get(a:, 1, "i")
if l:split == 'h'
call feedkeys("\<C-s>", "t")
elseif l:split == 'v'
call feedkeys("\<C-v>", "t")
else
call feedkeys("\<CR>", "t")
endif
unlet g:ctrlp_default_input
endfunction
endif
" Yoink mappings
if IsPluginLoaded('vim-yoink')
nmap <c-n> <plug>(YoinkPostPasteSwapBack)
nmap <c-p> <plug>(YoinkPostPasteSwapForward)
nmap p <plug>(YoinkPaste_p)
nmap P <plug>(YoinkPaste_P)
endif
" Speedup Smoothie
let g:smoothie_base_speed = 25
" Search visual selection
" (from http://zzapper.co.uk/vimtips.html)
vmap <silent> // y/<C-R>=escape(@", '\\/.*$^~[]')<CR><CR>
" Enter vim commands in Cyrillic mode
set langmap=ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯ;ABCDEFGHIJKLMNOPQRSTUVWXYZ,фисвуапршолдьтщзйкыегмцчня;abcdefghijklmnopqrstuvwxyz