-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.vim
More file actions
651 lines (529 loc) · 16.6 KB
/
init.vim
File metadata and controls
651 lines (529 loc) · 16.6 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
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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
" vim: fdm=marker ts=2 sts=2 sw=2 fdl=0
set nocompatible
"get vim or nvim folder
let g:VIMPATH=fnamemodify(expand('<sfile>'), ':h')
let s:cache_dir = g:VIMPATH.'/.cache'
" Use English interface.
language message C
" dotvim settings {{{
let s:cache_dir = g:VIMPATH.'/.cache'
syntax on
let s:settings = {}
let s:settings.default_indent = 2
let s:settings.max_column = 120
let s:settings.enable_cursorcolumn=0
let g:author="Alberto Caro alberto.caro.m@gmail.com"
let g:ycm_confirm_extra_conf = 0
if !has('nvim')
set term=screen-256color
endif
" Set augroup.
augroup MyAutoCmd
autocmd!
augroup END
"}}}
" detect OS {{{
let s:is_windows = has('win32') || has('win64')
let s:is_cygwin = has('win32unix')
let s:is_macvim = has('gui_macvim')
let s:is_windows = has('win32') || has('win64')
function! IsWindows() abort
return s:is_windows
endfunction
function! IsMac() abort
return !s:is_windows && !has('win32unix')
\ && (has('mac') || has('macunix') || has('gui_macvim')
\ || (!executable('xdg-open') && system('uname') =~? '^darwin'))
endfunction
if IsWindows()
" Exchange path separator.
set shellslash
endif
"}}}
" functions {{{
function! s:get_cache_dir(suffix) "{{{
return resolve(expand(s:cache_dir . '/' . a:suffix))
endfunction "}}}
function! Source(begin, end) "{{{
let lines = getline(a:begin, a:end)
for line in lines
execute line
endfor
endfunction "}}}
function! Preserve(command) "{{{
" preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" do the business:
execute a:command
" clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction "}}}
function! StripTrailingWhitespace() "{{{
call Preserve("%s/\\s\\+$//e")
endfunction "}}}
function! EnsureExists(path) "{{{
if !isdirectory(expand(a:path))
call mkdir(expand(a:path))
endif
endfunction "}}}
function! MaximizeToggle() "{{{
if exists("s:maximize_session")
exec "source " . s:maximize_session
call delete(s:maximize_session)
unlet s:maximize_session
let &hidden=s:maximize_hidden_save
unlet s:maximize_hidden_save
else
let s:maximize_hidden_save = &hidden
let s:maximize_session = tempname()
set hidden
exec "mksession! " . s:maximize_session
only
endif
endfunction "}}}
function! CloseWindowOrKillBuffer() "{{{
let number_of_windows_to_this_buffer = len(filter(range(1, winnr('$')), "winbufnr(v:val) == bufnr('%')"))
" never bdelete a nerd tree
if matchstr(expand("%"), 'NERD') == 'NERD'
wincmd c
return
endif
if number_of_windows_to_this_buffer > 1
wincmd c
else
bdelete
endif
endfunction "}}}
"}}}
function! DeleteActualFile()
:call delete(expand("%"))
:BD!
endfunction
command! DeleteActualFile :call DeleteActualFile()
" base configuration {{{
let mapleader = ","
let g:mapleader = ","
set timeoutlen=500 "mapping timeout
set ttimeoutlen=50 "keycode timeout
set mouse=a "enable mouse
set mousehide "hide when characters are typed
set history=1000 "number of command lines to remember
set ttyfast "assume fast terminal connection
set viewoptions=folds,options,cursor,unix,slash "unix/windows compatibility
set encoding=utf-8 "set encoding for text
if exists('$TMUX')
set clipboard=
else
set clipboard=unnamed "sync with OS clipboard
endif
set hidden "allow buffer switching without saving
set autoread "auto reload if file saved externally
set fileformats+=mac "add mac to auto-detection of file format line endings
set nrformats-=octal "always assume decimal numbers
set showcmd
set tags=tags;/
set showfulltag
set modeline
set modelines=5
if s:is_windows && !s:is_cygwin
" ensure correct shell in gvim
set shell=c:\windows\system32\cmd.exe
endif
if $SHELL =~ '/fish$'
" VIM expects to be run from a POSIX shell.
set shell=sh
endif
set noshelltemp "use pipes
" whitespace
set backspace=indent,eol,start "allow backspacing everything in insert mode
set autoindent "automatically indent to match adjacent lines
set expandtab "spaces instead of tabs
set smarttab "use shiftwidth to enter tabs
let &tabstop=s:settings.default_indent "number of spaces per tab for display
let &softtabstop=s:settings.default_indent "number of spaces per tab in insert mode
let &shiftwidth=s:settings.default_indent "number of spaces when indenting
set list "highlight whitespace
set listchars=tab:→\ ,eol:↲,nbsp:␣,trail:•,extends:⟩,precedes:⟨,conceal:Δ
set list
set shiftround
set linebreak
let &showbreak='↪ '
set scrolloff=1 "always show content after scroll
set scrolljump=5 "minimum number of lines to scroll
set display+=lastline
set wildmenu "show list for autocomplete
set wildmode=list:full
set wildignorecase
set splitbelow
set splitright
" disable sounds
set noerrorbells
set novisualbell
set t_vb=
" searching
set hlsearch "highlight searches
set incsearch "incremental searching
set ignorecase "ignore case for searching
set smartcase "do case-sensitive if there's a capital letter
:nmap \q :nohlsearch<CR>
if executable('ack')
set grepprg=ack\ --nogroup\ --column\ --smart-case\ --nocolor\ --follow\ $*
set grepformat=%f:%l:%c:%m
endif
if executable('ag')
set grepprg=ag\ --nogroup\ --column\ --smart-case\ --nocolor\ --follow
set grepformat=%f:%l:%c:%m
endif
let g:localvimrc_persistent=1
let g:localvimrc_persistence_file=g:VIMPATH . "/lvimrc_persistent"
let g:localvimrc_ask=1
" vim file/folder management {{{
" persistent undo
if exists('+undofile')
set undofile
let &undodir = s:get_cache_dir('undo')
endif
" backups
set backup
let &backupdir = s:get_cache_dir('backup')
" swap files
let &directory = s:get_cache_dir('swap')
set noswapfile
call EnsureExists(s:cache_dir)
call EnsureExists(&undodir)
call EnsureExists(&backupdir)
call EnsureExists(&directory)
"}}}
let mapleader = ","
"}}}
"Scripts pluggins {{{
"
if empty(g:VIMPATH .'/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(g:VIMPATH . '/bundle')
exec "source " . g:VIMPATH . "/plugins.vimrc"
" source ~/.vim/vimrc
"Add plugins to &runtimepath
call plug#end()
"}}}
" ui configuration {{{
set showmatch "automatically highlight matching braces/brackets/etc.
set matchtime=2 "tens of a second to show matching parentheses
set number
set lazyredraw
set laststatus=2
set noshowmode
set foldenable "enable folds by default
set foldmethod=syntax "fold via syntax of files
set foldlevelstart=99 "open all folds by default
let g:xml_syntax_folding=1 "enable xml folding
set cursorline
autocmd WinLeave * setlocal nocursorline
autocmd WinEnter * setlocal cursorline
let &colorcolumn=s:settings.max_column
if s:settings.enable_cursorcolumn
set cursorcolumn
autocmd WinLeave * setlocal nocursorcolumn
autocmd WinEnter * setlocal cursorcolumn
endif
if has('conceal')
set conceallevel=1
set listchars+=conceal:Δ
endif
if has('gui_running')
" open maximized
set lines=999 columns=9999
if s:is_windows
autocmd GUIEnter * simalt ~x
endif
set guioptions+=t "tear off menu items
set guioptions-=T "toolbar icons
if s:is_macvim
set gfn=Ubuntu_Mono:h14
set transparency=2
endif
if s:is_windows
set gfn=Ubuntu_Mono:h10
endif
if has('gui_gtk')
set gfn=Ubuntu\ Mono\ 11
endif
else
if $COLORTERM == 'gnome-terminal'
set t_Co=256 "why you no tell me correct colors?!?!
endif
if $TERM_PROGRAM == 'iTerm.app'
" different cursors for insert vs normal mode
if exists('$TMUX')
let &t_SI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=1\x7\<Esc>\\"
let &t_EI = "\<Esc>Ptmux;\<Esc>\<Esc>]50;CursorShape=0\x7\<Esc>\\"
else
let &t_SI = "\<Esc>]50;CursorShape=1\x7"
let &t_EI = "\<Esc>]50;CursorShape=0\x7"
endif
endif
endif
"}}}
" mappings {{{
" formatting shortcuts
nmap <leader>fef :call Preserve("normal gg=G")<CR>
nmap <leader>f$ :call StripTrailingWhitespace()<CR>
vmap <leader>s :sort<cr>
" eval vimscript by line or visual selection
nmap <silent> <leader>e :call Source(line('.'), line('.'))<CR>
vmap <silent> <leader>e :call Source(line('v'), line('.'))<CR>
" nnoremap <leader>w :w<cr>
" toggle paste
map <F6> :set invpaste<CR>:set paste?<CR>
" remap arrow keys
nnoremap <left> :bprev<CR>
nnoremap <right> :bnext<CR>
nnoremap <up> :tabnext<CR>
nnoremap <down> :tabprev<CR>
" smash escape
inoremap jk <esc>
inoremap kj <esc>
nnoremap <leader><space> :let @/ = ""<CR>
" mac version
"nnoremap <leader>cfn :let @*=expand("%").":".line(".")
" linux version
nnoremap <leader>cfn :let @+=expand("%").":".line(".")
if mapcheck('<space>/') == ''
nnoremap <space>/ :vimgrep //gj **/*<left><left><left><left><left><left><left><left>
endif
" sane regex {{{
nnoremap / /\v
vnoremap / /\v
nnoremap ? ?\v
vnoremap ? ?\v
nnoremap :s/ :s/\v
" }}}
" command-line window {{{
nnoremap q: q:i
nnoremap q/ q/i
nnoremap q? q?i
" }}}
" folds {{{
nnoremap zr zr:echo &foldlevel<cr>
nnoremap zm zm:echo &foldlevel<cr>
nnoremap zR zR:echo &foldlevel<cr>
nnoremap zM zM:echo &foldlevel<cr>
" }}}
" screen line scroll
nnoremap <silent> j gj
nnoremap <silent> k gk
" auto center {{{
nnoremap <silent> n nzz
nnoremap <silent> N Nzz
nnoremap <silent> * *zz
nnoremap <silent> # #zz
nnoremap <silent> g* g*zz
nnoremap <silent> g# g#zz
nnoremap <silent> <C-o> <C-o>zz
nnoremap <silent> <C-i> <C-i>zz
"}}}
" reselect visual block after indent
vnoremap < <gv
vnoremap > >gv
" reselect last paste
nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'
" find current word in quickfix
nnoremap <leader>fw :execute "vimgrep ".expand("<cword>")." %"<cr>:copen<cr>
" find last search in quickfix
nnoremap <leader>ff :execute 'vimgrep /'.@/.'/g %'<cr>:copen<cr>
" shortcuts for windows {{{
nnoremap <leader>v <C-w>v<C-w>l
nnoremap <leader>s <C-w>s
nnoremap <leader>vsa :vert sba<cr>
if has('nvim')
let $NVIM_TUI_ENABLE_CURSOR_SHAPE=1
" Hack to get C-h working in neovim
nmap <BS> <C-W>h
tnoremap <Esc> <C-\><C-n>
endif
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
"}}}
" tab shortcuts
map <leader>tn :tabnew<CR>
map <leader>tc :tabclose<CR>
" make Y consistent with C and D. See :help Y.
nnoremap Y y$
" hide annoying quit message
nnoremap <C-c> <C-c>:echo<cr>
" window killer
nnoremap <silent> Q :call CloseWindowOrKillBuffer()<cr>
" quick buffer open
nnoremap gb :ls<cr>:e #
" general
nmap <leader>l :set list! list?<cr>
nnoremap <BS> :set hlsearch! hlsearch?<cr>
map <F10> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<'
\ . synIDattr(synID(line("."),col("."),0),"name") . "> lo<"
\ . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">"<CR>
" helpers for profiling {{{
nnoremap <silent> <leader>DD :exe ":profile start profile.log"<cr>:exe ":profile func *"<cr>:exe ":profile file *"<cr>
nnoremap <silent> <leader>DP :exe ":profile pause"<cr>
nnoremap <silent> <leader>DC :exe ":profile continue"<cr>
nnoremap <silent> <leader>DQ :exe ":profile pause"<cr>:noautocmd qall!<cr>
"}}}
" Toggle Maximize split buffer
nnoremap <C-W>z :call MaximizeToggle()<CR>
nnoremap <C-W>Z :call MaximizeToggle()<CR>
nnoremap <leader>T :Commentary <cr>
vnoremap <leader>T :Commentary <cr>
nnoremap <leader>cn :cnext <cr>
nnoremap <leader>cp :cprevious<cr>
nnoremap <leader>co :copen<cr>
nnoremap <leader>cc :cclose<cr>
nnoremap <leader>cf :cfirst<cr>
nnoremap <leader>cc :clast<cr>
if has('nvim')
tnoremap <esc><esc> <C-\><C-n>
endif
" shortcuts to edit configuration or save it.
" :nnoremap <leader>ev :vsplit $MYVIMRC<cr>
" :nnoremap <leader>sv :source $MYVIMRC<cr>
:nnoremap <leader>ev :vsplit $VIMPATH."/init.vim"<cr>
:nnoremap <leader>sv :source $MYVIMRC<cr>
:nnoremap <leader>w :w<cr>
:nnoremap <leader>q :q<cr>
:nnoremap <leader>q! :q!<cr>
:nnoremap <leader>qa :qa<cr>
:nnoremap <leader>m :make<cr>
:nnoremap <leader>= mqggVG='qm<esc>q
:nnoremap <leader>0 mqggVG='qm<esc>q
if !has("nvim")
:nnoremap <leader>s :shell <cr>
endif
"}}}
"
if (exists('+colorcolumn'))
set colorcolumn=80
highlight ColorColumn ctermbg=9
endif
" autocmd {{{
" go back to previous position of cursor if any
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe 'normal! g`"zvzz' |
\ endif
autocmd FileType js,scss,css autocmd BufWritePre <buffer> call StripTrailingWhitespace()
autocmd FileType css,scss setlocal foldmethod=marker foldmarker={,}
autocmd FileType css,scss nnoremap <silent> <leader>S vi{:sort<CR>
autocmd FileType python setlocal foldmethod=indent
autocmd FileType markdown setlocal nolist
autocmd FileType vim setlocal fdm=indent keywordprg=:help
autocmd FileType lua setlocal makeprg=luacheck\ \%
au BufNewFile,BufRead *.js, *.html, *.css
\ set tabstop=2
\ set softtabstop=2
\ set shiftwidth=2
au BufNewFile,BufRead *.py
\ set tabstop=4
\ set softtabstop=4
\ set shiftwidth=4
\ set textwidth=79
\ set expandtab
\ set autoindent
\ set fileformat=unix
"}}}
"
"exec 'colorscheme ' . 'wombat256mod'
" Theme
syntax enable
if has ('nvim')
let $NVIM_TUI_ENABLE_TRUE_COLOR=1
else
set t_Co=256
endif
"{{{
if has('gui_running')
" set background=dark
" colorscheme solarized
colorscheme desert
else
" colorscheme zenburn
colorscheme OceanicNext
endif
"}}}
set background=dark
function! BuffersCloseButCurrent()
let curr = bufnr("%")
let last = bufnr("$")
if curr > 1 | silent! execute "1,".(curr-1)."bd" | endif
if curr < last | silent! execute (curr+1).",".last."bd" | endif
endfunction
"" Fold Asciidoc files at sections and using nested folds for subsections
" compute the folding level
function! AsciidocLevel()
if getline(v:lnum) =~ '^== .*$'
return ">1"
endif
if getline(v:lnum) =~ '^=== .*$'
return ">2"
endif
if getline(v:lnum) =~ '^==== .*$'
return ">3"
endif
if getline(v:lnum) =~ '^===== .*$'
return ">4"
endif
if getline(v:lnum) =~ '^====== .*$'
return ">5"
endif
if getline(v:lnum) =~ '^======= .*$'
return ">6"
endif
return "="
endfunction
" run the folding level method when asciidoc is here
autocmd Syntax asciidoc setlocal foldexpr=AsciidocLevel()
" enable folding method: expression on asciidoc
autocmd Syntax asciidoc setlocal foldmethod=expr
" start with text unfolded all the way
autocmd BufRead *.adoc normal zR
autocmd BufRead *.asciidoc normal zR
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
autocmd FileType yml setlocal ts=2 sts=2 sw=2 expandtab
function CleanCurrentFile()
%s/\%ua0/ /g
endfunction
command! CleanCurrentFile :call CleanCurrentFile()
" TODO following does not work as folding is lost up reloading
" autocmd Syntax asciidoc normal zR
command! Capitalize :normal! "_yiwvgU
set showbreak=↳
set hls
" if has('gui_running')
" set listchars=tab:▶\ ,trail:·,extends:\#,nbsp:.
" else
" set listchars=tab:>.,trail:.,extends:\#,nbsp:.
" endif
let g:gtest#gtest_command = ""
function! ACMGTestCmd(gtest_command)
let g:acm#gtest_command = a:gtest_command
endfunction
function! ACMGTEST()
let oldmakeprg = &makeprg
let olderrorformat=&errorformat
set errorformat=%f:%l:\ %m
let &makeprg=g:acm#gtest_command
silent execute ":make"
let &makeprg=oldmakeprg
let &errorformat=olderrorformat
silent execute ":copen"
silent execute ":redraw!"
endfunction
command! AcmGTest :call ACMGTEST()
command! -nargs=1 -complete=file AcmGTestCmd call ACMGTestCmd(<f-args>)
" set <Esc><Esc> as keybinding to go terminal normal mode
tnoremap <Esc><Esc> <C-w>N