-
Notifications
You must be signed in to change notification settings - Fork 0
/
vimrc
714 lines (609 loc) · 22.3 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
set nocompatible " be iMproved, required
" Easier to access than the default \
let mapleader = " "
" required, before bundle
filetype off
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'VundleVim/Vundle.vim'
" Comment things out, e.g. with gcc motion
Plugin 'tpope/vim-commentary'
" Popup as you go autocomplete
Plugin 'Valloric/YouCompleteMe'
let g:ycm_filetype_whitelist = {'vim': 1, 'javascript': 1, 'javascript.jsx': 1}
let g:ycm_filetype_blacklist = {
\ 'tagbar': 1,
\ 'qf': 1,
\ 'notes': 1,
\ 'markdown': 1,
\ 'unite': 1,
\ 'text': 1,
\ 'vimwiki': 1,
\ 'pandoc': 1,
\ 'infolog': 1,
\ 'mail': 1,
\ 'gitcommit': 1
\}
" Snippets, snippets, snippets
Plugin 'SirVer/ultisnips'
" Overrides...executing a command and returning to insert? don't care
let g:UltiSnipsExpandTrigger="<C-o>"
let g:UltiSnipsJumpForwardTrigger="<C-o>"
let g:UltiSnipsEditSplit="vertical"
" This...somehow manages to avoid conflict with <BS>. Sweetness.
let g:UltiSnipsJumpBackwardTrigger="<C-h>"
let g:UltiSnipsSnippetsDir=$HOME."/.dotfiles/snippets"
let g:UltiSnipsSnippetDirectories=["UltiSnips", $HOME."/.dotfiles/snippets"]
" Syntax checking w/ rubocop for teh
Plugin 'neomake/neomake'
" R
Plugin 'vim-scripts/Vim-R-plugin'
runtime macros/matchit.vim
" Typescript
Plugin 'leafgarland/typescript-vim'
" Easier to toggle list made by neomake
Plugin 'milkypostman/vim-togglelist'
" Better basic syntax for javascript
Plugin 'jelera/vim-javascript-syntax'
" And better indentation, highlighting
Plugin 'pangloss/vim-javascript'
" And jsx, naturally
Plugin 'mxw/vim-jsx'
" Syntax for mustache too
Plugin 'mustache/vim-mustache-handlebars'
" Syntax highlight for markdown files
Plugin 'plasticboy/vim-markdown'
let g:vim_markdown_folding_disabled=1
" http://ternjs.net/ explains better than I can
Plugin 'marijnh/tern_for_vim'
nnoremap <Leader>g :TernDef<CR>
nnoremap <Leader>r :TernRefs<CR>
" Allows for repeating of plugin movement keys (sneak, surround)
Plugin 'tpope/vim-repeat'
" A good medium range movement key (replaces 's')
Plugin 'justinmk/vim-sneak'
let g:sneak#streak = 1
" nmap s :redr<CR><Plug>(SneakStreak)
" nmap S :redr<CR><Plug>(SneakStreakBackward)
" Replaces s with the 'surround' movement
Plugin 'tpope/vim-surround'
" I like :Gblame, now :Git blame -w
Plugin 'tpope/vim-fugitive'
" A few small supplements to netrw
" Try '-', for example, to open to current file/dir in netrw
Plugin 'tpope/vim-vinegar'
" Ctrl-direction can navigate either vim or tmux splits
Plugin 'christoomey/vim-tmux-navigator'
" CtrlP - Awesome show-as-you-type file searching
Plugin 'ctrlpvim/ctrlp.vim'
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/](\.git|\.hg|\.svn|node_modules|yuidoc|projects\/war\/war|projects\/pages\/reports|javascripts-min|javascripts-prod|javascripts-min-prod|3rdparty|swagger_scripts|licenses|classes|assets\/dist|projects\/adminwar\/war)$',
\ 'file': '\v\.(exe|so|dll|class|orig|swp)$',
\ 'link': '',
\ }
" Faster CtrlP matching
" http://blog.patspam.com/2014/super-fast-ctrlp
let g:ctrlp_user_command = 'ag %s -i --nocolor --nogroup --hidden
\ --ignore .git
\ --ignore .svn
\ --ignore .hg
\ --ignore .DS_Store
\ --ignore "**/*.pyc"
\ --ignore node_modules
\ --ignore .class
\ -g ""'
" Faster CtrlP matching
Plugin 'FelikZ/ctrlp-py-matcher'
let g:ctrlp_match_func = { 'match': 'pymatcher#PyMatch' }
" My colorscheme
" forked from: Plugin 'nielsmadan/harlequin'
Plugin 'wyantb/harlequin'
" Handy dealing with minified files from a random source
Plugin 'tony/vim-jsbeautify'
command! JsBeautify call JsBeautify()
" Let's make custom text objects
Plugin 'kana/vim-textobj-user'
" try: cic, dac, daC (aC includes whitespace)
Plugin 'glts/vim-textobj-comment'
" try: ci_, da_
Plugin 'lucapette/vim-textobj-underscore'
" i, a, | for function params
Plugin 'sgur/vim-textobj-parameter'
" i/ a/ | for the last search (remember dot formula: n. n. n.)
Plugin 'kana/vim-textobj-lastpat'
" ie ae | for whole buffer - hey, ya never know...
Plugin 'kana/vim-textobj-entire'
" highligts best letters for fFtT on the current line
Plugin 'unblevable/quick-scope'
" Language specific bits, otherwise uninteresting
Plugin 'groenewege/vim-less'
Plugin 'jnwhiteh/vim-golang'
Plugin 'Blackrush/vim-gocode'
" fzf, find stuff https://github.com/junegunn/fzf
Plugin 'junegunn/fzf', { 'dir': '~/.fzf', 'do': './install --all' }
Plugin 'junegunn/fzf.vim'
nnoremap <Leader>p :FZF<CR>
" async, for ferret, and then aliases for easier quickfix usage
Plugin 'tpope/vim-dispatch'
Plugin 'tpope/vim-unimpaired'
" :Ack, which uses ag
Plugin 'wincent/ferret'
" :Ags, which uses ag
Plugin 'gabesoft/vim-ags'
" Visual representation of undo graph
" Toggle w/ :UndotreeToggle
Plugin 'mbbill/undotree'
nnoremap <Leader>u :UndotreeToggle<CR>
" Helpful when JSON goes all wrong
Plugin 'elzr/vim-json'
" What it says on the tin. Handy enough
Plugin 'kien/rainbow_parentheses.vim'
" Displays +/-/etc in gutter
" Also, can use [c or ]c to jump between hunks
Plugin 'airblade/vim-gitgutter'
" Uses ctags to display landmarks
Plugin 'majutsushi/tagbar'
nnoremap <Leader>t :TagbarToggle<CR>
" And lets get path/tags working nicely w/ my gemfile and all
Plugin 'tpope/vim-bundler'
Plugin 'tpope/vim-rake'
Plugin 'tpope/vim-rails'
" Multi-cursor support???
Plugin 'mg979/vim-visual-multi'
Plugin 'wakatime/vim-wakatime'
" All of your Plugins must be added before the following line
call vundle#end() " required
filetype plugin indent on " required
let g:ags_agexe = 'rg'
let g:ags_agargs = {
\ '--column' : ['', ''],
\ '--line-number' : ['', ''],
\ '--context' : ['g:ags_agcontext', '-C'],
\ '--max-count' : ['g:ags_agmaxcount', ''],
\ '--heading' : ['',''],
\ '--smart-case' : ['','-S'],
\ '--color' : ['always',''],
\ '--colors' : [['match:fg:green', 'match:bg:black', 'match:style:nobold', 'path:fg:red', 'path:style:bold', 'line:fg:black', 'line:style:bold'] ,''],
\ }
" Undo tweaks, assuming undotree plugin
if has("persistent_undo")
set undodir=~/.config/vim-undodir/
set undofile
endif
" Setup async syntax checking with rubocop etc
call neomake#configure#automake('rw', 1000)
"let g:neomake_open_list = 2
" The basics
set nocompatible
syntax on
set number
" nvim has mouse behaviors enabled; I honestly don't use mouse for vim, would
" prefer the default gnome-terminal behavior (to e.g. let my copy/paste stuff
" from the statusline)
set mouse=
if has("nvim")
set inccommand=nosplit
endif
" Search stuffs
set hlsearch " highlight searches
set incsearch " do incremental searching
set showmatch " jump to matches when entering regexp
set ignorecase " ignore case when searching
set smartcase " no ignorecase if Uppercase char present
" Clear highlighted search when redrawing screen, without moving cursor
nnoremap <CR> :nohls<CR>
" Saving as sudo if I forget to start as sudo
cmap w!! w !sudo tee > /dev/null %
" Backup files in Vim have never helped me, only annoyed, disable them
set nobackup
set noswapfile
" With enough stuff going on and macros and etc, not redrawing while in
" progress really does help
set lazyredraw
set visualbell t_vb = " turn off error beep/flash
set novisualbell " turn off visual bell
set undolevels=200
" Highlights line#, underlines line @ cursor
set cursorline
" So you want spaces, not tabs?
function! SpaceTab()
set nopaste
set autoindent
set softtabstop=2
set expandtab
set ts=2
set sw=2
endfunction
command! SpaceTab call SpaceTab()
command! TwoSpace call SpaceTab()
" Four spaces, not tabs, not 2, 4!
function! FourSpace()
set nopaste
set autoindent
set softtabstop=4
set expandtab
set ts=4
set sw=4
endfunction
command! FourSpace call FourSpace()
" So you want tabs, not spaces?
function! RealTab()
set nopaste
set autoindent
set softtabstop=0
set noexpandtab
set ts=2
set sw=2
endfunction
command! RealTab call RealTab()
" syntax of these languages is fussy over tabs vs spaces
autocmd FileType make setlocal ts=2 sts=2 sw=2 noexpandtab
autocmd FileType go setlocal ts=2 sts=2 sw=2 noexpandtab
autocmd FileType yaml setlocal ts=2 sts=2 sw=2 expandtab
autocmd FileType java setlocal ts=2 sts=0 sw=2 noexpandtab
autocmd FileType groovy setlocal ts=2 sts=0 sw=2 noexpandtab
" Do it manually to start
set autoindent
set expandtab
set softtabstop=2
set ts=2
set sw=2
" Sometimes, you have some insane file that you need to open, and you really,
" really don't want syntax highlighting and stuff hosing your system
function! OptimizeSpeed()
setlocal syntax=
setlocal nohlsearch
setlocal t_Co=0
if g:qs_enable
QuickScopeToggle
endif
endfunction
function! OptimizeDefault()
syntax on
set hlsearch
set t_Co=256
if !g:qs_enable
QuickScopeToggle
endif
endfunction
command! OptimizeSpeed call OptimizeSpeed()
command! OptimizeDefault call OptimizeDefault()
command! FormatJSON %!python -m json.tool
" Make backspance handle everything it should
set backspace=indent,eol,start
" Show chars in place of normal tabs
set list listchars=tab:→\ ,trail:·
" Scroll padding
set scrolloff=5
" Vim 7.4 combined nu/rnu behavior wins over toggling
set number
set relativenumber
" And when we leave buffers, just keep the numbers absolute
au BufEnter * set rnu
au BufLeave * set nornu
set foldmethod=manual
" Navigation keys will wrap around lines
set whichwrap+=<,>,h,l,[,]
" Thank you Reddit
" http://www.reddit.com/r/vim/comments/1kgx0q/status_line_in_vim/cbp0uly
" See also :help statusline
set laststatus=2 " Always display a statusline
set statusline=%<\ " begins with whitespace
set statusline+=%t " filename
set statusline+=\ " whitespace
set statusline+=%m " modified
set statusline+=%r " read-only
set statusline+=%y " filetype
set statusline+=%w " preview
" Syntastic
" set statusline+=\ " whitespace
" set statusline+=%#warningmsg#
" set statusline+=%{SyntasticStatuslineFlag()}
set statusline+=%*
set statusline+=%= " split
set statusline+=Col:\ \%c " column number
set statusline+=\ " whitespace
set statusline+=Lin:\ \%l\/\%L " line number/total
set statusline+=\ " ends with whitespace
" Reload vimrc
map <Leader>v :source ~/.dotfiles/vimrc<CR>:filetype detect<CR>:exe ":echo '\nvimrc reloaded'"<CR>
" Somewhat destructive, but I don't use marks much, so I think I can afford making
" jumps to marks a little bit more keypress to get to
nnoremap ' :
vnoremap ' :
nnoremap <Leader>' '
vnoremap <Leader>' '
" Easier to reach, default H/L (move to top/bot of window) aren't helpful
noremap H ^
noremap L g_
" Setting some automatic Marks for different filetypes
" Thanks https://www.reddit.com/r/vim/comments/41wgqf
autocmd BufLeave *.css,*.less,*scss normal! mC
autocmd BufLeave *.html,*.hbr,*.hbs normal! mH
autocmd BufLeave *.js normal! mJ
autocmd BufLeave Gruntfile.js normal! mG
autocmd BufLeave *.xml normal! mX
autocmd BufLeave build.xml normal! mB
autocmd BufLeave *.properties normal! mP
"autocmd BufLeave vimrc,*.vim normal! mO
autocmd BufLeave *.java normal! mV
autocmd BufLeave *.txt,*.text normal! mE
autocmd BufLeave *.ts normal! mT
" Easier trigger for repeating previously-used macro
nnoremap <Leader>m @@
" Make yank behavior more consistent with D, C
map Y y$
" Undo all changes to one line...why? Try to map to something useful
nmap U <nop>
" I have never used Ex mode, and likely never will. Type in commands with no
" feedback? Try to map to something useful.
nmap Q <nop>
nmap gQ <nop>
" Colors!
" To experiment, try tabbing through - :color [Tab][Tab][Tab] (etc)
" color slate " what I used before 256 colors
set t_Co=256
set background=dark
color harlequin-wyantb
nmap <silent> <Leader>f :let @+ = expand("%")<cr>
vmap <silent> <Leader>f :<c-u>let @+ = expand("%")<cr>
" nmap <silent> <Leader>w :terminal bundle exec rspec expand("%")<cr>
" vmap <silent> <Leader>w :<c-u>terminal bundle exec rspec expand("%")<cr>
" Empty out trailing whitespace on save (nice w/ my snippets that may introduce
" spaces)
function! TrimTrailingWhitespace()
" Remembering cursor location courtesy of
" http://unix.stackexchange.com/a/75438
let l = line(".")
let c = col(".")
%s/\s\+$//e " clear out whitespace (possibly moving cursor)
call cursor(l, c) " and go back to original pos
endfunction
command! TrimTrailingWhitespace call TrimTrailingWhitespace()
autocmd FileType c,cpp,java,php,javascript,html,less autocmd BufWritePre <buffer> :call TrimTrailingWhitespace()
" Thanks, SO! http://stackoverflow.com/a/29819201
function! JscsFix()
"Save current cursor position"
let l:winview = winsaveview()
"Pipe the current buffer (%) through the jscs -x command"
% ! jscs -x
"Restore cursor position - this is needed as piping the file"
"through jscs jumps the cursor to the top"
call winrestview(l:winview)
endfunction
command! JscsFix :call JscsFix()
"Run the JscsFix command just before the buffer is written for *.js files"
"autocmd BufWritePre *.js JscsFix
" Experimental and various commands to remember
command! RemoveDups :g/^\(.*\)$\n\1$/d
" :sort u - sorts all the lines in the current file
" http://vim.wikia.com/wiki/Uniq_-_Removing_duplicate_lines
" --------------------------------------------------------------------
" From Salman: possibly experimental/stuff I don't actually want to use
" --------------------------------------------------------------------
" Returns a dictionary that can be passed to functions#RestoreMarks to restore the specified marks. For example, calling with "<>" can be used to save and
" restore the visual mode marks.
"
" Unused marks return [ 0, 0, 0, 0 ] which will delete them when next passed to functions#RestoreMarks, which seems correct. To ignore unused marks, pass in 1
" for the optional argument. Note that ignoring unused marks will not delete them when they are next restored.
function! SaveMarks( marks, ... )
let marks = substitute( a:marks, '\s\+', '', 'g' )
let ignoreUnusedMarks = exists( "a:1" ) ? a:1 : 0
let result = {}
let i = 0
while ( i < len( marks ) )
let mark = marks[ i ]
let markPos = getpos( "'" . mark )
if ( !ignoreUnusedMarks || markPos != [ 0, 0, 0, 0 ] )
let result[ mark ] = getpos( "'" . mark )
endif
let i += 1
endwhile
return result
endfunction
function! RestoreMarks( markDictionary )
for mark in keys( a:markDictionary )
let coordinates = a:markDictionary[ mark ]
call setpos( "'" . mark, coordinates )
endfor
endfunction
" e.g. gpi' replaces contents of quote with sys clipboard
function! PasteOverMotion( type )
let command = ":\<c-u>set paste\<cr>gv\"_c\<c-r>+\<esc>:set nopaste\<cr>"
if ( len( a:type ) == 1 )
silent execute "normal! " . command
else
if ( a:type == 'line' )
silent execute "normal! '[V']" . command
elseif ( a:type == 'block' )
" This is not likely as it can only happen from visual mode, for which the mapping isn't defined anyway
silent execute "normal! `[\<c-v>`]" . command
else
silent exe "normal! `[v`]" . command
endif
endif
endfunction
nmap <silent> gp :set opfunc=PasteOverMotion<cr>g@
vmap <silent> gp :<c-u>call PasteOverMotion( visualmode() )<CR" Escapes the input string so it's safe for use in a search.
" For example: echo MakeSafeForSearch( 'a b[]' ) results in 'a\_s\+b\[\]' (without the quotes).
function! MakeSafeForSearch( input )
return substitute( escape( a:input, '$*^[]~\/.' ), '\_s\+', '\\_s\\+', 'g' )
endfunction
" Sets the search register and adds the value that was set to the search command's history.
function! SetSearchRegister( value )
let @/ = a:value
call histadd( '/', a:value )
call HighlightSearchResults()
endfunction
" This is a function that will turn on the highlighting of search results IF 'hlsearch' is set but temporarily disabled through a call to :nohlsearch.
" May 24, 2011: it doesn't actually work... Can't really be done from a function, apparently, though a command can.
" See |autocmd-searchpat| I think? :nohls doesn't play well with this, but
" if you just have a key that toggles like set hls!, it works out.
function! HighlightSearchResults()
if ( &hlsearch )
set hlsearch
endif
endfunction
" Defines an operator (<Leader>/) that will search for the specified text.
function! SetSearch( type )
let saveZ = @z
let savedMarks = SaveMarks('<>')
if a:type == 'line'
'[,']yank z
elseif a:type == 'block'
" This is not likely as it can only happen from visual mode, for which the mapping isn't defined anyway
execute "normal! `[\<c-v>`]\"zy"
else
normal! `[v`]"zy
endif
call SetSearchRegister( MakeSafeForSearch( @z ) )
let @z = saveZ
call RestoreMarks(savedMarks)
endfunction
nnoremap <leader>/ :set opfunc=SetSearch<cr>g@
" Sometimes, you want to copy/paste code for people, that's indented. Use
" this - <Leader>y / <Leader>Y - instead of "+y, to include in the clipboard the text with
" common whitespace stripped (bonus: less characters to type)
function! GetLinesWithoutIndent( start, end )
let lowIndent = indent( a:start )
for i in range( a:start + 1, a:end )
" Ignore completely blank lines.
if ( getline( i ) =~ '^\s*$' )
continue
endif
if ( indent( i ) < lowIndent )
let lowIndent = indent( i )
endif
endfor
let result = []
for i in range( a:start, a:end )
call add( result, substitute( getline( i ), '^ \{' . lowIndent . '}', '', '' ) )
endfor
return result
endfunction
function! CopyWithoutIndent( type )
if ( len( a:type ) == 1 )
let lineStart = line( "'<" )
let lineEnd = line( "'>" )
else
let lineStart = line( "'[" )
let lineEnd = line( "']" )
endif
let result = GetLinesWithoutIndent( lineStart, lineEnd )
let @+ = join( result, "\<NL>" )
endfunction
nmap <silent> <Leader>y :set opfunc=CopyWithoutIndent<cr>g@
vmap <silent> <Leader>y :<c-u>call CopyWithoutIndent( visualmode() )<CR>
function! CopyFileLinesWithoutIndent( type )
if ( len( a:type ) == 1 )
let lineStart = line( "'<" )
let lineEnd = line( "'>" )
else
let lineStart = line( "'[" )
let lineEnd = line( "']" )
endif
let info = expand( "%:p" )
if ( lineEnd - lineStart == 0 )
let info .= ', line ' . lineStart . ':'
else
let info .= ', lines ' . lineStart . '-' . lineEnd . ':'
endif
let lines = GetLinesWithoutIndent( lineStart, lineEnd )
let @+ = join( [ info, "" ] + lines, "\<NL>" )
endfunction
nmap <silent> <Leader>Y :set opfunc=CopyFileLinesWithoutIndent<cr>g@
vmap <silent> <Leader>Y :<c-u>call CopyFileLinesWithoutIndent( visualmode() )<CR>
function! StripHome(inp)
return substitute(a:inp, '\/Users\/brianwyant\/', '~/', '')
endfunction
function! CopyFileLinesForSnippet( type )
if ( len( a:type ) == 1 )
let lineStart = line( "'<" )
let lineEnd = line( "'>" )
else
let lineStart = line( "'[" )
let lineEnd = line( "']" )
endif
let info = StripHome( expand( "%:p" ) )
if ( lineEnd - lineStart == 0 )
let info .= ', line ' . lineStart . ':'
else
let info .= ', lines ' . lineStart . '-' . lineEnd . ':'
endif
let lines = GetLinesWithoutIndent( lineStart, lineEnd )
let joinedLines = '```' . join( lines, "\<NL>" ) . '```'
let @+ = join( [ info, "", joinedLines ], "\<NL>" )
endfunction
nmap <silent> <Leader>s :set opfunc=CopyFileLinesForSnippet<cr>g@
vmap <silent> <Leader>s :<c-u>call CopyFileLinesForSnippet( visualmode() )<CR>
" From Salman: commands for converting text to have spaces, ALL_CAPS,
" dash-joins, etc
function! CamelizeText( text )
let result = a:text
" Make sure it isn't already camel-cased.
if ( match( result, '[_\- ]' ) >= 0 )
let result = substitute( tolower( result ), '[_\- ]\([a-z]\)', '\u\1', 'g' )
endif
return result
endfunction
" Converts 'anInterestingPhrase' or 'an interesting phrase' to 'AN_INTERESTING_PHRASE'.
function! MakeConstant( text )
return toupper( substitute( substitute( a:text, '\C\([^A-Z]\)\([A-Z]\)', '\1_\2', 'g' ), '[[:space:]_\-]\+', '_', 'g' ) )
endfunction
function! ManipulateMotion( type, searchString, replacementString )
if a:type == 'line'
let command = "S/" . a:searchString . "/" . a:replacementString . "/g"
silent execute "'[,']" . command
return
elseif a:type == 'block'
" This is not likely as it can only happen from visual mode, for which the mapping isn't defined anyway
silent exe "normal! `[\<C-V>`]"
else
silent exe "normal! `[v`]"
endif
execute "normal! \"xc\<c-r>=substitute(@x,'" . a:searchString . "','" . a:replacementString . "','g')\<cr>\<esc>"
endfunction
" From
" the quick red fox jumped over the lazy brown dogs
" To
" theQuickRedFoxJumpedOverTheLazyBrownDogs
function! CamelizeMotion( type )
call ManipulateMotion( a:type, '.*', '\=CamelizeText(submatch(0))' )
endfunction
nmap <silent> <leader>xa :set opfunc=CamelizeMotion<cr>g@
" From
" the quick red fox jumped over the lazy brown dogs
" To
" TheQuickRedFoxJumpedOverTheLazyBrownDogs
function! CamelizeWithCapitalMotion( type )
call ManipulateMotion( a:type, '.*', '\=substitute(CamelizeText(submatch(0)), ".", "\\U\\0", "")' )
endfunction
nmap <silent> <leader>xf :set opfunc=CamelizeWithCapitalMotion<cr>g@
" From
" the quick red fox jumped over the lazy brown dogs
" To
" THE_QUICK_RED_FOX_JUMPED_OVER_THE_LAZY_BROWN_DOGS
function! ConstantizeMotion( type )
call ManipulateMotion( a:type, '.*', '\=MakeConstant(submatch(0))' )
endfunction
nmap <silent> <leader>xo :set opfunc=ConstantizeMotion<cr>g@
" From
" the quick red fox jumped over the lazy brown dogs
" To
" the_quick_red_fox_jumped_over_the_lazy_brown_dogs
function! SnakeCaseMotion( type )
call ManipulateMotion( a:type, '.*', '\=tolower(MakeConstant(submatch(0)))' )
endfunction
nmap <silent> <leader>xu :set opfunc=SnakeCaseMotion<cr>g@
" From
" TheQuickRedFoxJumpedOverTheLazyBrownDogs
" To
" the quick red fox jumped over the lazy brown dogs
function! WordifyMotion( type )
call ManipulateMotion( a:type, '.*', '\=tolower(substitute(MakeConstant(submatch(0)), "_", " ", "g"))' )
endfunction
nmap <silent> <leader>xw :set opfunc=WordifyMotion<cr>g@