-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathvimrc
410 lines (316 loc) · 10.2 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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
" Lays <[email protected]>
set nocompatible " be iMproved
"==============================================================
"> vim-plug
"==============================================================
" Check if vim-plug installed
if empty(glob('~/.vim/autoload/plug.vim'))
echo "vim-plug not installed!"
if confirm("Install vim-plug now?", "&Yes\n&No", 1)==1
silent !curl -fLo ~/.vim/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source $MYVIMRC
endif
else
call plug#begin('~/.vim/plugged')
" --- Plugins ---
Plug 'vim-scripts/L9'
Plug 'othree/vim-autocomplpop'
Plug 'ctrlpvim/ctrlp.vim'
Plug 'majutsushi/tagbar'
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'L4ys/molokai'
Plug 'tpope/vim-surround'
Plug 'sheerun/vim-polyglot'
Plug 'rhysd/accelerated-jk'
if has("mac") || has("macunix")
Plug 'msanders/cocoa.vim'
endif
call plug#end()
endif
"==============================================================
"> General
"==============================================================
" Sets how many lines of history VIM has to remember
set history=200
" Enable filetype plugins
filetype plugin on
filetype indent on
" Set to auto read when a file is changed from the outside
set autoread
" Set leader key to ','
let mapleader = ","
" Set utf8 as standard encoding
let $LANG="en_US.utf-8"
set encoding=utf-8
set fileencodings=usc-bom,utf-8,big5,taiwan,chinese,default,latin1
" Turn off expand tab in makefile
autocmd FileType make setlocal noexpandtab
" Indent 2 for html / css
autocmd BufNewFile,BufRead *.html,*.htm,*.css setlocal tabstop=2 shiftwidth=2
"==============================================================
"> VIM user interface
"==============================================================
" Set 7 lines to the cursor - when moving vertically using j/k
set so=7
" Turn on the WiLd menu
set wildmenu
" Ignore compiled files
set wildignore=*.o,*~,*.pyc,*.class,*.obj
" Always show current position
set ruler
" Height of the command bar
set cmdheight=1
" A buffer becomes hidden when it is abandoned
set hid
" Configure backspace so it acts as it should act
set backspace=eol,start,indent
set whichwrap+=<,>,h,l
" Ignore case when searching
set ignorecase
" When searching try to be smart about cases
set smartcase
" Highlight search results
set hlsearch
" Makes search act like search in modern browsers
set incsearch
" Don't redraw while executing macros (good performance config)
set lazyredraw
" u got a fast terminal
set ttyfast
" Prevent long line lag
set synmaxcol=512
" For regular expressions turn magic on
set magic
" Show matching brackets when text indicator is over them
set showmatch
" How many tenths of a second to blink when matching brackets
set mat=2
" No annoying sound on errors
set noerrorbells
set novisualbell
set t_vb=
set tm=500
" Always show the status line
set laststatus=2
" hold shift to select and copy text
" set mouse=a
"==============================================================
"> Colors and Fonts
"==============================================================
" Enable syntax highlighting
syntax enable
set shortmess=atI " remove start screen
set background=dark
set number
set cursorline
set t_Co=256
let g:rehash256 = 1
if filereadable(expand('~/.vim/plugged/molokai/colors/molokai.vim'))
let g:molokai_original = 1
colorscheme molokai
endif
"==============================================================
"> Files, backups and undo
"==============================================================
" Turn backup off, since most stuff is in SVN, git et.c anyway...
set nobackup
set nowb
set noswapfile
set noundofile
"==============================================================
"> Text, tab and indent related
"==============================================================
" Use spaces instead of tabs
set expandtab
" Be smart when using tabs ;)
set smarttab
" 1 tab == 4 spaces
set shiftwidth=4
set tabstop=4
" Linebreak on 500 characters
set lbr
set tw=500
set ai " Auto indent
set si " Smart indent
set wrap " Wrap lines
" Remove preview window
set completeopt-=preview
" Auto save and load fold setting
au BufWinLeave *.* silent mkview
au BufWinEnter *.* silent loadview
" Hightlight from start of file
au BufEnter * :syntax sync fromstart
"==============================================================
"> Visual mode related
"==============================================================
" Visual mode pressing * or # searches for the current selection
" Super useful! From an idea by Michael Naumann
vnoremap <silent> * :call VisualSelection('f')<CR>
vnoremap <silent> # :call VisualSelection('b')<CR>
"==============================================================
"> Moving around, tabs, windows and buffers
"==============================================================
" Treat long lines as break lines (useful when moving around in them)
map j gj
map k gk
" Disable highlight when <leader><cr> is pressed
map <leader><CR> :noh<CR>
" Open a newtab with file
noremap <leader>t :tabedit <C-R>=expand("%:p:h")<CR>
" Switch to next tab
noremap <leader><leader> :tabnext<CR>
" Switch to previous tab
noremap <leader>. :tabprevious<CR>
" Switch between tabs
for i in range(1, 9)
exec 'nmap <leader>'.i.' '.i.'gt<CR>'
endfor
" Return to last edit position when opening files (You want this!)
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal! g`\"" |
\ endif
" Remember info about open buffers on close
set viminfo^=%
"==============================================================
"> Editing mappings
"==============================================================
" Remap VIM 0 to first non-blank character
map 0 ^
" Delete trailing white space on save, useful for Python and CoffeeScript ;)
func! DeleteTrailingWS()
exe "normal mz"
%s/\s\+$//ge
exe "normal `z"
endfunc
"autocmd BufWrite *.py,*.coffee,*.js,*.html,*.c,*.cpp,*.xm :call DeleteTrailingWS()
"==============================================================
"> Misc
"==============================================================
" Remove the Windows ^M - when the encodings gets messed up
noremap <Leader>m mmHmt:%s/<C-V><cr>//ge<cr>'tzt'm
noremap <Leader>M :%s/\r/\r/g<CR>
"==============================================================
"> Helper functions
"==============================================================
function! CmdLine(str)
exe "menu Foo.Bar :" . a:str
emenu Foo.Bar
unmenu Foo
endfunction
function! VisualSelection(direction) range
let l:saved_reg = @"
execute "normal! vgvy"
let l:pattern = escape(@", '\\/.*$^~[]')
let l:pattern = substitute(l:pattern, "\n$", "", "")
if a:direction == 'b'
execute "normal ?" . l:pattern . "^M"
elseif a:direction == 'gv'
call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.')
elseif a:direction == 'replace'
call CmdLine("%s" . '/'. l:pattern . '/')
elseif a:direction == 'f'
execute "normal /" . l:pattern . "^M"
endif
let @/ = l:pattern
let @" = l:saved_reg
endfunction
let $in_hex=0
function! ToggleHex()
"set binary
"set noeol
if $in_hex>0
:%!xxd -r
let $in_hex=0
else
:%!xxd
let $in_hex=1
endif
endfunction
"==============================================================
"> Other
"==============================================================
" Auto reload vimrc when editing it
autocmd! bufwritepost .vimrc source ~/.vimrc
" Allow saving of files as sudo when I forgot to start vim using sudo.
cmap w!! w !sudo tee > /dev/null %
" Copy to system clipboard by Ctrl-C
if has("mac") || has("macunix")
vmap <silent><C-c> :w !pbcopy<CR><CR>
noremap <silent><leader>c :w !pbcopy<CR><CR>
endif
" Daily routines
noremap <leader>z :w<CR><C-Z>
noremap <leader>w :w<CR>
noremap <leader>x :x<CR>
noremap <leader>q :q!<CR>
noremap <leader>e :edit <C-R>=expand("%:p:h")<CR>/
" Split with file
noremap <leader>s :split <C-R>=expand("%:p:h")<CR>/
noremap <leader>v :vsplit <C-R>=expand("%:p:h")<CR>/
" Redraw, useful in terminal when screen getr messed up
nnoremap <leader>rr :redraw!<CR>
" <F2> toggles paste mode
set pastetoggle=<F2>
" <F3> toggles line number
noremap <silent> <F3> :set nu!<CR>
imap <silent><F3> <C-O><F3>
" <F4> toggles line wrap
noremap <silent> <F4> :set wrap!<CR>
imap <silent><F4> <C-O><F4>
" <F5> toggles hex edit
noremap <silent> <F5> :call ToggleHex()<CR>
imap <silent><F5> <C-O><F5>
" <F6> syntax sync
noremap <F6> <Esc>:syntax sync fromstart<CR>
imap <silent><F6> <C-O><F6>
" <F7> spelling check
noremap <silent> <F7> :set spell!<CR>
imap <silent><F7> <C-O><F7>
" <F10> toggles foldenable
noremap <silent> <F10> :set foldenable!<CR>
imap <silent> <F10> <C-O><F10>
" <F12> toggles tagbar
noremap <silent> <F12> :TagbarToggle<CR>
imap <silent> <F12> <C-O><F12>
"==============================================================
"> Plugins
"==============================================================
" ctrlp
let g:ctrlp_custom_ignore = {
\ 'dir': '\.git$\|\.hg$:|\.svn$\|\.yardoc\|public\/images\|public\/system\|data\|log\|tmp$',
\ 'file': '\.exe$\|\.so$\|\.dat$'
\ }
let g:ctrlp_show_hidden = 1
let g:ctrlp_cmd = 'CtrlPMRU'
" leader + b to open buffer list with ctrlp
nmap <leader>b :CtrlPBuffer<CR>
" airline
set ttimeoutlen=50
set noshowmode
if !exists('g:airline_symbols')
let g:airline_symbols = {}
endif
let g:airline_theme = 'powerlineish'
let g:airline_powerline_fonts = 0
let g:airline_left_sep = ''
let g:airline_left_alt_sep = ''
let g:airline_right_sep = ''
let g:airline_right_alt_sep = ''
let g:airline_symbols.linenr = '¶'
let g:airline_symbols.branch = '⎇'
let g:airline#extensions#branch#enabled = 1
let g:airline#extensions#branch#empty_message = ''
let g:airline#extensions#whitespace#enabled = 0
" UltiSnips
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<c-b>"
let g:UltiSnipsJumpBackwardTrigger="<c-z>"
let g:polyglot_disabled = ['python']
" jk
nmap j <Plug>(accelerated_jk_gj)
nmap k <Plug>(accelerated_jk_gk)