forked from tangledhelix/dotfiles
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
895 lines (666 loc) · 27 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
" Bootstrap {{{
" Turn off vi compatibility. If I wanted vi, I would use vi.
set nocompatible
" Reset all autocmds
autocmd!
" Load matchit library. This lets % match if/elsif/else/end, open/close
" XML tags, stuff like that, instead of just brackets and parens.
runtime macros/matchit.vim
" Detect the OS
if has('unix')
let s:uname = system('uname')
if s:uname == "Darwin\n"
let s:has_darwin = 1
endif
endif
" ------------------------------------------------------------------------ }}}
" Pathogen {{{
" vim-pathogen, for sane plugin management.
" https://github.com/tpope/vim-pathogen
let g:pathogen_disabled = []
if !has('python')
let g:pathogen_disabled += ['gundo']
let g:pathogen_disabled += ['sparkup']
endif
filetype off
runtime bundle/pathogen/autoload/pathogen.vim
call pathogen#infect()
call pathogen#helptags()
filetype plugin indent on
" ------------------------------------------------------------------------ }}}
" General settings {{{
let mapleader = ','
let maplocalleader = '\'
" Turn on mouse support
set mouse=a
" Allow 'hidden' buffers. :help hidden
set hidden
" Ignore whitespace-only changes in diff mode
set diffopt=iwhite
" Which VCS Signify should care about
let g:signify_vcs_list = [ 'git', 'svn' ]
" Prefer postgres SQL
let g:sql_type_default = 'pgsql'
" ------------------------------------------------------------------------ }}}
" General keymaps {{{
" Use jj to get back to command mode instead of Esc, which is out of the
" way and on some keyboards hard to reach. Esc still works too.
inoremap jj <esc>
" map this too to be uniform with oh-my-zsh
inoremap jk <esc>
" Use more natural key movement on wrapped lines.
nnoremap j gj
nnoremap k gk
" Open quickfix window
nnoremap <leader>q :cwindow<cr>
" Open location list window
nnoremap <leader>l :lwindow<cr>
" Source the current line
nnoremap <leader>S ^vg_y:execute @@<cr>
vnoremap <leader>S y:execute @@<cr>
" Redraw the screen
nnoremap <leader>L :syntax sync fromstart<cr>:redraw!<cr>
" Define 'del' char to be the same backspace (saves a LOT of trouble!)
" As the angle notation cannot be use with the LeftHandSide
" with mappings you must type this in *literally*!
" map <c-v>127 <c-h>
" cmap <c-v>127 <c-h>
inoremap <c-h>
cnoremap <c-h>
" the same for Linux Debian which uses
inoremap <esc>[3~ <c-h>
" go to location of last change
nnoremap gl `.
" ------------------------------------------------------------------------ }}}
" Messages and alerts {{{
set noerrorbells
set visualbell
" Kind of messages to show. Abbreviate them all.
set shortmess=atI
" Show a report when N lines were changed. report=0 means 'show all changes'.
set report=0
if !has('gui_running')
" Terminal's visual bell - turned off to make Vim quiet.
set t_vb=
endif
" ------------------------------------------------------------------------ }}}
" Status and title bars {{{
" Always show the status bar
set laststatus=2
" Show the current mode (INSERT, REPLACE, VISUAL, paste, etc.)
set showmode
" Show current uncompleted command.
set showcmd
"let g:Powerline_symbols = 'unicode'
" Set the title bar if running as GUI, but never in terminals. If set in
" a terminal, it will wipe away my title and not reset it on exit.
" Disable the toolbar in GUI mode
if has('gui_running')
set title
set guioptions=-t
else
set notitle
endif
" Activate Fugitive in statline
let g:statline_fugitive = 1
" Activate rbenv in statline
let g:statline_rbenv = 1
" ------------------------------------------------------------------------ }}}
" Cursor and position indicators {{{
" Show current cursor line position
set cursorline
" Show row/col of cursor position, and percentage into the file we are.
set ruler
" Show line numbers as relative to current, not as absolute. This makes it
" easy to use count-based commands, e.g. 5dd or 10j. Fall back to regular
" numbering if we're on an old vim.
" Map <leader>n to toggle the number column between relative (if supported),
" absolute, and off.
"
" It turns out relativenumber is still not usually available (at least not
" on RHEL/CentOS), just sticking with regular line numbers for now.
"
"if exists('+relativenumber')
" set relativenumber
" set numberwidth=3
"
" " cycles between relative / absolute / no numbering
" function! RelativeNumberToggle()
" if (&relativenumber == 1)
" set number number?
" elseif (&number == 1)
" set nonumber number?
" else
" set relativenumber relativenumber?
" endif
" endfunc
"
" nnoremap <silent> <leader>n :call RelativeNumberToggle()<cr>
"
"else
" set number
" nnoremap <silent> <leader>n :set number! number?<cr>
"endif
set nonumber
"nnoremap <silent> <leader>n :set number! number?<cr>:call ToggleShowBreak()<cr>
nnoremap <silent> <leader>n :set number! number?<cr>
" Restore cursor position from our last session, if known.
autocmd BufReadPost * if line("'\"") > 0 && line("'\"") <= line('$') | execute 'normal! g`"zvzz' | endif
" iTerm2-specific: Use a bar cursor in insert mode, block in other modes.
" https://gist.github.com/1195581
" This is really aggravating / slow to update in tmux, disabling
"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
" Only show the 'margin' column in insert mode
if exists('&colorcolumn')
autocmd InsertEnter * set colorcolumn=80
autocmd InsertLeave * set colorcolumn=""
endif
" ------------------------------------------------------------------------ }}}
" Tabs and indenting {{{
set expandtab
set tabstop=4
set softtabstop=4
" Number of columns to use for (auto)indent. Generally this should be the
" same as the tabstop.
set shiftwidth=4
" Set or show tab width info
nnoremap <leader>T :Stab<cr>
" When changing indent with <, >, >>, <<, use a multiple of shiftwidth.
set shiftround
" Keep selection when indent/dedenting in select mode.
vnoremap > >gv
vnoremap < <gv
" ------------------------------------------------------------------------ }}}
" Selecting {{{
" Reselect what was just pasted so I can so something with it.
" (To reslect last selection even if it is not the last paste, use gv.)
nnoremap <leader>V `[v`]
" Select current line, excluding leading and trailing whitespace
nnoremap vv ^vg_
" ------------------------------------------------------------------------ }}}
" Copy and paste {{{
" Key combo to toggle paste-mode
set pastetoggle=,p
" Duplicate current selection (best used for lines, but can be used
" with any selection). Pastes duplicate at end of select region.
vnoremap D y`>p
" Key combos to copy/paste using Mac clipboard
if exists('s:has_darwin')
nnoremap <leader>c "*yy
vnoremap <leader>c "*y
nnoremap <leader>v "*p
vnoremap <leader>v "*p
" Variants that set paste first. How to preserve paste if it's
" already set, though?
" nnoremap <leader>v :set paste<cr>"*p:set nopaste<cr>
" vnoremap <leader>v :set paste<cr>"*p:set nopaste<cr>
else
nnoremap <leader>c :echoerr 'Only supported on Mac'<cr>
vnoremap <leader>c :echoerr 'Only supported on Mac'<cr>
nnoremap <leader>v :echoerr 'Only supported on Mac'<cr>
vnoremap <leader>v :echoerr 'Only supported on Mac'<cr>
endif
" ------------------------------------------------------------------------ }}}
" Formatting {{{
" Text formatting options, used by 'gq', 'gw' and elsewhere. :help fo-table
set formatoptions=qrn1
" Insert two spaces after a period with every joining of lines? No!
set nojoinspaces
" Reformat current paragraph, selection, or line.
nnoremap Q gqip
vnoremap Q gq
nnoremap ql ^vg_gq
" Strip trailing whitespace file-wide, preserving cursor location
nnoremap <leader>W :call Preserve('%s/\s\+$//e')<cr>
" Swap ' for " (or vice versa) on strings, preserving cursor location
nnoremap <silent> <leader>' :call Preserve("normal cs\"'")<cr>
nnoremap <silent> <leader>" :call Preserve("normal cs'\"")<cr>
" Bubble a selection up or down
nmap <C-u> [e
nmap <C-d> ]e
vmap <C-u> [egv
vmap <C-d> ]egv
" Remap ~ to cycle through uppercase, lowercase, title-case.
vnoremap ~ ygv"=TwiddleCase(@")<cr>Pgv
" Retain cursor position on line join
" nnoremap J mzJ`z
" Split line at cursor position
nnoremap S mzi<cr><esc>`zj0
" Invoke Tabular
nnoremap <leader>= :Tabularize /
vnoremap <leader>= :Tabularize /
" ------------------------------------------------------------------------ }}}
" Wrapping {{{
" I use Vim mostly to write code. This doesn't auto-wrap lines, it only does
" a soft wrap to the window width.
set wrap
" No fixed width; 0 means to use the current window width, max out at 79.
set textwidth=0
" Break lines at whitespace or special characters (when tw != 0). Avoids lines
" where a word shows up on both the right and left edges of the screen. Which
" makes copy/paste into other apps FUN. Screws up coding. Off normally. makes
" copy/paste into other apps FUN. Screws up coding. Off normally.
set nolinebreak
" Backspace over indentation, end-of-line, and start-of-line.
set backspace=indent,eol,start
"function! ToggleShowBreak()
" if &showbreak == ''
" if has('multi_byte')
" execute('set showbreak=↪')
" endif
" else
" execute('set showbreak=')
" endif
"endfunction
"nnoremap <silent> <leader>N :call ToggleShowBreak()<cr>
" ------------------------------------------------------------------------ }}}
" Folding {{{
" Use explicit markers for folding (triple curly-brace)
set foldmethod=marker
" Use space to toggle folds.
nnoremap <space> za
" Focus on the current fold
nnoremap <leader>z zMzvzz
" Fold current HTML tag.
nnoremap <leader>Ft Vatzf
" ------------------------------------------------------------------------ }}}
" History, undo and caches {{{
" What to store from an editing session in the viminfo file.
" Can be used at next session.
set viminfo=%,'50,\"100,:100,n~/.viminfo
" Increase the history size (default is 20).
set history=100
" Some cache / backup locations
set backupdir=~/.vim/tmp/backup// " backups
set directory=~/.vim/tmp/swap// " swap files
set backup " enable backups
" set noswapfile " It's 2012, Vim.
if has('persistent_undo')
set undodir=~/.vim/tmp/undo// " undo files
endif
" Toggle Gundo window
if has('python')
nnoremap <leader>u :GundoToggle<cr>
else
nnoremap <leader>u :echoerr 'Gundo requires Python support'<cr>
endif
" ------------------------------------------------------------------------ }}}
" Search and replace {{{
" Highlight matches, and use incremental search (like iTunes).
set hlsearch
set incsearch
" Ignore case in search patterns unless an uppercase character is used
" in the search, then pay attention to case.
set ignorecase
set smartcase
" Clear the highlighted words from an hlsearch (can be visual clutter).
nnoremap <silent> <leader><space> :nohlsearch<cr>:call clearmatches()<cr>
" Turn hlsearch on or off.
nnoremap <leader>h :set hlsearch!<cr>
" Turn off vim's default regex and use normal regexes (behaves more
" like Perl regex now...) - this is 'very magic' mode. Only alphanumerics
" and underscore are *not* quoted with backslash. See ':help magic'.
nnoremap / /\v
vnoremap / /\v
" Use 'magic' patterns (extended regex) in search patterns. ('\s\+').
" This isn't used by the / search due to the / remaps. For :s and :g.
set magic
" Assume /g at the end of any :s command. I usually want that anyway.
set gdefault
" Keep search matches positioned in the middle of the window.
" nnoremap n nzzzv
" nnoremap N Nzzzv
" Since we borrowed , for the mapleader, replicate its purpose in \
" (the mapleader we displaced).
nnoremap \ ,
" Open a Quickfix window for the last search.
nnoremap <silent> <leader>/ :execute 'vimgrep /'.@/.'/g %'<cr>:copen<cr>
" Start a search with the ack plugin
nnoremap <leader>a :Ack --smart-case<space>
" ------------------------------------------------------------------------ }}}
" Diff {{{
nnoremap <silent> <leader>d :call DiffToggle()<cr>
function! DiffToggle()
if &diff
diffoff
else
diffthis
endif
endfunction
" ------------------------------------------------------------------------ }}}
" Invisibles {{{
" Do not show invisibles by default.
set nolist
" Turn invisibles on/off.
nnoremap <silent> <leader>i :set list!<cr>
" How to display tabs, EOL, and other invisibles.
if has('multi_byte')
set encoding=utf-8
"set showbreak=↪
set listchars=tab:▸\ ,eol:¬,extends:❯,precedes:❮
else
set listchars=tab:>-,eol:$,extends:>,precedes:<
endif
" ------------------------------------------------------------------------ }}}
" Abbreviations {{{
" Lorem ipsum text
abbr lorem Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras a ornare metus. In justo metus, auctor nec semper in, laoreet porttitor augue. Maecenas tortor libero, dignissim vel placerat sit amet, malesuada ut quam. Curabitur vitae velit lacus, sed imperdiet sapien. Sed posuere, odio nec pharetra adipiscing
" ------------------------------------------------------------------------ }}}
" Expansion and completion {{{
" Keystroke used for 'expansion' on the command line. Default is <c-e>.
set wildchar=<tab>
" Show me more than the first possible completion.
set wildmenu
" Behave like a shell, show me completion only to point of ambiguity.
set wildmode=list:longest
" Toggle English-word completion from system dictionary. (^n, ^p)
nnoremap <silent> <leader>E :call ToggleFlag('complete', 'k', 'English completion')<cr>
" ------------------------------------------------------------------------ }}}
" Text object 'N': number {{{
onoremap N :<c-u>call <sid>NumberTextObject(0)<cr>
xnoremap N :<c-u>call <sid>NumberTextObject(0)<cr>
onoremap aN :<c-u>call <sid>NumberTextObject(1)<cr>
xnoremap aN :<c-u>call <sid>NumberTextObject(1)<cr>
onoremap iN :<c-u>call <sid>NumberTextObject(1)<cr>
xnoremap iN :<c-u>call <sid>NumberTextObject(1)<cr>
function! s:NumberTextObject(whole)
normal! v
while getline('.')[col('.')] =~# '\v[0-9]'
normal! l
endwhile
if a:whole
normal! o
while col('.') > 1 && getline('.')[col('.') - 2] =~# '\v[0-9]'
normal! h
endwhile
endif
endfunction
" ------------------------------------------------------------------------ }}}
" Spelling {{{
" System dictionary to use
set dictionary=/usr/share/dict/words
" Spellcheck language
set spelllang=en_us
" Toggle spellcheck mode
nnoremap <leader>s :set spell!<cr>
" ------------------------------------------------------------------------ }}}
" Windows and tabpages {{{
" Create new windows below/at right of current one, if no direction was specified.
set splitbelow
set splitright
" Create a new vertical window to the right, and switch to it.
nnoremap <silent> <leader>w :wincmd v<cr>:wincmd l<cr>
" Easier window nav keys (ctrl-<direction>)
" Look in plugin/tmux_navigator.vim now
"nnoremap <silent> <c-h> :wincmd h<cr>
"nnoremap <silent> <c-j> :wincmd j<cr>
"nnoremap <silent> <c-k> :wincmd k<cr>
"nnoremap <silent> <c-l> :wincmd l<cr>
" Use default split window height (0 disables special help height).
set helpheight=0
" Open a new tab in the current view.
nnoremap <silent> <leader>t :tabnew<cr>
" Tab navigation
"nnoremap <c-h> :tabprevious<cr>
nnoremap <c-t> :tabnext<cr>
" Resize splits when the window is resized.
autocmd VimResized * :wincmd =
" ------------------------------------------------------------------------ }}}
" GUI window size {{{
if has('gui_running')
set lines=40
set columns=90
endif
" ------------------------------------------------------------------------ }}}
" Finding and opening files {{{
" List of directories to search when I specify a file with an edit command.
set path=.
" cd to the directory of the current file. Makes it easier to :e
" files in the same directory... but it breaks gitv.
" autocmd BufEnter * cd %:p:h
" Ignore filename with any of these suffixes when using the
" ":edit" command. Most of these are files created by LaTeX.
set suffixes=.aux,.bak,.dvi,.gz,.idx,.log,.ps,.swp,.tar,.tgz,.sit,.dmg,.hqx
" Search for files with CtrlP
nnoremap <leader>* :CtrlP<cr>
" Open filename under cursor (optionally in new tab or window)
nnoremap <leader>of gf
vnoremap <leader>of gf
nnoremap <leader>ow :wincmd f
vnoremap <leader>ow :wincmd f
nnoremap <leader>ot :wincmd gf
vnoremap <leader>ot :wincmd gf
" Open a file browser
nnoremap <leader>e :edit .<cr>
" NERDTree window
nnoremap <leader>f :NERDTreeToggle<CR>
" ------------------------------------------------------------------------ }}}
" Shell and external commands {{{
" Shell to use. Stick with the old standard.
let &shell='/bin/sh'
" Execute the current line via the default shell, replacing the line with
" the resulting output.
nnoremap <silent> <leader>X :echo 'Executing...'<cr>:execute ':.!' . &shell<cr>
" Automatically save modifications to files when you use
" critical (external) commands.
set autowrite
" QuickRun the current buffer, autodetecting syntax
nnoremap <leader>r :QuickRun<cr>
" Read current buffer, turn it into a bookmarklet, insert that bookmarklet
" in a comment on line 1 (discarding previously inserted bookmarklet if it
" exists), copy bookmarklet to the clipboard.
nnoremap <silent> <leader>B :%!$HOME/.vim/bin/bookmarklet_build.pl<cr>
" Preview a markdown file in the default browser
if exists('s:has_darwin')
nnoremap <leader>M :w!<cr>:!$HOME/.vim/bin/markdownify % > /tmp/%.html && open /tmp/%.html<cr><cr>
endif
" Convert file, or selection, so each contiguous non-whitespace blob is
" on its own line. Strip all other whitespace.
nnoremap <leader>O :%!$HOME/bin/convert-to-one-string-per-line.rb<cr>
vnoremap <leader>O :!$HOME/bin/convert-to-one-string-per-line.rb<cr>
if has('python') && exists('s:has_darwin')
" Reload Google Chrome on Mac from Vim.
" Adapted from: https://github.com/gcollazo/BrowserRefresh-Sublime/
function! ChromeReload()
python << EOF
from subprocess import call
browser = """
tell app "Google Chrome" to tell the active tab of its first window
reload
end tell
"""
call(['osascript', '-e', browser])
EOF
endfunction
" Reload Safari on Mac from Vim.
function! SafariReload()
python << EOF
from subprocess import call
browser = """
tell application "Safari"
do JavaScript "window.location.reload()" in front document
end tell
"""
call(['osascript', '-e', browser])
EOF
endfunction
endif
" Map one or the other depending which browser I'm mostly using right now.
" nnoremap <silent> <leader>R :call SafariReload()<cr>
nnoremap <silent> <leader>R :call ChromeReload()<cr>
" ------------------------------------------------------------------------ }}}
" Fonts and colors {{{
if has('gui_running')
set guifont=Menlo\ Regular:h14
set antialias
endif
set background=light
colorscheme solarized
" Mark Git-style conflict markers, and trailing whitespace.
match ErrorMsg '\(\s\+$\|\(^\(<\|=\|>\)\{7\}\([^=].\+\)\?$\)\)'
" ------------------------------------------------------------------------ }}}
" Syntax {{{
" Syntax: General {{{
" 'syntax enable' will turn on syntax highlighting without wiping out
" any highlight commands already in place. 'syntax on' will reset it
" all to defaults. So I use 'syntax on' and put my highlight commands
" after this point, that way I can ':so ~/.vimrc' and reset everything
" whenever I want.
syntax on
" When positioned on a bracket, highlight its partner.
set showmatch
" Modelines are kind of ugly, and I've read there are security problems
" with them. Disabling.
" Hah, this is funny, I was just trying to convince my team to start using
" modelines, and here I have them disabled, claiming security problems.
set nomodeline
set modelines=0
" Re-indent entire file, preserving cursor location
"nnoremap <leader>= :call Preserve('normal! gg=G')<cr>
" Create an HTML version of our syntax highlighting for display or printing.
nnoremap <leader>H :TOhtml<cr>
" Ask Vim for the syntax type at cursor location
nnoremap <leader>? :call SynStack()<cr>
" ------------------------------------------------------------------------ }}}
" Syntax: BIND {{{
autocmd BufNewFile,BufRead *.com set filetype=bindzone
" ------------------------------------------------------------------------ }}}
" Syntax: C {{{
autocmd FileType c setlocal foldmethod=syntax
" ------------------------------------------------------------------------ }}}
" Syntax: Email and Exim {{{
autocmd BufNewFile,BufRead aliases.* set filetype=mailaliases
autocmd BufNewFile,BufRead exim.cf* set filetype=exim
" ------------------------------------------------------------------------ }}}
" Syntax: Epub {{{
" Look inside .epub files
au BufReadCmd *.epub call zip#Browse(expand('<amatch>'))
" ------------------------------------------------------------------------ }}}
" Syntax: Erlang {{{
autocmd BufNewFile,BufRead ejabberd.cfg set filetype=erlang
" ------------------------------------------------------------------------ }}}
" Syntax: help {{{
autocmd Filetype help nnoremap <buffer> <space> <PageDown>
autocmd Filetype help nnoremap <buffer> <PageUp>
" ------------------------------------------------------------------------ }}}
" Syntax: Javascript {{{
autocmd BufNewFile,BufRead *.json set filetype=javascript
autocmd Filetype javascript nnoremap <leader>J <esc>:%!json_xs -f json -t json-pretty<cr>
" ------------------------------------------------------------------------ }}}
" Syntax: M4 {{{
autocmd BufNewFile,BufRead *.global set filetype=m4
" ------------------------------------------------------------------------ }}}
" Syntax: Make {{{
" Makefile requires real tabs, not spaces, enforce that
autocmd BufNewFile,BufRead [Mm]akefile* set filetype=make
autocmd Filetype make setlocal noexpandtab
" ------------------------------------------------------------------------ }}}
" Syntax: Markdown, MultiMarkdown, Octopress {{{
" Octopress is a superset of Markdown so just use it everywhere.
" Set line wrapping for convenience.
autocmd BufNewFile,BufRead *.md,*.markdown set filetype=octopress
autocmd FileType markdown,octopress setlocal tw=78 wrap lbr ts=4 sw=4 sts=4
" Bold/italic for Markdown/Octopress (plugin 'surround')
autocmd FileType markdown,octopress let b:surround_{char2nr('i')} = "*\r*"
autocmd FileType markdown,octopress let b:surround_{char2nr('b')} = "**\r**"
" ------------------------------------------------------------------------ }}}
" Syntax: Mediawiki {{{
autocmd BufNewFile,BufRead *.wiki,*ISSwiki* set filetype=mediawiki
" smarter wrapping
autocmd FileType mediawiki setlocal tw=78 wrap lbr ts=4 sw=4 sts=4
" Italic, bold surrounds for Mediawiki (plugin 'surround')
autocmd FileType mediawiki let b:surround_{char2nr('i')} = "''\r''"
autocmd FileType mediawiki let b:surround_{char2nr('b')} = "'''\r'''"
" Header levels 2, 3, 4
autocmd FileType mediawiki let b:surround_{char2nr('2')} = "==\r=="
autocmd FileType mediawiki let b:surround_{char2nr('3')} = "===\r==="
autocmd FileType mediawiki let b:surround_{char2nr('4')} = "====\r===="
" ------------------------------------------------------------------------ }}}
" Syntax: Perl {{{
autocmd BufNewFile,BufRead *.t set filetype=perl
" ------------------------------------------------------------------------ }}}
" Syntax: PHP {{{
autocmd BufNewFile,BufRead *.inc set filetype=php
" ------------------------------------------------------------------------ }}}
" Syntax: Rdist {{{
autocmd BufNewFile,BufRead distfile.common set filetype=rdist
" ------------------------------------------------------------------------ }}}
" Syntax: Ruby {{{
" autocmd FileType ruby setlocal foldmethod=syntax
" ------------------------------------------------------------------------ }}}
" Syntax: Shell {{{
autocmd BufNewFile,BufRead .bash/*,bash/* set filetype=sh
" ------------------------------------------------------------------------ }}}
" Syntax: Taskpaper {{{
autocmd BufNewFile,BufRead *.taskpaper setlocal foldmethod=indent noexpandtab
autocmd BufNewFile,BufRead *.taskpapertheme set filetype=xml
" ------------------------------------------------------------------------ }}}
" Syntax: Template Toolkit {{{
autocmd BufNewFile,BufRead *.tt2 set filetype=tt2html
" ------------------------------------------------------------------------ }}}
" Syntax: Text {{{
autocmd BufNewFile,BufRead *.txt set filetype=text
" ------------------------------------------------------------------------ }}}
" Syntax: Vim {{{
" Snippet files need real tabs, at least on the left margin.
" This works out okay because when they're triggered, if expandtab
" is set, they will be translated to spaces during expansion.
autocmd FileType snippet setlocal noexpandtab
" ------------------------------------------------------------------------ }}}
" Syntax: YAML {{{
" YAML requires spaces, not tabs
autocmd FileType yaml setlocal expandtab ts=2 sts=2 sw=2
" ------------------------------------------------------------------------ }}}
" ------------------------------------------------------------------------ }}}
" Highlight interesting words {{{
" A Steve Losh joint
" This needs to be at or near the end of .vimrc for some reason, to work.
" This mini-plugin provides a few mappings for highlighting words temporarily.
"
" Sometimes you're looking at a hairy piece of code and would like a certain
" word or two to stand out temporarily. You can search for it, but that only
" gives you one color of highlighting. Now you can use <leader>N where N is
" a number from 1-6 to highlight the current word in a specific color.
function! HiInterestingWord(n)
" Save our location.
normal! mz
" Yank the current word into the z register.
normal! "zyiw
" Calculate an arbitrary match ID. Hopefully nothing else is using it.
let b:mid = 86750 + a:n
" Clear existing matches, but don't worry if they don't exist.
silent! call matchdelete(b:mid)
" Construct a literal pattern that has to match at boundaries.
let b:pat = '\V\<' . escape(@z, '\') . '\>'
" Actually match the words.
call matchadd("InterestingWord" . a:n, b:pat, 1, b:mid)
" Move back to our original location.
normal! `z
endfunction
" Mappings
nnoremap <silent> <leader>1 :call HiInterestingWord(1)<cr>
nnoremap <silent> <leader>2 :call HiInterestingWord(2)<cr>
nnoremap <silent> <leader>3 :call HiInterestingWord(3)<cr>
nnoremap <silent> <leader>4 :call HiInterestingWord(4)<cr>
nnoremap <silent> <leader>5 :call HiInterestingWord(5)<cr>
nnoremap <silent> <leader>6 :call HiInterestingWord(6)<cr>
" Default Highlights
hi def InterestingWord1 guifg=#000000 ctermfg=16 guibg=#ffa724 ctermbg=214
hi def InterestingWord2 guifg=#000000 ctermfg=16 guibg=#aeee00 ctermbg=154
hi def InterestingWord3 guifg=#000000 ctermfg=16 guibg=#8cffba ctermbg=129
hi def InterestingWord4 guifg=#000000 ctermfg=16 guibg=#b88853 ctermbg=137
hi def InterestingWord5 guifg=#000000 ctermfg=16 guibg=#ff9eb8 ctermbg=211
hi def InterestingWord6 guifg=#000000 ctermfg=16 guibg=#ff2c4b ctermbg=195
" ------------------------------------------------------------------------ }}}
" Local customizations {{{
" Override this file without modifying the master copy in git.
if filereadable($HOME . '/.vimrc.local')
source ~/.vimrc.local
endif
" ------------------------------------------------------------------------ }}}