-
Notifications
You must be signed in to change notification settings - Fork 20
/
.vimrc
1446 lines (1214 loc) · 48.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
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
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
" My vimrc uses folds
"
" zi toggle all folds (open or closed)
" 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
" My vimrc command and mapping quick reference {{{1
" -----------------------------------------------------------------
"
" The mapleader has been switched from '\' to ',' anytime you see
" <leader> that is what this refers to.
"
" Change Option mnemonic {{{2
" -----------------------------------------------------------------
" coc -- Switch between light and dark colors
" coe -- Show current :Errors
" cog -- Toggle the gutter and clear signs
" coh -- Clear the current search highlight
" coH -- Toggles the highlight search
" coi -- Toggles invisible characters
" col -- Toggles the location list
" con -- Toggles the line numbers
" conn -- Toggles relative line numbers
" coq -- Toggle the quickfix window
" cos -- Toggle spell checking
" cot -- Change the tab name
" cov -- Edit the current user's vimrc
" cow -- Toggle line wrapping
" cox -- Toggles NERDTree drawer
"
" Clean Up mnemonic {{{2
" -----------------------------------------------------------------
" cuw -- Removes trailing whitespace characters
" cuf -- Clean up the current file using autoformat
" cut -- Find things to clean up. TODO, XXX, etc.
" cuv -- Sort a buildout versions.cfg file
"
" File Type mnemonic {{{2
" -----------------------------------------------------------------
" ftc -- Change current filetype to CSS
" fth -- Change current filetype to HTML
" ftj -- Change current filetype to Javascript
" ftm -- Change current filetype to Markdown
" ftp -- Change current filetype to Python
" ftr -- Change current filetype to reStructuredText
" ftv -- Change current filetype to Vim
" ftw -- Change current filetype to Wiki
"
" TeSt mnemonic
" -----------------------------------------------------------------
" tsl -- :TestNearest
" ts; -- :TestFile
" ts' -- :TestSuite
" tss -- :TestLast
"
" Fuzzy Finder mnemonic {{{2
" -----------------------------------------------------------------
" ff -- Fuzzy file mode
" fft -- Fuzzy tag mode
" ffr -- Fuzzy MRU mode
" ffe -- Fuzzy buffer mode
" ffc -- Fuzzy :colors mode
"
" Tell Me mnemonic {{{2
" -----------------------------------------------------------------
" tma -- Starts an ack search in the CWD
" tmf -- Shows the current file in the NERDTree. This
" is the TextMate equivalent of ctrl+cmd+r
" tmi -- Toggle indent guides
" tmy -- Show the yankring
" tmb -- Shortcut for getting to NERDTree bookmarks
" tm1 -- Set a highlight for the current word (1)
" tm2 -- Set a highlight for the current word (2)
" tm3 -- Set a highlight for the current word (3)
" tmr -- Show me reST preview
" tmrk -- Stop reST preview
" tmm -- Show me Markdown preview
" tmmk -- Stop Markdown preview
" tms -- Save the file
" tmg -- Toggle signify folds (show only vcs changes)
" tmt -- Show translations for the current key (rails)
" tmte -- Expand the current YAML key (rails)
"
" Git stuff {{{2
" -----------------------------------------------------------------
" tgg -- Git status (tmg was too hard, so tg)
" // -- Git grep (double tap to start)
" tgd -- Git diff
" tgb -- Git blame
" tgbb -- Show commit in browser
" tgl -- Git log on the current file (back 100)
" tgll -- Git log on the current project (back 100)
" tgh -- Git log search looking for + / - of term
" tghh -- Git log search with word in diff
"
" Window Management {{{2
" -----------------------------------------------------------------
" <C-W>- -- Horizontal split
" <C-W>| -- Vertical split
" <C-W>z -- Zoom in on the current buffer
" <C-W><C-E> -- Cycle through windows
" <C-H> -- Move left to window
" <C-J> -- Move up to window
" <C-K> -- Move down to window
" <C-L> -- Move right to window
" <C-W><C-H> -- Move left to next tab
" <C-W><C-L> -- Move right to next tab
" <C-W><C-N> -- Create a new tab
" <C-W><C-I> -- Edit current file in a new tab
" <C-W><C-X> -- Close the current tab
" + -- Make the current window taller
" - -- Make the current window shorter
"
" Other random stuff {{{2
" -----------------------------------------------------------------
" ]q -- Previous quickfix change
" [q -- Next quickfix change
" ]w -- Previous location list change
" [w -- Next location list change
" tt -- Opens up the taglist
" Y -- Yank to the end of the line, no newline
" YY -- Yank the current line, no newline
" funi -- Find the next non-ascii character (funny)
" jj -- Alternative to <ESC>
" jk -- Alternative to <ESC>
" <leader>Enter -- Split line at current cursor in normal mode
" <F2> -- Toggle smart indent on paste
"
" Command line mappings {{{2
" -----------------------------------------------------------------
"
" <C-a> -- Beginning of the line
" <C-c> -- End of the line
"
" Custom Commands {{{2
" -----------------------------------------------------------------
"
" I have set up some custom commands that might be of interest
"
" MarkdownToHTML -- Converts the current buffer into HTML and
" places it in a scratch buffer.
" MarkdownToHTMLCopy -- Same as previous, but copies to clipboard
" 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
" W -- Save the following file using sudo to avoid
" the [readonly] flag.
" 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
set modeline
" This setting prevents vim from emulating the original vi's
" bugs and limitations.
set nocompatible
" Load up all vim plugins
source ~/.vim_plugins.vim
" set the mapleader key
let mapleader = ","
let g:mapleader = ","
" Set a shorter timeout length to make jk and jj easier to use
set timeoutlen=350
" set the default encoding
if !has('nvim')
set enc=utf-8
endif
" only increment numbers and letters
set nrformats=""
" set up jj as mode switch
map! jj <ESC>
map! jk <ESC>
" Save shortcut
nnoremap tms :w<CR>
" Set the shell to bash, zsh and vim don't seem to play nice
set shell=$SHELL
" :terminal settings
let g:terminal_scrollback_buffer_size=100000
" Python support via virtualenvs
let g:python_host_prog = expand('~/.virtualenvs/neovim-py2/bin/python', ':p')
let g:python3_host_prog = expand('~/.virtualenvs/neovim/bin/python', ':p')
" 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/*
if v:version >= 703
set undofile
" keep a persistent backup file
if has('nvim')
set undodir=~/.backup/vim/undo,~/tmp,/tmp
else
set undodir=~/.backup/vim/undo_vim,~/tmp,/tmp
endif
endif
" have fifty lines of command-line (etc.) history:
set history=10000
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
" Use the clipboard
set clipboard^=unnamed,unnamedplus
" 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
" Only one space after periods when formatting strings
set nojoinspaces
" Allow command line editing like emacs
cnoremap <C-A> <Home>
cnoremap <C-E> <End>
" open up my vimrc in a tab for modifications
map cov :tabedit $MYVIMRC<CR>
" Highlight the word under the cursor
" Taken from https://bitbucket.org/sjl/dotfiles/src/tip/vim/.vimrc
nnoremap <silent> tm1 :execute 'match InterestingWord1 /\<<c-r><c-w>\>/'<cr>
nnoremap <silent> tm2 :execute '2match InterestingWord2 /\<<c-r><c-w>\>/'<cr>
nnoremap <silent> tm3 :execute '3match InterestingWord3 /\<<c-r><c-w>\>/'<cr>
" Re-initialize interesting words to select different ones.
nnoremap <silent> tm0 :ExtraHighlightsInit<cr>
" shortcut to cycle through quickfix list
nnoremap [q :cnext<cr>
nnoremap ]q :cprevious<cr>
" shortcut to cycle through location list
nnoremap [w :lnext<cr>
nnoremap ]w :lprevious<cr>
" Use sane regexes.
nnoremap / /\v
vnoremap / /\v
nnoremap //// :tab helpg \v\c<Left><Left>
" Easy filetype switching
nnoremap ftm :set ft=markdown<CR>
nnoremap ftp :set ft=python<CR>
nnoremap ftw :set ft=wiki<CR>
nnoremap ftr :set ft=ruby<CR>
nnoremap ftrs :set ft=rst<CR>
nnoremap ftv :set ft=vim<CR>
nnoremap ftj :set ft=javascript<CR>
nnoremap fts :set ft=sql<CR>
nnoremap ftsh :set ft=sh<CR>
nnoremap ftc :set ft=css<CR>
nnoremap fth :set ft=html<CR>
" Visual settings {{{1
" -----------------------------------------------------------------
" tell the bell to go beep itself!
set visualbell t_vb=
" Always hide concealable content
set conceallevel=2
" set the title of the window
set title
set titlestring=%f%(\ [%M]%)
" Enhanced command menu ctrl + d to expand directories
set wildmenu
" command <Tab> completion, list matches, then longest common part, then all.
set wildmode=list:longest,full
" Ignore case when tab completing
set wildignorecase
set wildignore+=*.pyc,*.pyo,CVS,.svn,.git,*.mo,.DS_Store,*.pt.cache,*.Python,*.o,*.lo,*.la,*~,.AppleDouble,*/blobstorage/*,*/Paste*-*.egg/*
map <silent> cos :set spell!<CR>
if version >= 700
set spl=en spell
endif
set spell
" This setting will cause the cursor to very briefly jump to a
" brace/parentheses/bracket's "match" whenever you type a closing or
" opening brace/parentheses/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
" lines to scroll when cursor leaves screen
set scrolljump=0
" show the statusline in all windows
set laststatus=2
" set all window splits equal
set equalalways
" more natural split direction
set splitbelow
set splitright
" highlight the cursor line
set cursorline
" turn on line numbers, aww yeah
set number
" shortcut to turn off line numbers
map <silent> con :set number!<CR>
" toggle relative number
map <silent> conn :set relativenumber!<CR>
" don't redraw during macros
set lazyredraw
" Set linebreak so words don't get split
set linebreak
" Scroll in smaller increments when going horizontal
set sidescroll=5
" toggle line wrapping on/off
map <silent> cow :set wrap!<CR>
augroup PreservingFilePosition
autocmd!
" When editing a file, always jump to the last known cursor position.
" Don't do it when the position is invalid or when inside an event handler
" (happens when dropping a file on gvim).
" Also don't do it when the mark is in the first line, that is the default
" position when opening a file.
autocmd BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g`\"" | endif
" always jump to the top of commit messages
" NOTE: mercurial and bazaar use temporary files, so this isn't necessary
autocmd BufReadPost svn-commit*.tmp exe "normal! gg"
autocmd BufReadPost COMMIT_EDITMSG* exe "normal! gg"
augroup END
" Borrowed from
" http://dhruvasagar.com/2013/03/28/vim-better-foldtext
function! NeatFoldText()
let line = ' ' . substitute(getline(v:foldstart), '^\s*"\?\s*\|\s*"\?\s*{{' . '{\d*\s*', '', 'g') . ' '
let lines_count = v:foldend - v:foldstart + 1
let lines_count_text = '| ' . printf("%10s", lines_count . ' lines') . ' |'
let foldchar = matchstr(&fillchars, 'fold:\zs.')
let foldtextstart = strpart('+' . repeat(foldchar, v:foldlevel*2) . line, 0, (winwidth(0)*2)/3)
let foldtextend = lines_count_text . repeat(foldchar, 8)
let foldtextlength = strlen(substitute(foldtextstart . foldtextend, '.', 'x', 'g')) + &foldcolumn
return foldtextstart . repeat(foldchar, winwidth(0)-foldtextlength) . foldtextend
endfunction
set foldtext=NeatFoldText()
" 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> coH :set hlsearch!<CR>
" Shortcut to clear out the search pattern (and thus turn off the highlighting)
" from http://stackoverflow.com/questions/657447/vim-clear-last-search-highlighting
map <silent> coh :let @/ = ""<CR>
" Find any non-ascii character
map <silent> funi /[^ -~]<CR>
" Colors and Syntax {{{1
" -----------------------------------------------------------------
" 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 background=light
" Use the "original" molokai theme colors instead of "dark"
let g:molokai_original=1
" Zenburn settings
let g:zenburn_alternate_Error = 1
" Solarized settings
let g:solarized_termcolors=16
let g:solarized_diffmode='high'
let g:neosolarized_termtrans=1
" Function to quickly apply and reset custom highlights
function! s:extraHighlights()
" Syntax highlights for the mappings set above
hi InterestingWord1 guifg=#eee8d5 guibg=#FF4300 ctermfg=254 ctermbg=166
hi InterestingWord2 guifg=#eee8d5 guibg=#859900 ctermfg=254 ctermbg=64
hi InterestingWord3 guifg=#eee8d5 guibg=#268bd2 ctermfg=254 ctermbg=33
" Setting the highlight for the IndentGuides function above
hi IndentGuides guibg=#373737 ctermbg=237
match none
2match none
3match none
" Set comments to italic to use the power of Operator Mono
hi Comment cterm=italic
" The PaperColor highlights were a bit much for me.
" Set the spell bad to underline and don't highlight rare words.
" hi clear SpellBad
" hi clear SpellRare
" hi SpellBad cterm=undercurl gui=undercurl guisp=black
" hi ErrorMsg ctermfg=8 ctermbg=1 guifg=White guibg=Red
endfunction
command! ExtraHighlightsInit :call s:extraHighlights()
" A function to toggle between light and dark colors, or switch to
" the given theme.
function! s:colorSwitch(...)
" Change to the specified theme, if there were args
if !empty(a:1)
" clear out the syntax so the new theme gets applied properly
hi clear
execute('colorscheme ' . a:1)
" Put the extra highlights back in place
call s:extraHighlights()
return
endif
" Toggle between a light and dark vim colorscheme
if &background == 'dark'
set background=light
silent !kitty +kitten themes --reload-in=all catppuccin-latte
elseif &background == 'light'
set background=dark
silent !kitty +kitten themes --reload-in=all catppuccin-mocha
endif
" Put the extra highlights back in place
call s:extraHighlights()
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
" Command to call the ColorSwitch function
command! -nargs=? -complete=customlist,s:completeColorSchemes ColorSwitcher :call s:colorSwitch(<q-args>)
" switch between light and dark colors
map <silent> coc :ColorSwitcher<CR>
" Issue loading PaperColor color scheme in latest neovim:
" https://github.com/NLKNguyen/papercolor-theme/issues/201
set termguicolors
" set the colorscheme
ColorSwitcher catppuccin-latte
" Toggle the gutter
function! s:toggleGutterSigns()
if &signcolumn =~ '\v(auto|yes)'
set signcolumn=no
CocDisable
else
set signcolumn=auto
CocEnable
endif
endfunction
command! ToggleGutterSigns :call s:toggleGutterSigns()
" Toggle the gutter on and off
map <silent> cog :ToggleGutterSigns<cr>
" Diff mode settings {{{1
" -----------------------------------------------------------------
" Handle diff mode a bit different as there are some things that don't make
" sense to run
if &diff
" Disable CoC
let g:coc_start_at_startup=0
endif
" Custom functions and commands {{{1
" -----------------------------------------------------------------
" Strip whitespace {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" Taken from here:
" https://vi.stackexchange.com/a/456/5433
fun! TrimWhitespace()
let l:save = winsaveview()
keeppatterns %s/\s\+$//e
call winrestview(l:save)
endfun
command! TrimWhitespace call TrimWhitespace()
nnoremap <silent> cuw :TrimWhitespace<cr>
" 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 2
" 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
" Markdown {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" run markdown on the current file and place the html in a scratch buffer
command! -nargs=0 MarkdownToHTML call s:RunShellCommand('Markdown.pl %')
" replace the current buffer with the html version of the markdown
command! -nargs=0 MarkdownToHTMLReplace %!Markdown.pl "%"
" copy the html version of the markdown to the clipboard
command! -nargs=0 MarkdownToHTMLCopy !Markdown.pl "%" | clipboard
" use pandoc to convert from html into markdown
command! -nargs=0 MarkdownFromHTML %!pandoc -f html -t markdown_github "%"
" Quickfix {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" Borrowed from
" http://vim.wikia.com/wiki/Toggle_to_open_or_close_the_quickfix_window
function! GetBufferList()
redir =>buflist
silent! ls!
redir END
return buflist
endfunction
function! ToggleList(bufname, pfx)
let buflist = GetBufferList()
for bufnum in map(filter(split(buflist, '\n'), 'v:val =~ "'.a:bufname.'"'), 'str2nr(matchstr(v:val, "\\d\\+"))')
if bufwinnr(bufnum) != -1
exec(a:pfx.'close')
return
endif
endfor
if a:pfx == 'l' && len(getloclist(0)) == 0
echohl ErrorMsg
echo "Location List is Empty."
return
endif
let winnr = winnr()
exec(a:pfx.'open')
if winnr() != winnr
wincmd p
endif
endfunction
nnoremap <silent> coq :call ToggleList("Quickfix List", 'c')<CR>
nnoremap <silent> col :call ToggleList("Location List", 'l')<CR>
" Copy search matches to register {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" Copy matches of the last search to a register (default is the clipboard).
" Accepts a range (default is whole file).
" 'CopyMatches' copy matches to clipboard (each match has \n added).
" 'CopyMatches x' copy matches to register x (clears register first).
" 'CopyMatches X' append matches to register x.
" We skip empty hits to ensure patterns using '\ze' don't loop forever.
command! -range=% -register CopyMatches call s:CopyMatches(<line1>, <line2>, '<reg>')
function! s:CopyMatches(line1, line2, reg)
let hits = []
for line in range(a:line1, a:line2)
let txt = getline(line)
let idx = match(txt, @/)
while idx >= 0
let end = matchend(txt, @/, idx)
if end > idx
call add(hits, strpart(txt, idx, end-idx))
else
let end += 1
endif
if @/[0] == '^'
break " to avoid false hits
endif
let idx = match(txt, @/, end)
endwhile
endfor
if len(hits) > 0
let reg = empty(a:reg) ? '+' : a:reg
execute 'let @'.reg.' = join(hits, "\n") . "\n"'
else
echo 'No hits'
endif
endfunction
" :global to buffer {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" Output the last global command to a buffer for further use
command! GlobalToBuffer execute 'normal! 0"ay0' | execute 'g//y A' | split | enew | setlocal bt=nofile | put! a | execute 'normal! ggddGdd'
" 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>)
" Show indent guides {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" Taken from https://bitbucket.org/sjl/dotfiles/src/tip/vim/.vimrc
" though that may not be the originator.
let g:indentguides_state = 0
function! IndentGuides() " {{{
if g:indentguides_state
let g:indentguides_state = 0
2match None
else
let g:indentguides_state = 1
execute '2match IndentGuides /\%(\_^\s*\)\@<=\%(\%'.(0*&sw+1).'v\|\%'.(1*&sw+1).'v\|\%'.(2*&sw+1).'v\|\%'.(3*&sw+1).'v\|\%'.(4*&sw+1).'v\|\%'.(5*&sw+1).'v\|\%'.(6*&sw+1).'v\|\%'.(7*&sw+1).'v\)\s/'
endif
endfunction " }}}
nnoremap <silent> tmi :call IndentGuides()<cr>
" Save a file with sudo when it is [readonly] {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" Taken from command line fu.
" http://www.commandlinefu.com/commands/view/9425
command! W :execute ':silent w !sudo tee % > /dev/null' | :edit!
" Git Commit Dance {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function! GitCommitDance()
" Disable scrolloff
set scrolloff=0
" Find the last line of the git file list / first line before diff
execute "normal G?^#\<CR>"
let curline=line('.')
" Split the window so we can see the diff and the commit message
split
" show only the git message on top, set it to that height
execute "normal ggz". curline ."\<CR>"
" Start the diff window at the top of the diff
execute "normal \<C-W>j". curline ."Gjz\<CR>"
" Go back to the commit editing
execute "normal \<C-W>k"
endfunction
" Open help in a tab {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" via http://stackoverflow.com/a/7515418/34530
cnoreabbrev <expr> help getcmdtype() == ":" && getcmdline() == 'help' ? 'tab help' : 'help'
cnoreabbrev <expr> h getcmdtype() == ":" && getcmdline() == 'h' ? 'tab help' : 'h'
cnoreabbrev <expr> helpgrep getcmdtype() == ":" && getcmdline() == 'helpgrep' ? 'tab helpgrep' : 'helpgrep'
cnoreabbrev <expr> helpg getcmdtype() == ":" && getcmdline() == 'helpg' ? 'tab helpg' : 'helpg'
" Search i18n-tasks for a string {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
function! s:I18nTasksFind(...)
" TODO: Check for bundle or the command itself
execute("setlocal makeprg=bundle\\ exec\\ i18n-tasks\\ find\\ '". a:1 ."'")
" TODO: Handle the multi-line format properly
setlocal errorformat=\ \ %f:%l\ %m
" TODO: Make this async...
silent make
copen
endfunction
command! -nargs=1 I18nTasksFind :call s:I18nTasksFind(<q-args>)
" Plugins {{{1
" -----------------------------------------------------------------
" turn on filetype checking for plugins like pyflakes
filetype on " enables filetype detection
filetype plugin indent on " enables filetype specific plugins
" Grepper {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
map /// :Grepper -tool rg<cr>
map // :Grepper -tool git<cr>
map cut :Grepper -tool branchd -highlight -query '\b(TODO\|XXX\|HACK\|FIXME\|NOTE)\b'<cr>
" initialize g:grepper with defaults
runtime plugin/grepper.vim
" Available list of grepping tools
let g:grepper.tools = ['rg', 'git', 'giti', 'grep', 'branch', 'branchd']
" Modify git args to be case insensitive
let g:grepper.git.grepprg = 'git grep -nEIi'
" Case sensitive search is good sometimes though
let g:grepper.giti = {
\ 'grepprg': 'git grep -nEI',
\ 'grepformat': '%f:%l:%m',
\ }
" Search across files modified in the current branch against master / dev
let g:grepper.branch = {
\ 'grepprg': "git grep -nE $* -- `git diff --name-only origin/master...`",
\ 'grepformat': '%f:%l:%m',
\ }
let g:grepper.branchd = {
\ 'grepprg': "git grep -nE $* -- `git diff --name-only origin/dev...`",
\ 'grepformat': '%f:%l:%m',
\ }
" Highlight matches
let g:grepper.highlight = 1
" Don't open and switch to the Quickfix window, manually open it
let g:grepper.open = 0
" CSV {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" turn on tsv in csv mode
function! Csv_tsv()
let b:delimiter='\t'
let b:col=substitute(b:col, ',', '\t', 'g')
endfunction
" NERDTree {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" set project folder to x
map cox :NERDTreeToggle<CR>
map tmb :NERDTreeFromBookmark<Space>
nnoremap <silent> tmf :NERDTreeFind<CR>
" files/dirs to ignore in NERDTree (mostly the same as my svn ignores)
let NERDTreeIgnore=[
\'\~$',
\'\.pt.cache$',
\'\.Python$',
\'\.svn$',
\'\.git*$',
\'\.pyc$',
\'__pycache__$',
\'\.pyo$',
\'\.mo$',
\'\.o$',
\'\.lo$',
\'\.la$',
\'\..*.rej$',
\'\.rej$',
\'\.\~lock.*#$',
\'tndrbox_Images.*gif.*',
\'tndrbox_.*[Ll]ogo.*',
\'\.AppleDouble$',
\'\.pt.py$',
\'\.DS_Store$']
" set the sort order to alphabetical
let NERDTreeSortOrder=[]
" when the root is changed, change Vim's working dir
let NERDTreeChDirMode=2
" use fancy ass arrows
let NERDTreeDirArrows=1
" php debugger {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" turn off the mini buf explorer when using the debugger so the
" windows get initialized properly
let g:debuggerMiniBufExpl = 1
" Airline {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let g:airline_theme='base16_grayscale'
let g:airline_powerline_fonts=1
let g:airline_section_z='%4l/%-4L|%-3c'
" Disable specific extensions
let g:airline#extensions#whitespace#enabled = 0
" Tagbar {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nnoremap tt :TagbarToggle<CR>
" unset the sort so it sorts by source file order
let g:tagbar_sort = 0
" always jump into the tagbar pane when it is opened
let g:tagbar_autofocus = 1
" ZCML type
" XXX: This doesn't currently work because I use a filetype setting
" of "xml.zcml".
let g:tagbar_type_zcml = {
\ 'ctagstype': 'zcml',
\ 'kinds': [
\ 'n:name',
\ 'f:for',
\ 'g:profile',
\ 'p:permission',
\ 'p:provides',
\ 'h:handler',
\ 'm:component',
\ 'f:factory',
\ 'c:class',
\ 'i:id',
\ 'v:view',
\ 's:schema',
\ 'c:controller',
\ 't:type',
\ 'w:workflow'
\ ]
\}
" cfg file type
let g:tagbar_type_cfg = {
\ 'ctagstype': 'ini',
\ 'kinds': ['s:section']
\ }
" Markdown type
let g:tagbar_type_markdown = {
\ 'ctagstype': 'markdown',
\ 'kinds': [
\ '1:header1',
\ '2:header2',
\ '3:header3',
\ '4:header4',
\ '5:header5',
\ '6:header6',
\ '7:header7'
\ ]
\ }
let g:tagbar_type_yaml = {
\ 'ctagstype': 'yaml',
\ 'kinds': [
\ 'd:definition',
\ 'n:name'
\ ]
\ }
let g:tagbar_type_sls = {
\ 'ctagstype': 'yaml',
\ 'kinds': [
\ 'd:definition',
\ 'n:name'
\ ]
\ }
" yankstack {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let g:yankstack_map_keys = 0
imap <C-f> <Plug>yankstack_substitute_older_paste
imap <C-g> <Plug>yankstack_substitute_newer_paste
nnoremap <silent> tmy :Yanks<CR>
" Signify {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" Only show these VCS differences
let g:signify_vcs_list = ['git', 'hg', 'svn']
" Toggle signify folds
nmap <silent> tmg :SignifyFold!<CR>
" Markdown {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
let g:vim_markdown_folding_disabled=1
" Riv {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
augroup RivExpandFolds
autocmd!
" Auto open folds on file open
" Couldn't figure out how to do this with the available riv options
autocmd BufReadPost *.rst :normal zR
" Manually decide when to break a line based on grammar
autocmd BufReadPost *.rst :set textwidth=0
augroup END
" livedown {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nmap tmm :LivedownPreview<CR>
nmap tmmk :LivedownKill<CR>
" instant-rst {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
nmap tmr :InstantRst<CR>
nmap tmrk :StopInstantRst<CR>
" Taboo {{{2
" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
" Set the tab formats
let g:taboo_tab_format=" (%N.%W) %f%m "
let g:taboo_renamed_tab_format=" (%N.%W) %l%m "
" Set the modified flag
let g:taboo_modified_tab_flag="+"