-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.vimrc
574 lines (455 loc) · 17.1 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
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
" This vimrc uses folds
"
" zR open all folds
" zM close all folds
" za toggle fold at cursor position
" zj move down to start of next fold
" zk move up to end of previous fold
" vimrc command and mapping quick reference {{{1
" -----------------------------------------------------------------
"
" This is your vim configuration file. There are some shortcuts set
" up for you by default. Here are the highlights:
"
" The mapleader has been switched from '\' to ',' anytime you see
" <leader> that is what this refers to.
"
" <leader>t -- opens the fuzzy finder coverage mode
" <leader>h -- toggles the highlight search
" <leader>n -- toggles the line numbers
" <leader>T -- Open new buffer
" <leader>i -- toggles invisible characters
" <leader>\ -- toggle line wrapping
" <leader>y -- show the yankring
" <leader><Enter> -- opens a line at the current column (this is
" the reverse of J)
" <leader>c -- Switch between light and dark colors
" <leader>n -- Switch to next buffer
" <leader>p -- Switch to previous buffer
" jj -- alternative to <ESC>
" ; -- alternative to :
" ctrl + tab -- cycle through buffers/tabs
" <Enter> -- open a new line (non-insert)
" <S-Enter> -- open a new line above (non-insert)
" <leader>s -- Toggle spell checking
" <F2> -- Toggle smart indent on paste
" CTRL-= -- Make the current window taller
" CTRL-- (CTRL-DASH) -- Make the current window shorter
"
" I have set up some custom commands that might be of interest
"
" Shell -- Runs a shell command and places it in the
" scratch buffer
" TidyXML -- Runs tidy in XML mode on the current buffer
" TabStyle -- Set the tab style and number, :TabStyle space 4
" TerminalHere -- Opens the terminal to the directory of the
" current buffer
" General setting {{{1
" -----------------------------------------------------------------
" On Windows, also use '.vim' instead of 'vimfiles'; this makes synchronization
" across (heterogeneous) systems easier.
if has('win32') || has('win64')
set runtimepath=$HOME/.vim,$VIM/vimfiles,$VIMRUNTIME,$VIM/vimfiles/after,$HOME/.vim/after
endif
" FreeBSD security advisory for this one...
set nomodeline
" This setting prevents vim from emulating the original vi's
" bugs and limitations.
set nocompatible
" set the mapleader key
let mapleader = ","
let g:mapleader = ","
" set the default encoding
set enc=utf-8
" only increment numbers and letters
set nrformats=""
" Set the shell to sh, zsh and vim don't seem to play nice
set shell=sh
" set up jj as mode switch
map! jj <ESC>
" hide the backup and swap files
set backupdir=~/.backup/vim,.,/tmp
set directory=~/.backup/vim/swap,.,/tmp
set backupskip=/tmp/*,/private/tmp/*,$TMPDIR/*,$TMP/*,$TEMP/*
" have fifty lines of command-line (etc) history:
set history=1000
if has('mouse')
" have the mouse enabled all the time
set mouse=a
" make a menu popup on right click
set mousemodel=popup
endif
" allow for switching buffers when a file has changes
set hidden
" allow backspacing over everything in insert mode
set backspace=indent,eol,start
" The first setting tells vim to use "autoindent" (that is, use the current
" line's indent level to set the indent level of new lines). The second makes
" vim attempt to intelligently guess the indent level of any new line based on
" the previous line.
set autoindent
set smartindent
set updatetime=100
" Visual settings {{{1
" -----------------------------------------------------------------
" tell the bell to go beep itself!
set visualbell t_vb=
" Enhanced command menu ctrl + d to expand directories
set wildmenu
" list completions, then cycle through them
set wildmode=list:longest,full
set wildignore+=*.pyc,*.pyo,CVS,.svn,.git,*.mo,.DS_Store,*.pt.cache,*.Python,*.o,*.lo,*.la,*~,.AppleDouble
"
" turn on spell checking
"set spell spelllang=en_us
map <silent> <leader>s :set spell!<CR>
" This setting will cause the cursor to very briefly jump to a
" brace/parenthese/bracket's "match" whenever you type a closing or
" opening brace/parenthese/bracket.
set showmatch
" Display an incomplete command in the lower right corner of the Vim window
set showcmd
" Set a margin of lines when scrolling
set scrolloff=4
" This setting ensures that each window contains a statusline that displays the
" current cursor position.
set ruler
" set a custom status line similar to that of ":set ruler"
"set statusline=\ \ \ \ \ line:%l\ column:%c\ \ \ %M%Y%r%=%-14.(%t%)\ %p%%
" show the statusline in all windows
set laststatus=2
" turn on line numbers, aww yeah
set number
" Use raw line numbers on insert, relative in normal mode.
autocmd InsertEnter * :set number
"
" By default, vim doesn't let the cursor stray beyond the defined text. This
" setting allows the cursor to freely roam anywhere it likes in command mode.
" It feels weird at first but is quite useful.
"set virtualedit=all
" Scroll in smaller increments when going horizontal
set sidescroll=5
" Set the characters showing horizontal scrolling
set listchars+=precedes:←,extends:→
" toggle line wrapping on/off
map <silent> <leader>\ :set wrap!<CR>
" Pasting {{{1
" -----------------------------------------------------------------
" turn off smart indentation when pasting
set pastetoggle=<F2>
" Searching {{{1
" -----------------------------------------------------------------
" find as you type
set incsearch
" highlight the terms
set hlsearch
" make searches case-insensitive
set ignorecase
" unless they contain upper-case letters
set smartcase
" a toggle for search highlight
map <silent> <leader>h :set hlsearch!<CR>
" Colors and Syntax {{{1
" -----------------------------------------------------------------
set background=dark
" turn on syntax highlighting
syntax on
" highlight all python syntax
let python_highlight_all=1
" gui and terminal compatible color scheme
set t_Co=256
" set global variables that will define the colorscheme
let g:light_theme='solarized'
let g:dark_theme='solarized'
" Use the "original" molokai theme colors instead of "dark"
let g:molokai_original=1
" Command to call the ColorSwitch funciton
command! -nargs=? -complete=customlist,s:completeColorSchemes ColorSwitcher :call s:colorSwitch(<q-args>)
" A function to toggle between light and dark colors
function! s:colorSwitch(...)
" function to switch colorscheme
function! ChangeMe(theme)
execute('colorscheme '.a:theme)
try
execute('colorscheme '.a:theme.'_custom')
catch /E185:/
" There was no '_custom' scheme...
endtry
endfunction
" Change to the specified theme
if eval('a:1') != ""
" check to see if we are passing in an existing var
if exists(a:1)
call ChangeMe(eval(a:1))
else
call ChangeMe(a:1)
endif
return
endif
" Toggle between a light and dark vim colorscheme
if &background == 'dark'
set background=light
call ChangeMe(g:light_theme)
elseif &background == 'light'
set background=dark
call ChangeMe(g:dark_theme)
endif
endfunction
" completion function for colorscheme names
function! s:completeColorSchemes(A,L,P)
let colorscheme_names = []
for i in split(globpath(&runtimepath, "colors/*.vim"), "\n")
let colorscheme_name = fnamemodify(i, ":t:r")
if stridx(colorscheme_name, "_custom") < 0
call add(colorscheme_names, colorscheme_name)
endif
endfor
return filter(colorscheme_names, 'v:val =~ "^' . a:A . '"')
endfunction
" set the colorscheme
if hostname() == "Nolans-MacBook-Pro.local"
call s:colorSwitch(g:light_theme)
else
call s:colorSwitch(g:dark_theme)
endif
" switch between light and dark colors
map <silent> <leader>c :ColorSwitcher<CR>
" Custom functions and commands {{{1
" -----------------------------------------------------------------
" This isn't multiplatform, sadly, but helpful on Linux.
command PbCopy :w !xclip -selection clipboard
" Tabs and spaces {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" command to switch tab styles
command! -nargs=+ TabStyle :call s:TabChanger(<f-args>)
" function to switch between tabs and spaces
" initial idea taken from:
" http://github.com/twerth/dotfiles/blob/master/etc/vim/vimrc
function! s:TabChanger(...)
let l:tab_type = a:1
if !exists('a:2')
let l:tab_length = 4
else
let l:tab_length = a:2
endif
exec 'set softtabstop=' . l:tab_length
exec 'set shiftwidth=' . l:tab_length
exec 'set tabstop=' . l:tab_length
if l:tab_type == "space"
set expandtab
elseif l:tab_type =="tab"
set noexpandtab
endif
endfunction
TabStyle space 4
" Shell as scratch buffer {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" function to run shell commands and create a scratch buffer (modified
" slightly so that it doesn't show the command and it's interpretation)
" http://vim.wikia.com/wiki/Display_output_of_shell_commands_in_new_window
" Example, show output of ls in a scratch buffer:
"
" :Shell ls -al
"
command! -complete=shellcmd -nargs=+ Shell call s:RunShellCommand(<q-args>)
function! s:RunShellCommand(cmdline)
echo a:cmdline
let expanded_cmdline = a:cmdline
for part in split(a:cmdline, ' ')
if part[0] =~ '\v[%#<]'
let expanded_part = '"'.fnameescape(expand(part)).'"'
let expanded_cmdline = substitute(expanded_cmdline, part, expanded_part, '')
endif
endfor
botright new
setlocal buftype=nofile bufhidden=wipe nobuflisted noswapfile nowrap
call setline(1,substitute(getline(1),'.','=','g'))
execute '$read !'. expanded_cmdline
setlocal nomodifiable
1
endfunction
" Whitespace {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" A function to strip trailing whitespace and clean up afterwards so
" that the search history remains intact and cursor does not move.
" Taken from: http://vimcasts.org/episodes/tidying-whitespace
function! StripTrailingWhitespaces()
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
%s/\s\+$//e
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
endfunction
" Markdown {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let g:vim_markdown_folding_disabled = 1
" Open a buffer number in a vertical split {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" Vertical Split Buffer Function
function! VerticalSplitBuffer(buffer)
execute "vert belowright sb" a:buffer
endfunction
" Vertical Split Buffer Mapping
command! -nargs=1 Vbuffer call VerticalSplitBuffer(<f-args>)
" Plugins {{{1
" -----------------------------------------------------------------
" turn on filetype checking for plugins like pyflakes
filetype on " enables filetype detection
filetype plugin indent on " enables filetype specific plugins
" Dpaste {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
map <leader>L :Dpaste<CR>
" syntastic {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" Enable signs support to visually see where errors/warnings appear
let g:syntastic_enable_signs=1
" Automatically open the location list when there are errors
let g:syntastic_auto_loc_list=0
" Flake8 {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" Don't worry about line length
let g:flake8_max_line_length=110
let g:flake8_cmd="/usr/local/share/python/flake8"
" Yankring {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" Show and hide the yankring history
nnoremap <silent> <leader>y :YRShow<CR>
" Set the maximum number of history
let g:yankring_max_history = 200
" Make the yankring set the numbered registers
let g:yankring_manage_numbered_reg = 1
" don't leave the history in my home dir
let g:yankring_history_dir = '$HOME/.backup/vim'
let g:loaded_delimitMate = 1
" Tagbar {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let g:tagbar_type_go = {
\ 'ctagstype' : 'go',
\ 'kinds' : [
\ 'p:package',
\ 'i:imports:1',
\ 'c:constants',
\ 'v:variables',
\ 't:types',
\ 'n:interfaces',
\ 'w:fields',
\ 'e:embedded',
\ 'm:methods',
\ 'r:constructor',
\ 'f:functions'
\ ],
\ 'sro' : '.',
\ 'kind2scope' : {
\ 't' : 'ctype',
\ 'n' : 'ntype'
\ },
\ 'scope2kind' : {
\ 'ctype' : 't',
\ 'ntype' : 'n'
\ },
\ 'ctagsbin' : 'gotags',
\ 'ctagsargs' : '-sort -silent'
\ }
" vim-go {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let g:go_fmt_command = "goimports"
let g:SuperTabDefaultCompletionType = "context"
" Automatically write the type info to the status bar.
let g:go_auto_type_info = 1
" Automatically highlight the same IDs
let g:go_auto_sameids = 1
" ctrlp {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nmap <leader>m :CtrlP<CR>
" Use rg for CtrlP searching
if executable('rg')
set grepprg=rg\ --color=never
let g:ctrlp_user_command = 'rg %s --files --color=never --glob ""'
let g:ctrlp_use_caching = 0
else
let g:ctrlp_clear_cache_on_exit = 0
endif
" Auto command settings {{{1
" -----------------------------------------------------------------
if has("autocmd")
" shell files
au BufNewFile,BufRead .common* set filetype=sh
" Vagrant files
au BufNewFile,BufRead Vagrantfile set filetype=ruby
au BufNewFile,BufRead *.html,*.htm,*.shtml,*.stm,*.jinja2 set ft=jinja
" Misc. Files
au BufRead,BufNewFile *.fountain set filetype=fountain
" Yaml
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
au BufRead,BufNewFile *.yml,*.yaml set ft=yaml
endif
" Cursor and window controls {{{1
" -----------------------------------------------------------------
" Make cursor move by visual lines instead of file lines (when wrapping)
" This makes me feel more at home :)
map <up> gk
map k gk
imap <up> <C-o>gk
map <down> gj
map j gj
imap <down> <C-o>gj
map E ge
" window resizing
if bufwinnr(1)
map + <C-W>+
map - <C-W>-
endif
" Insert newlines with enter and shift + enter
map <S-Enter> O<ESC>
map <Enter> o<ESC>
" open a new line from the current spot (sort of the opposite of J)
map <leader><Enter> i<CR><ESC>
" sort versions in a versions.cfg
map <leader>V /\[versions\]<CR>jVG:g/^#/d<CR>gv:g/^$/d<CR>gv:sort i<CR>
" set up the invisible characters
set listchars+=tab:\|\ ,eol:¬
" show invisible characters by default
set list
hi SpecialKey ctermfg=2 guifg=gray
" toggle invisible characters
noremap <silent> <leader>i :set list!<CR>
" Window management settings {{{1
" -----------------------------------------------------------------
" Mapping window commands directly
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
" vim-airline {{{1
" -----------------------------------------------------------------
" Disable ctags support.
let g:airline#extensions#tagbar#enabled = 0
" Enable the list of buffers
let g:airline#extensions#tabline#enabled = 1
" Show just the filename
let g:airline#extensions#tabline#fnamemod = ':t'
" Customize mixed indentation warnings
" so license headers don't complain in go files
" For some reason, excluding them just for go with the below didn't work
"let g:airline#extensions#whitespace#skip_indent_check_ft = {'go': ['mixed-indent-file']}
let g:airline#extensions#whitespace#checks = [ 'indent', 'trailing', 'long' ]
"
" Buffer shortcuts {{{1
" -----------------------------------------------------------------
" Better buffer controls
" Open a new empty buffer
nmap <leader>T :enew<cr>
nmap <leader>n :bnext<cr>
nmap <leader>p :bprevious<cr>
" Remap ^z to suspend the session, the redraw on resume. Should fix drawing
" issues in tmux and doing ^z/fg
noremap ^z :suspend<bar>:redraw!<cr>
" Move between buffers
nmap <leader>b :CtrlPBuffer<CR>
" turn on folds (must be the last lines in the file)
" vim: fdm=marker
"