This repository was archived by the owner on Feb 16, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvimrc
More file actions
827 lines (646 loc) · 24.4 KB
/
vimrc
File metadata and controls
827 lines (646 loc) · 24.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
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
" .vimrc
" Author: Franco Saliola <saliola@gmail.com>
" credit: various sources, including steve losh's vimrc http://bitbucket.org/sjl/dotfiles/src/tip/vim/
" Things to look up ------------------------------------------------------- {{{
"
" <C-x><C-f>
" <C-x><C-l>
" <C-x><C-]>
" g*
" g#
" g;
" g,
" gv (reselect last visual selection)
" =ip (format inner paragraph)
" `` (jump to position before last jump)
" Explore
" Texplore
" tip: s//bar/g will replace the current search pattern with bar
" vim-unimpaired mappings
" :set spell spelllang=fr
" cox from vim-unimpaired to toggle cursorline and cursorcolumn (x)
" @: -- repeat last command-line (then use @@ to repeat)
" @@ -- repeat last @{0-9a-z":*} command
" :w !cmd -- execute cmd with give lines as std input, but do not replace (:write_c)
" :[range]m[move] {address} -- Move the lines given by [range] to below the line given by {address}.
" :[range]co[py] {address} -- Copy the lines given by [range] to below the line given by {address}.
" :t -- Synonym for copy.
"
" ------------------------------------------------------------------------- }}}
" On startup -------------------------------------------------------------- {{{
" Force version of Python to be used
if has('python3')
endif
" ------------------------------------------------------------------------- }}}
" vim-plug ---------------------------------------------------------------- {{{
call plug#begin('~/.vim/plugged')
" Configurations
Plug 'tpope/vim-sensible'
Plug 'tpope/vim-unimpaired'
Plug 'tpope/vim-repeat'
" Appearance
Plug 'mhinz/vim-startify'
Plug 'saliola/vim-airline', { 'branch': 'charcount' }
Plug 'arcticicestudio/nord-vim', { 'branch': 'develop' }
Plug 'Yggdroot/indentLine'
Plug 'haishanh/night-owl.vim'
" File navigation and System interaction
Plug 'tpope/vim-vinegar'
Plug 'tpope/vim-eunuch'
Plug 'tpope/vim-dispatch'
" Git / Mercurial / Subversion
Plug 'mhinz/vim-signify'
Plug 'tpope/vim-fugitive'
Plug 'junegunn/gv.vim'
" Tmux
Plug 'christoomey/vim-tmux-navigator'
Plug 'tpope/vim-tbone'
" Editing
Plug 'tpope/vim-commentary'
Plug 'tpope/vim-surround'
Plug 'SirVer/ultisnips'
Plug 'honza/vim-snippets'
Plug 'junegunn/vim-easy-align'
Plug 'andymass/vim-matchup'
" LaTeX
Plug 'lervag/vimtex'
" Sage
Plug 'saliola/vim-sage', { 'for': 'sage' }
" Testing: improved searching
Plug 'junegunn/vim-slash'
Plug 'wellle/context.vim'
call plug#end()
" ------------------------------------------------------------------------- }}}
" Leaders ----------------------------------------------------------------- {{{
" map Space to leader, so that leader commands appear in showcmd area
let mapleader = " "
map <Space> <Leader>
" set localleader to q (first disable q for recording macros)
nnoremap q <Nop>
let maplocalleader = "q"
nnoremap <leader>q q
" ------------------------------------------------------------------------- }}}
" vimrc ------------------------------------------------------------------- {{{
map <leader>vrc :tabnew $HOME/.vim/vimrc<CR>
map <leader>vb :Texplore $HOME/.vim/plugged/<CR>
" Source the vimrc file after saving it
augroup vimrc
au!
au bufwritepost .vimrc source $MYVIMRC
au bufwritepost ~/.vim/vimrc source $MYVIMRC
augroup END
augroup ft_vim
au!
au FileType vim setlocal foldmethod=marker
au FileType help setlocal textwidth=78
au FileType vim setlocal keywordprg=:help
au BufWinEnter *.txt if &ft == 'help' | setlocal keywordprg=:help | endif
augroup END
" ------------------------------------------------------------------------- }}}
" Basic options ----------------------------------------------------------- {{{
set visualbell
set viminfo='20,\"50 " read/write a .viminfo file with at most 50 lines
" General Editing {{{ "
set encoding=utf-8
set nojoinspaces " only put one space after periods
set textwidth=0 " set textwidth to 75 to cause wrapping
set scrolloff=1 " always show n screen lines to above and below the cursor
set tabstop=4|set shiftwidth=4|set softtabstop=4|set expandtab " tab settings for all files
set nowrap " don't wrap text ; I have a wide monitor
" show tabs, etc.
set list
set listchars=tab:▸-,extends:❯,precedes:❮
"set listchars+=eol:¬
set showbreak=…
match ErrorMsg /\t/
set backspace=indent,eol,start " allow backspacing over everything in insert mode
set formatoptions+=1n
set linebreak
set hidden
" }}} General Editing "
" Searching {{{ "
" Settings:
" - hightlight search results (hlsearch)
" - enable incremental search (incsearch)
" - ignore case in search patterns (ignorecase)
" - case-sensitive if the pattern contains uppercase characters (smartcase)
set hlsearch
set incsearch
set ignorecase
set smartcase
" }}} Searching "
" Status line {{{ "
set laststatus=2
set showmode
set showcmd
set ruler " show the cursor position all the time
" }}} Status line "
" Line numbers {{{ "
set number
set relativenumber
" }}} Line numbers "
" Undo / Redo / Backup / Swap {{{ "
set undofile
set undoreload=10000
set undodir=~/.vim/tmp/undo// " undo files
set backup
set backupdir=~/.vim/tmp/backup// " backups
set directory=~/.vim/tmp/swap// " swap files
set noswapfile " no swap files
" use 'U' for "redo" since 'u' is "undo"
noremap U <c-r>
" }}} Undo / Redo / Backup / Swap "
" Windows {{{ "
set splitbelow
set splitright
" Resize splits when the window is resized
au VimResized * :wincmd =
" use | and - to split windows, which mimics tmux behaviour
nnoremap <silent> <C-W>\| <C-W>v
nnoremap <silent> <C-W>- <C-W>s
" }}} Windows "
" Spelling {{{ "
set nospell
set spellsuggest=5
"set dictionary+=~/.vim/spell/fr.utf-8.spl
" TODO: this is somewhat useful, but we need something better
" " Look up word under cursor in a dictionary:
" " - <Leader>d : Dictionary.app in Mac OSX
" " - <Leader>gd : google dictionary (launch browser)
" " - <Leader>wd : wordnet (launch browser)
" " - <Leader>mw : merriam-webster thesaurus (launch browser)
" if has("unix")
" let s:uname = system("uname")
" if s:uname == "Darwin\n"
" " Source: http://tammersaleh.com/posts/using-dictionary-app-with-vim/
" nnoremap <silent> <Leader>d :!open dict://<cword><CR><CR>
" else
" nnoremap <silent> <Leader>d :!open "https://www.google.ca/webhp?\#q=define:"<cword><CR><CR>
" endif
" endif
" nnoremap <silent> <Leader>gd :!open "https://www.google.ca/webhp?\#q=define:"<cword><CR><CR>
" nnoremap <silent> <Leader>wn :!open "http://wordnetweb.princeton.edu/perl/webwn?s="<cword><CR><CR>
" nnoremap <silent> <Leader>mw :!open "http://www.merriam-webster.com/thesaurus/"<cword><CR><CR>
" }}} Spelling "
" Thesaurus {{{ "
set thesaurus+=~/.vim/thesaurus/mthesaur.txt
" }}} Thesaurus "
" Printing {{{ "
" header:0 Do not print a header.
" number:y Include line numbers in the printed output. (default:n)
" wrap:n Truncate long lines.
set printoptions=paper:letter,number:n,header:0,wrap:n,duplex:long
" }}} Printing "
" Command line mode ------------------------------------------------------- {{{
" wild card settings
set wildmenu
set wildmode=list:full
set history=50 " 50 lines of command lines history
" cursor movement in command line mode
cnoremap <C-a> <Home>
cnoremap <C-e> <End>
" ------------------------------------------------------------------------- }}}
" ------------------------------------------------------------------------- }}}
" Line Return ------------------------------------------------------------- {{{
" Make sure Vim returns to the same line when you reopen a file.
" Thanks, Steve Losh https://bitbucket.org/sjl/dotfiles/src/tip/vim/vimrc
augroup line_return
au!
au BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ execute 'normal! g`"zvzz' |
\ endif
augroup END
" ------------------------------------------------------------------------- }}}
" Mappings ---------------------------------------------------------------- {{{
" Insert the current directory into a command-line path
" Notes:
" - if path contains whitespace, then ``escape`` will escape them
cmap <C-P> <C-R>=escape(expand("%:p:h"),' ') . "/"<CR>
" Insert the current filename into a command-line path
cmap %% <C-R>=escape(expand("%"),' ')<CR>
map <Leader>tn :tabnew<Space>
map <Leader>tt :tabnew %<CR>
map <Leader>ts :tabnew +Startify<CR>
" Scratchpad settings
command! ScratchPad :tabnew ~/Dropbox/scratchpad.rst
" Fullscreen with
" command! FullScreenEditing :vertical new readonly | :vertical resize 120 | :wincmd w
command! FullScreenEditing :vertical new | :vertical resize 120 | :wincmd w
" Make the help key do something useful.
noremap <F1> :checktime<cr>
inoremap <F1> <esc>:checktime<cr>
" Make the Q key to something useful.
nnoremap Q gqip
vnoremap Q gq
" Join an entire paragraph.
" Source: Steve Losh
nnoremap <Leader>J mzvipJ`z
" Don't move on *
" Source: Steve Losh
nnoremap <silent> * :let stay_star_view = winsaveview()<cr>*:call winrestview(stay_star_view)<cr>
" Highlight next search by pulsing the CursorLine and CursorColumn; also, open
" just enough folds to make the line in which the cursor is located not folded.
"
" Source: mashup of Damien Conway's idea and Steve Losh's Pulse and zv
nnoremap <silent> n nzv:PulseX<cr>
nnoremap <silent> N Nzv:PulseX<cr>
" Skip over closed folds with { and }
nnoremap <expr> } foldclosed(search('^$', 'Wn')) == -1 ? "}" : "}j}"
nnoremap <expr> { foldclosed(search('^$', 'Wnb')) == -1 ? "{" : "{k{"
" set gV to select the most recently changed text (use to select pasted text,
" like how gv selects the previously-selected text in visual mode)
nnoremap <expr> gV '`[' . getregtype()[0] . '`]'
" ------------------------------------------------------------------------- }}}
" Folding ----------------------------------------------------------------- {{{
" From Steve Losh:
" "Focus" the current line. Basically:
"
" 1. Close all folds.
" 2. Open just the folds containing the current line.
" 3. Move the line a few lines above the center of the screen.
" 4. Pulse the cursor line.
"
" Warning: This mapping wipes out the z mark.
nnoremap <Leader>f mzzMzvzz10<c-e>`z:Pulse<cr>
" toggle fold with za
nnoremap <Leader><Space> za
" ------------------------------------------------------------------------- }}}
" Appearance -------------------------------------------------------------- {{{
colorscheme my-colorscheme
" ------------------------------------------------------------------------- }}}
" Plugin settings --------------------------------------------------------- {{{
" UltiSnips --------------------------------------------------------------- {{{
let g:snips_author="Franco Saliola"
let g:snips_author_email="saliola@gmail.com"
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
let g:UltiSnipsEditSplit="vertical"
" ------------------------------------------------------------------------- }}}
" Commentary -------------------------------------------------------------- {{{
nmap <leader>c <Plug>CommentaryLine
xmap <leader>c <Plug>Commentary
augroup plugin_commentary
au!
au FileType python,sage setlocal commentstring=#%s
augroup END
" ------------------------------------------------------------------------- }}}
" vim-tmux-navigator {{{ "
" vim-tmux-navigator overwrites <C-l>, so I need another way to use nohlsearch.
nnoremap <silent> <Esc><Esc> <Esc>:nohlsearch<CR><Esc>
" }}} vim-tmux-navigator "
" vim-signify {{{ "
" Some Notes:
" :SignifyRefresh
" :SignifyToggle
" :SignifyToggleHighlight
" mappings: ]c / [c to move between changes / hunks
" text object: ic / ac
let g:signify_vcs_list = [ 'git', 'hg', 'svn' ]
omap ic <plug>(signify-motion-inner-pending)
xmap ic <plug>(signify-motion-inner-visual)
omap ac <plug>(signify-motion-outer-pending)
xmap ac <plug>(signify-motion-outer-visual)
" }}} vim-signify "
" vim-dispatch {{{ "
nnoremap <Leader>d :Dispatch<CR>
nnoremap <Leader>D :Dispatch!<CR>
nnoremap <Leader>m :Make<CR>
nnoremap <Leader>M :Make!<CR>
" }}} vim-dispatch "
" vim-startify {{{ "
autocmd User Startified setlocal cursorline
let g:startify_bookmarks = [ '~/.vim/vimrc' ]
let g:startify_files_number = 20
let g:startify_change_to_dir = 1
hi StartifyFooter ctermfg=240
hi StartifyHeader ctermfg=114
hi StartifyPath ctermfg=245
hi StartifySpecial ctermfg=240
" }}} vim-startify "
" vim-airline {{{ "
let airline#extensions#wordcount#enabled = 1
let airline#extensions#charcount#enabled = 1
let airline#extensions#charcount#countspaces = 1
let airline#extensions#charcount#filetypes = 'help|markdown|rst|org|text'
" }}} vim-airline "
" vim-unimpaired {{{ "
nnoremap ]t :tabnext<CR>
nnoremap [t :tabprevious<CR>
" }}} vim-unimpaired
" ------------------------------------------------------------------------- }}}
" Filetype-specific ------------------------------------------------------- {{{
" txt / rst {{{
augroup ft_txt
au!
" Use ReStructuredText syntax highlighting for .txt files
autocmd BufWinEnter *.txt if &ft != 'help' | set filetype=rst | endif
augroup END
augroup ft_rst
au!
" set iskeyword (rst syntax file loads the lisp syntax file for code
" blocks, which overwrites iskeyword)
" au FileType rst setlocal iskeyword=@,48-57,a-z,A-Z,192-255
au FileType rst setlocal iskeyword=@,48-57,_,192-255
augroup END
" }}}
" notes {{{
augroup ft_notes
au!
" Use ReStructuredText syntax highlighting for .notes and .txt files
autocmd BufRead,BufNewFile *.notes set filetype=rst
augroup END
" }}}
" Hg {{{
function! OpenHGRejectFile()
" splits window and opens the %.rej
let filename=expand('%')
let rejectsfile = filename.'.rej'
split
execute 'edit '.rejectsfile
endfunction
command! HGRejects :call OpenHGRejectFile()
" }}}
" Python {{{
augroup ft_python
autocmd!
autocmd FileType python,sage setlocal tabstop=4 shiftwidth=4 softtabstop=4 expandtab
autocmd FileType python,sage setlocal wildignore+=*.pyc
augroup END
" }}}
" bash vi-input mode {{{
" Syntax highlighting in Bash vi-input mode
" Source: http://stackoverflow.com/questions/7115324/syntax-highlighting-in-bash-vi-input-mode/7115478#7115478
augroup bash_vi_input_mode
au!
au BufRead,BufNewFile bash-fc-* set filetype=sh
augroup END
" }}}
" xmonad.hs {{{ "
" recompile and restart xmonad on save
augroup xmonad
au!
au bufwritepost xmonad.hs :!xmonad --recompile && xmonad --restart
augroup END
" }}} xmonad.hs "
" ------------------------------------------------------------------------- }}}
" Latex ------------------------------------------------------------------- {{{
if has("unix")
let s:uname = system("uname")
if s:uname == "Linux\n"
let g:vimtex_view_method = 'mupdf'
endif
if s:uname == "Darwin\n"
let g:vimtex_view_method = 'skim'
endif
endif
let g:vimtex_fold_enabled = 1 " -- default value is 0
let g:vimtex_fold_types = {
\ 'preamble' : {'enabled' : 0},
\ 'items' : {'enabled' : 0},
\ 'comments' : {'enabled' : 1},
\ 'envs' : {
\ 'blacklist' : [],
\ 'whitelist' : ['solution'],
\ },
\}
let g:vimtex_compiler_latexmk = {
\ 'backend' : 'process',
\ 'background' : 0,
\ 'build_dir' : 'latexoutput',
\ 'callback' : 1,
\ 'continuous' : 0,
\ 'options' : [
\ '-g',
\ '-pdf',
\ '-cd',
\ '-interaction=nonstopmode',
\ '-bibtex-cond',
\ '-e "\$pdflatex .= '' && cp -v latexoutput/\%R.pdf .''"'
\ ],
\}
augroup ft_tex
autocmd!
" ignore these filenames during tab completion
autocmd FileType tex setlocal wildignore+=*.out,*.synctex.gz,*.aux,*.ilg,*.log,*.nls,*.idx,*.ind,*.blg,*.nlo,*.pdf,*.toc
" set iskeyword (tex syntax file overides this....)
autocmd FileType tex setlocal iskeyword=@,48-57,_,192-255
" if there is no Makefile, then set dispatch command
if ! filereadable(expand("Makefile"))
autocmd FileType tex echo "setting makeprg to latexmk ..."
autocmd FileType tex setlocal makeprg=latexmk\ -f\ -g\ -pdf\ -output-directory=latexoutput\ -interaction=nonstopmode\ -bibtex-cond\ %
endif
" the `` at the end moves the cursor to the position before the last jump
autocmd FileType tex nnoremap <Leader>d :make<CR>``
autocmd FileType tex nnoremap <Leader>D :make!<CR>``
autocmd FileType tex nnoremap <Leader>m :make<CR>``
autocmd FileType tex nnoremap <Leader>M :make!<CR>``
augroup END
" ------------------------------------------------------------------------- }}}
" Useful functions -------------------------------------------------------- {{{
" yank / paste from the clipboard ------------------------------------------ {{{
" toggle (no)paste before pasting from the clipboard
" Reference: http://tilvim.com/2014/03/18/a-better-paste.html
nnoremap <Leader>p :set paste<CR>"*]p:set nopaste<cr>
" yank to system clipboard
vmap <Leader>y "+y
nmap <Leader>yy "+yy
" ------------------------------------------------------------------------- }}}
" Diff current file with the version on disk ------------------------------ {{{
" [From Hacking Vim, Chapter 4, by Kim Schulz]
function! DiffWithFileFromDisk()
let filename=expand('%')
let diffname = filename.'.fileFromBuffer'
execute 'saveas! '.diffname
diffthis
vsplit
execute 'edit '.filename
diffthis
endfunction
" ------------------------------------------------------------------------- }}}
" Open the url under the cursor with gx ----------------------------------- {{{
if has("unix")
let s:uname = system("uname")
if s:uname == "Darwin\n"
" defaults to 'open' on Mac OSX
let g:netrw_browsex_viewer='-'
else
let g:netrw_browsex_viewer='gvfs-open'
endif
endif
" ------------------------------------------------------------------------- }}}
" Show the highlight group syntax under the cursor ------------------------ {{{
" Show the stack of syntax hilighting classes affecting whatever is under the
" cursor.
" Source: Steve Losh
function! SynStack()
echo join(map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")'), " > ")
endfunc
" ------------------------------------------------------------------------- }}}
" Pulse Line -------------------------------------------------------------- {{{
" Source: Steve Losh
function! s:PulseX(pulsesteps, pulseline, pulsecolumn, color) " {{{
if a:pulseline == 1
redir => old_hi_cursorline
silent execute 'hi CursorLine'
redir END
let old_hi_cursorline = split(old_hi_cursorline, '\n')[0]
let old_hi_cursorline = substitute(old_hi_cursorline, 'xxx', '', '')
endif
if a:pulsecolumn == 1
redir => old_hi_cursorcolumn
silent execute 'hi CursorColumn'
redir END
let old_hi_cursorcolumn = split(old_hi_cursorcolumn, '\n')[0]
let old_hi_cursorcolumn = substitute(old_hi_cursorcolumn, 'xxx', '', '')
endif
let steps = a:pulsesteps
let width = 1
let start = width
let end = steps * width
let color = a:color
for i in range(start, end, width)
if a:pulseline
execute "hi CursorLine ctermbg=" . (color + i)
endif
if a:pulsecolumn
execute "hi CursorColumn ctermbg=" . (color + i)
endif
redraw
sleep 6m
endfor
for i in range(end, start, -1 * width)
if a:pulseline
execute "hi CursorLine ctermbg=" . (color + i)
endif
if a:pulsecolumn
execute "hi CursorColumn ctermbg=" . (color + i)
endif
redraw
sleep 6m
endfor
if a:pulseline
execute 'hi ' . old_hi_cursorline
endif
if a:pulsecolumn
execute 'hi ' . old_hi_cursorcolumn
endif
endfunction " }}}
command! -nargs=0 Pulse call s:PulseX(4, 1, 0, 160)
command! -nargs=0 PulseX call s:PulseX(2, 1, 1, 240)
" ------------------------------------------------------------------------- }}}
" Indent Guides ----------------------------------------------------------- {{{
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 " }}}
hi def IndentGuides guibg=#303030 ctermbg=234
nnoremap <leader>I :call IndentGuides()<cr>
" ------------------------------------------------------------------------- }}}
" GetDigraphWrapper {{{ "
" Wrap C-k to allow backspace to interrupt digraph insertion;
" currently, it spits out <BS>, which is completely useless
" Source: loosely inspired by Damien Conway's HUDigraphs
function! GetDigraphWrapper ()
let char1 = getchar()
if (char1 == "\<BS>") | return "" | endif
let char2 = getchar()
if (char2 == "\<BS>") | return "" | endif
return "\<C-K>" . nr2char(char1) . nr2char(char2)
endfunction
inoremap <expr> <C-K> GetDigraphWrapper()
cnoremap <expr> <C-K> GetDigraphWrapper()
" }}} GetDigraphWrapper "
" Cursorline {{{ "
function! RedCursorLine()
let w:red_cursor = exists('w:red_cursor') ? !w:red_cursor : 0
if w:red_cursor
colorscheme my-colorscheme
set cursorline
set cursorcolumn
else
set cursorline
hi CursorLine cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white
set nocursorcolumn
hi CursorColumn cterm=NONE ctermbg=darkred ctermfg=white guibg=darkred guifg=white
set colorcolumn=
endif
endfunction
command! RedCursorLine :call RedCursorLine()
" }}} Cursorline "
" FixTrailingWhitespace {{{ "
" Reference: https://github.com/bronson/vim-trailing-whitespace
set listchars+=trail:·
function! s:FixTrailingWhitespace(line1,line2)
let l:save_cursor = getpos(".")
silent! execute ':' . a:line1 . ',' . a:line2 . 's/\s\+$//'
call setpos('.', l:save_cursor)
endfunction
command! -range=% FixTrailingWhitespace call <SID>FixTrailingWhitespace(<line1>,<line2>)
" }}} FixTrailingWhitespace "
" ------------------------------------------------------------------------- }}}
" Mac OSX Specific -------------------------------------------------------- {{{
" For the French keyboard on the MacBook: map the key §/± key to `/~
map! § `
map! ± ~
" ------------------------------------------------------------------------- }}}
" Experimental {{{ "
" Date-stamped file {{{ "
function! EditNewDatestampedFile(filename, extension)
execute 'tabnew '.a:filename.'.'.strftime("%Y-%m-%d").'.'.a:extension
endfunction
" }}} Date-stamped file "
" Quick-fix grep {{{ "
function! GrepResultsInQuickFixWindow(searchpattern)
" Save the current view
let b:currentview = winsaveview()
" Save the current iskeyword setting.
let save_iskeyword = &iskeyword
" Set last search pattern to a:searchpattern
if a:searchpattern =~ "/.\\+/"
let @/=a:searchpattern[1:-2]
else
let @/=a:searchpattern
endif
" Call vimgrep (populates the quickfix window)
execute "lvimgrep ".a:searchpattern.' '.escape(expand("%"),' ')
" open the quickfix window
lopen
" Use the same iskeyword setting as the original window so that search
" matches agree. For instance, if the original window's iskeyword does not
" contain _ (.tex files), then \<alpha\> will not match the alpha in
" alpha_n if _ is in iskeyword. (iskeyword contains _, by default.)
execute 'setlocal iskeyword=' . save_iskeyword
" Use conceal to hide the filename from the location list.
set conceallevel=2 concealcursor=nc
syntax match qfFileName /^[^|]*/ transparent conceal
" For some reason, conceal disables the syntax highlighting of the line
" number, so let's re-establish it.
syntax match myqfLineNr /[0-9]\+ col [0-9]\+/
highlight link myqfLineNr qfLineNr
" Match the current search pattern
execute '2match GrepQuickfixTerm ' . a:searchpattern
" Move to previous window
wincmd w
" Restore the view
call winrestview(b:currentview)
endfunction
hi def GrepQuickfixTerm guifg=#000000 ctermfg=16 guibg=#ffa724 ctermbg=214
" You cannot set the last used search pattern and highlighting from within
" a function, see :help function-search-undo.
command! -nargs=1 QuickFixGrep call GrepResultsInQuickFixWindow(<f-args>)
nnoremap <Leader>g :QuickFixGrep //<Left>
nnoremap <Leader>* "zyiw:execute "QuickFixGrep /\\<".@z."\\>/"<CR>
nnoremap <Leader>g* "zyiw:execute "QuickFixGrep /".@z."/"<CR>
" }}} Quick-fix grep "
" Count non-space characters {{{ "
nnoremap <Leader>w :!cat % \| tr '\n' ' ' \| tr -d ' ' \| wc -c<CR>
" }}} Count non-space characters "
" }}} Experimental "