-
Notifications
You must be signed in to change notification settings - Fork 2
/
big.vim
501 lines (376 loc) · 14 KB
/
big.vim
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
" ----------------------------------------------------------------------------
" Lean 'n' Clean Neovim Config
" ----------------------------------------------------------------------------
call plug#begin()
" ----------------------------------------------------------------------------
" Basic Vim Configuration
" ----------------------------------------------------------------------------
let g:vimrcPath = $MYVIMRC
let g:vimPath = system('realpath '.g:vimrcPath)
let g:vimDir = fnamemodify(g:vimPath, ':h')
let g:plugDir = g:vimDir.'/plugged'
let mapleader = "," " Set mapleader
let g:mapleader = ","
set mouse=a " Allow mouse usage
set mousehide
set history=1000 " Remember everything
set undolevels=1000
set encoding=utf-8 " Set right encoding and formats
set fileformat=unix
set nrformats-=octal
set spelllang=en_us,fr " Spell check english and french
set hidden " Deal nicely with buffers and switch without saving
set autoread
set modeline " Allow modeline for per file formating using
set modelines=5
set backspace=indent,eol,start " Makes backspace behave like most editors
set clipboard+=unnamedplus
set hlsearch " Highlight search
set incsearch " Highlight pattern matches as you type
set ignorecase " Ignore case when using a search pattern
set smartcase " Override 'ignorecase' when pattern has upper case character
" Set grep tool
if executable('ack')
set grepprg=ack\ --nogroup\ --column\ --smart-case\ --nocolor\ --follow\ $*
set grepformat=%f:%l:%c:%m
endif
" ----------------------------------------------------------------------------
" Basic UI Configuration
" ----------------------------------------------------------------------------
set number " Show line numbers
set showcmd " Show last command
set lazyredraw " Don't redraw when not needed
set laststatus=2 " Always show the status line
set scrolloff=10 " Keep cursor from reaching end of screen
set noshowmode " Hide the mode on last line as we use Vim Airline
set cursorline " Highlight current line
autocmd WinLeave * setlocal nocursorline
autocmd WinEnter * setlocal cursorline
set autoindent " Auto indent line on CR
set smarttab " Add tab and backspace like you'd like to
set shiftround " Always indent with a multiple of shiftwidth
set tabstop=4 " Default indentation is 4 spaces long and uses tabs, not spaces...
set softtabstop=4
set shiftwidth=4
set noexpandtab
set list " Show invisible characters
"set listchars=tab:>-,trail:•,extends:❯,precedes:
set listchars=tab:\|\ ,trail:• ",eol:¶
"set listchars=tab:»·,trail:·
set linebreak " Show linebreaks
let &showbreak='↪ '
set showmatch " Hightlight brackets
set matchtime=2
set wildmenu " Tab complete commands
set wildmode=list:full " Show full list of commands
set wildignorecase
set wildignore+=*/.git/*,*/.hg/*,*/.svn/*,*/.idea/*,*/.DS_Store
set splitbelow " Split windows below
set splitright " Split windows right
set noerrorbells " Turn of error notifications
set novisualbell
set nofoldenable " Disable folding
set background=dark
" ----------------------------------------------------------------------------
" Unite Plugins
" ----------------------------------------------------------------------------
Plug 'Shougo/vimproc.vim', { 'do': 'make' }
Plug 'Shougo/neomru.vim'
Plug 'Shougo/unite.vim'
Plug 'Shougo/neoyank.vim'
" Unite setup
let g:unite_data_directory=g:vimDir.'/.cache/unite'
let g:unite_enable_start_insert=1
let g:unite_source_rec_max_cache_files=5000
let g:unite_prompt='» '
if executable('ack')
let g:unite_source_grep_command='ack'
let g:unite_source_grep_default_opts='--no-heading --no-color -a -C4'
let g:unite_source_grep_recursive_opt=''
endif
function! s:unite_settings()
imap <buffer> <C-j> <Plug>(unite_select_next_line)
imap <buffer> <C-k> <Plug>(unite_select_previous_line)
nmap <buffer> Q <plug>(unite_exit)
nmap <buffer> <esc> <plug>(unite_exit)
imap <buffer> <esc> <plug>(unite_exit)
endfunction
autocmd FileType unite call s:unite_settings()
" Set Unite leader
nmap <space> [unite]
nnoremap [unite] <nop>
" Set useful Unite mappings
nnoremap <silent> [unite]t :<C-u>Unite -auto-resize -buffer-name=files file<cr>
nnoremap <silent> [unite]y :<C-u>Unite history/yank -auto-resize -buffer-name=yanks<cr>
nnoremap <silent> [unite]l :<C-u>Unite -auto-resize -buffer-name=line line<cr>
nnoremap <silent> [unite]b :<C-u>Unite -auto-resize -buffer-name=buffers buffer<cr>
nnoremap <silent> [unite]m :<C-u>Unite -auto-resize -buffer-name=mappings mapping<cr>
" ----------------------------------------------------------------------------
" Core Plugins
" ----------------------------------------------------------------------------
Plug 'qpkorr/vim-bufkill'
Plug 'mhinz/vim-startify', {'on': 'Startify'}
Plug 'duff/vim-bufonly'
" Vim Startify setup
let g:startify_session_dir = g:vimDir.'/.cache/sessions'
let g:startify_change_to_vcs_root = 1
let g:startify_show_sessions = 1
nnoremap <F1> :Startify<cr>
" ----------------------------------------------------------------------------
" UI Plugins
" ----------------------------------------------------------------------------
Plug 'vim-airline/vim-airline'
Plug 'vim-airline/vim-airline-themes'
Plug 'zhaocai/GoldenView.Vim', {'on': '<Plug>ToggleGoldenViewAutoResize'}
Plug 'oblitum/rainbow'
" Vim Airline setup
let g:airline_powerline_fonts = 0
let g:airline#extensions#tabline#enabled = 1
" let g:airline#extensions#tabline#left_sep=' '
let g:airline#extensions#tabline#left_alt_sep='¦'
let g:airline#extensions#whitespace#mixed_indent_algo = 2
" GoldenView setup
let g:goldenview__enable_default_mapping=0
nmap <F4> <Plug>ToggleGoldenViewAutoResize
" Rainbow setup
au FileType c,cpp,objc,objcpp,python,javascript call rainbow#load()
" ----------------------------------------------------------------------------
" Autocompletion & Snippets Plugins
" ----------------------------------------------------------------------------
Plug 'Valloric/YouCompleteMe', { 'do': './install.py --clang-completer' }
Plug 'SirVer/ultisnips'
Plug 'ladislas/vim-snippets'
" YouCompleteMe setup
let g:ycm_autoclose_preview_window_after_completion = 1
let g:ycm_error_symbol = '>>'
let g:ycm_warning_symbol = '!!'
" UltiSnips setup
let g:UltiSnipsExpandTrigger='<c-e>'
let g:UltiSnipsJumpForwardTrigger='<c-j>'
let g:UltiSnipsJumpBackwardTrigger='<c-k>'
let g:UltiSnipsSnippetsDir=plugDir.'/vim-snippets/UltiSnips'
" ----------------------------------------------------------------------------
" Navigation Plugins
" ----------------------------------------------------------------------------
Plug 'mileszs/ack.vim'
Plug 'mbbill/undotree', {'on': 'UndotreeToggle'}
Plug 'scrooloose/nerdtree'
Plug 'Xuyuanp/nerdtree-git-plugin'
" Undotree setup
let g:undotree_WindowLayout='botright'
let g:undotree_SetFocusWhenToggle=1
nnoremap <silent> <F5> :UndotreeToggle<CR>
" NERDTree setup
let NERDTreeShowHidden=0
let NERDTreeQuitOnOpen=0
let g:NERDTreeUseSimpleIndicator=1
let NERDTreeShowLineNumbers=1
let NERDTreeChDirMode=2
let NERDTreeShowBookmarks=0
let NERDTreeIgnore=['\.hg', '.DS_Store']
let g:NERDTreeBookmarksFile = $HOME."/.config/nvim/.cache/NERDTree/NERDTreeShowBookmarks"
nnoremap <F2> :NERDTreeToggle<CR>
nnoremap <F3> :NERDTreeFind<CR>
" ----------------------------------------------------------------------------
" Editing Plugins
" ----------------------------------------------------------------------------
Plug 'editorconfig/editorconfig-vim'
Plug 'kristijanhusak/vim-multiple-cursors'
Plug 'tomtom/tcomment_vim'
Plug 'chrisbra/NrrwRgn'
Plug 'tpope/vim-endwise'
Plug 'jiangmiao/auto-pairs'
Plug 'tpope/vim-surround'
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-repeat'
Plug 'godlygeek/tabular'
Plug 'junegunn/vim-easy-align'
" Tabularize setup
nmap <Leader>a& :Tabularize /&<CR>
vmap <Leader>a& :Tabularize /&<CR>
nmap <Leader>a= :Tabularize /=<CR>
vmap <Leader>a= :Tabularize /=<CR>
nmap <Leader>a: :Tabularize /:<CR>
vmap <Leader>a: :Tabularize /:<CR>
nmap <Leader>a:: :Tabularize /:\zs<CR>
vmap <Leader>a:: :Tabularize /:\zs<CR>
nmap <Leader>a, :Tabularize /,<CR>
vmap <Leader>a, :Tabularize /,<CR>
nmap <Leader>a<Bar> :Tabularize /<Bar><CR>
vmap <Leader>a<Bar> :Tabularize /<Bar><CR>
" ----------------------------------------------------------------------------
" Language Specific Plugins
" ----------------------------------------------------------------------------
" Vim Polyglote
Plug 'sheerun/vim-polyglot'
let g:polyglot_disabled = ['markdown', 'c', 'cpp', 'h']
" C++
Plug 'octol/vim-cpp-enhanced-highlight', { 'for': ['cpp', 'c', 'h'] }
" Swift
Plug 'keith/swift.vim'
" Markdown
autocmd BufRead,BufNewFile *.md,*.markdown setlocal filetype=pandoc.markdown " Automatically set filetype for Markdown files"
Plug 'vim-pandoc/vim-pandoc', { 'for': ['markdown', 'pandoc.markdown', 'md'] }
Plug 'vim-pandoc/vim-pandoc-syntax', { 'for': ['markdown', 'pandoc.markdown', 'md'] }
Plug 'shime/vim-livedown', { 'for': ['markdown', 'pandoc.markdown', 'md'] }
" Pandoc setup
let g:pandoc#syntax#conceal#use = 0
let g:pandoc#syntax#conceal#blacklist = ['block', 'codeblock_start', 'codeblock_delim']
let g:pandoc#syntax#conceal#cchar_overrides = {'li': '*'}
let g:pandoc#formatting#equalprg = "pandoc -t gfm --wrap=none"
" Livedown setup
let g:livedown_autorun = 0
let g:livedown_open = 1
let g:livedown_port = 1337
let g:livedown_browser = "chrome"
map <leader>gm :call LivedownPreview()<CR>
" ----------------------------------------------------------------------------
" Text Object Plugins
" ----------------------------------------------------------------------------
" n/a
" ----------------------------------------------------------------------------
" Colors Themes
" ----------------------------------------------------------------------------
" Plug 'daylerees/colour-schemes'
Plug 'morhetz/gruvbox'
Plug 'effkay/argonaut.vim'
" Gruvbox setup
let g:gruvbox_bold = 0
" ----------------------------------------------------------------------------
" Source Control Management Plugins
" ----------------------------------------------------------------------------
Plug 'airblade/vim-gitgutter'
Plug 'tpope/vim-fugitive'
" Gitgutter setup
let g:gitgutter_realtime=0
" Fugitive setup
nnoremap <silent> <leader>gs :Gstatus<CR>
nnoremap <silent> <leader>gd :Gdiff<CR>
nnoremap <silent> <leader>gc :Gcommit<CR>
nnoremap <silent> <leader>gb :Gblame<CR>
nnoremap <silent> <leader>gl :Glog<CR>
nnoremap <silent> <leader>gp :Git push<CR>
nnoremap <silent> <leader>gw :Gwrite<CR>
nnoremap <silent> <leader>gr :Gremove<CR>
autocmd FileType gitcommit nmap <buffer> U :Git checkout -- <C-r><C-g><CR>
autocmd BufReadPost fugitive://* set bufhidden=delete
" ----------------------------------------------------------------------------
" Basic useful functions
" ----------------------------------------------------------------------------
function! PreserveCursorPosition(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 PreserveCursorPosition("%s/\\s\\+$//e")
endfunction
function! EnsureExists(path)
if !isdirectory(expand(a:path))
call mkdir(expand(a:path), 'p')
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
" ----------------------------------------------------------------------------
" Basic Backup
" ----------------------------------------------------------------------------
" Nice persistent undos
let &undodir=g:vimDir."/.cache/undo//"
set undofile
" Keep backups
let &backupdir=g:vimDir."/.cache/backup//"
set backup
" Keep swap files, can save your life"
let &directory=g:vimDir."/.cache/swap//"
set swapfile
call EnsureExists(g:vimDir.'/.cache')
call EnsureExists(&undodir)
call EnsureExists(&backupdir)
call EnsureExists(&directory)
call EnsureExists(g:vimDir.'/.cache/NERDTree/NERDTreeBookmarks')
" ----------------------------------------------------------------------------
" Mappings
" ----------------------------------------------------------------------------
" Call basic functions
nmap <leader>f$ :call StripTrailingWhitespace()<CR>
nmap <leader>fef :call PreserveCursorPosition("normal gg=G")<CR>
" Quick save
nnoremap <leader>w :w<cr>
" Add newline with return key
nmap <CR> o<Esc>
" Remap arrow keys
nnoremap <down> :tabprev<CR>
nnoremap <left> :bprev<CR>
nnoremap <right> :bnext<CR>
nnoremap <up> :tabnext<CR>
" Windows/Buffers motion keys
nnoremap <leader>v <C-w>v<C-w>l
nnoremap <leader>s <C-w>s
nnoremap <leader>vsa :vert sba<cr>
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
" Change cursor position in insert mode
inoremap <C-h> <left>
inoremap <C-l> <right>
inoremap <C-k> <up>
inoremap <C-j> <down>
if mapcheck('<space>/') == ''
nnoremap <space>/ :vimgrep //gj **/*<left><left><left><left><left><left><left><left>
endif
" Sane regex search
nnoremap / /\v
vnoremap / /\v
nnoremap ? ?\v
vnoremap ? ?\v
nnoremap :s/ :s/\v
" Turn search highlight on and off
nnoremap <BS> :set hlsearch! hlsearch?<cr>
" Screen line scroll
nnoremap <silent> j gj
nnoremap <silent> k gk
" Reselect visual block after indent
vnoremap < <gv
vnoremap > >gv
" Toggles smart indenting while pasting, A.K.A lifesaver
set pastetoggle=<F3>
" Reselect last paste
nnoremap <expr> gp '`[' . strpart(getregtype(), 0, 1) . '`]'
" 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 #
" Tab shortcuts
map <leader>tn :tabnew<CR>
map <leader>tc :tabclose<CR>
" Spell check on/off
nmap <silent> <leader>sp :set spell!<CR>
call plug#end()
" Set colorscheme
colorscheme gruvbox
" Finish tuning Vim
filetype plugin indent on
syntax on