Snippets

Created by Chris Chernesky last modified
  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
" Vim: curl -sfLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
" NeoVim: curl -sfLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
" call plug#begin('~/.vim/plugged')

if empty(glob('~/.vim/autoload/plug.vim'))
  silent execute "!curl -fLo ~/.vim/autoload/plug.vim --create-dirs https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim"
  autocmd VimEnter * PlugInstall | source $MYVIMRC
endif

call plug#begin()
     " Plug 'mikewest/vimroom'
    " Plug 'ajh17/VimCompletesMe'
    " Plug 'altercation/vim-colors-solarized'
    Plug 'c-brenn/phoenix.vim'
    " Plug 'chase/vim-ansible-yaml'
    " Plug 'chriskempson/base16-vim'
    " Plug 'danchoi/ri.vim'
    " Plug 'derekwyatt/vim-scala'
    " Plug 'dkprice/vim-easygrep'
    Plug 'elixir-lang/vim-elixir'
    " Plug 'elzr/vim-json'
    " Plug 'godlygeek/tabular'
    " Plug 'idanarye/vim-merginal'
    " Plug 'imeos/vim-colors-solstice'
    " Plug 'kana/vim-textobj-user'
    " Plug 'kien/rainbow_parentheses.vim'
    " Plug 'klen/python-mode', { 'for': 'python' }
    " Plug 'ludovicchabant/vim-lawrencium'
    " Plug 'majutsushi/tagbar'
    " Plug 'mattn/webapi-vim'
    " Plug 'mhinz/vim-signify'
    " Plug 'nelstrom/vim-textobj-rubyblock'
    " Plug 'palmer-eldritch/ri.vim'
    " Plug 'pangloss/vim-javascript'
    " Plug 'scrooloose/syntastic'
    " Plug 'thinca/vim-visualstar'
    " Plug 'tpope/vim-projectionist'
    " Plug 'trusktr/seti.vim'
    " Plug 'vim-scripts/Colour-Sampler-Pack'
    " Plug 'vim-scripts/CycleColor'
    " Plug 'vim-scripts/L9'
    " Plug 'vim-scripts/ScrollColors'
    " Plug 'vim-scripts/ZoomWin'
    " Plug 'vim-scripts/auto_mkdir'
    " Plug 'vim-scripts/groovy.vim'
    " Plug 'vim-scripts/vcscommand.vim'
    "Plug 'godlygeek/csapprox'
    Plug 'ConradIrwin/vim-bracketed-paste'
    Plug 'bogado/file-line'
    " Plug 'chrisbra/Recover.vim'
    Plug 'ctrlpvim/ctrlp.vim'
    Plug 'd11wtq/ctrlp_bdelete.vim'
    Plug 'ervandew/supertab'
    Plug 'flazz/vim-colorschemes'
    Plug 'jiangmiao/auto-pairs'
    Plug 'junegunn/goyo.vim'
    Plug 'kchmck/vim-coffee-script'
    Plug 'michaeljsmith/vim-indent-object'
    Plug 'ngmy/vim-rubocop'
    Plug 'rking/ag.vim'
    Plug 'rondale-sc/vim-spacejam'
    Plug 'scrooloose/nerdtree' ", { 'on': 'NERDTreeToggle' }
    Plug 'sickill/vim-pasta'
    Plug 'slim-template/vim-slim'
    Plug 'tacahiroy/ctrlp-funky'
    Plug 'thaerkh/vim-workspace'
    Plug 'tmhedberg/matchit'
    Plug 'tomtom/tcomment_vim'
    Plug 'tpope/vim-abolish'
    Plug 'tpope/vim-cucumber'
    Plug 'tpope/vim-endwise'
    Plug 'tpope/vim-fugitive'
    Plug 'tpope/vim-git'
    Plug 'tpope/vim-haml'
    Plug 'tpope/vim-markdown'
    Plug 'tpope/vim-rails'
    Plug 'tpope/vim-repeat'
    Plug 'tpope/vim-surround'
    Plug 'tpope/vim-unimpaired'
    Plug 'tpope/vim-vinegar'
    Plug 'vim-airline/vim-airline'
    Plug 'vim-airline/vim-airline-themes'
    " Plug 'vim-ruby/vim-ruby'
    Plug 'vim-scripts/ruby-matchit'
    Plug 'w0rp/ale'
    Plug 'xolox/vim-easytags'
    Plug 'xolox/vim-misc'
    Plug 'zxiest/vim-ruby'
call plug#end()
silent! call ctrlp_bdelete#init()

" ALE
let g:ale_sign_column_always = 1

" Workspace
nnoremap <leader>s :ToggleWorkspace<CR>
set nocp
filetype plugin on
" bring in the bundles for mac and windows
let mapleader = ','
nmap <Leader>b :CtrlPBuffer<CR>
autocmd Filetype gitcommit setlocal spell textwidth=72

if has("vim")
  set term=screen-256color
endif

set t_Co=256
set background=dark
silent! colorscheme lucius

let g:solarized_termcolors=&t_Co
let g:solarized_termtrans=1

" Remove trailing whitespace
autocmd BufWritePre * :%s/\s\+$//e

set pastetoggle=<leader>p

" if !empty($MY_RUBY_HOME)
"    let g:ruby_path = join(split(glob($MY_RUBY_HOME.'/lib/ruby/*.*')."\n".glob($MY_RUBY_HOME.'/lib/rubysite_ruby/*'),"\n"),',')
" endif
"
" ruby path if you are using rbenv
let g:ruby_path = system('echo $HOME/.rbenv/shims')

let g:loaded_netrw       = 1
let g:loaded_netrwPlugin = 1

autocmd WinEnter * call s:CloseIfOnlyNerdTreeLeft()

" Close all open buffers on entering a window if the only
" buffer that's left is the NERDTree buffer
function! s:CloseIfOnlyNerdTreeLeft()
  if exists("t:NERDTreeBufName")
    if bufwinnr(t:NERDTreeBufName) != -1
      if winnr("$") == 1
        q
      endif
    endif
  endif
endfunction

" The Silver Searcher Config
nmap g/ :Ag!<space>
nmap g* :Ag! -w <C-R><C-W><space>
nmap ga :AgAdd!<space>
nmap gn :cnext<CR>
nmap gp :cprev<CR>
nmap gq :ccl<CR>
nmap gl :cwindow<CR>

nmap nf :NERDTreeFind<CR>
nmap gt :NERDTreeToggle<CR>
nmap g :NERDTree \| NERDTreeToggle \| NERDTreeFind<CR>

" Tagbar Configuration
let g:tagbar_autofocus = 1
map <Leader>rt :!ctags --extra=+f -R *<CR><CR>
map <Leader>. :TagbarToggle<CR>

" Markdown Syntax Highlighting
augroup mkd
  autocmd BufNewFile,BufRead *.mkd      set ai formatoptions=tcroqn2 comments=n:> filetype=markdown
  autocmd BufNewFile,BufRead *.md       set ai formatoptions=tcroqn2 comments=n:> filetype=markdown
  autocmd BufNewFile,BufRead *.markdown set ai formatoptions=tcroqn2 comments=n:> filetype=markdown
augroup END

au! BufRead,BufNewFile *.json set filetype=json

" Markdown Preview
map <buffer> <Leader>mp :Mm<CR>

" NERDTree for project drawer
let NERDTreeHijackNetrw = 0


" Tabular
function! CustomTabularPatterns()
  if exists('g:tabular_loaded')
    AddTabularPattern! symbols         / :/l0
    AddTabularPattern! hash            /^[^>]*\zs=>/
    AddTabularPattern! chunks          / \S\+/l0
    AddTabularPattern! assignment      / = /l0
    AddTabularPattern! comma           /^[^,]*,/l1
    AddTabularPattern! colon           /:\zs /l0
    AddTabularPattern! options_hashes  /:\w\+ =>/
  endif
endfunction

autocmd VimEnter * call CustomTabularPatterns()

" shortcut to align text with Tabular
map <Leader>a :Tabularize<space>

" Zoomwin
map <Leader>z :ZoomWin<CR>

" Unimpaired
" Bubble single lines
nmap <C-Up> [e
nmap <C-Down> ]e

" Bubble multiple lines
vmap <C-Up> [egv
vmap <C-Down> ]egv

" Syntastic
" let g:syntastic_auto_loc_list = 2
" let g:syntastic_check_on_open = 1
" let g:syntastic_check_on_wq = 0
" let g:syntastic_enable_balloons = 0
" let g:syntastic_error_symbol = '✗'
" let g:syntastic_ignore_files = ['\.min\.js$', '\.min\.css$']
" let g:syntastic_loc_list_height = 5
" let g:syntastic_warning_symbol = '✗'
" let g:syntastic_style_error_symbol = '∆'
" let g:syntastic_style_warning_symbol = '∆'
" let g:syntastic_enable_signs=1
" let g:syntastic_ruby_checkers          = ['rubocop', 'mri']
" let g:syntastic_always_populate_loc_list = 1

" let g:syntastic_mode_map = { 'mode': 'active',
"                            \ 'active_filetypes': [],
"                            \ 'passive_filetypes': ['haml','scss','sass'] }
" let g:syntastic_quiet_messages = {'level': 'warnings'}
" syntastic is too slow for haml and sass
" Vim Rails
map <Leader>oc :Rcontroller<Space>
map <Leader>ov :Rview<Space>
map <Leader>om :Rmodel<Space>
map <Leader>oh :Rhelper<Space>
map <Leader>oj :Rjavascript<Space>
map <Leader>os :Rstylesheet<Space>
map <Leader>oi :Rintegration<Space>

" vim-surround
" # to surround with ruby string interpolation
let g:surround_35 = "#{\r}"
" - to surround with no-output erb tag
let g:surround_45 = "<% \r %>"
" = to surround with output erb tag
let g:surround_61 = "<%= \r %>"

" ctrl-p
nmap <Leader>t :CtrlP<CR>
nmap <Leader>m :CtrlPBufTag<CR>
nmap <Leader>mm :CtrlPBufTagAll<CR>
nmap <Leader>y :CtrlPBufTagAll<CR>
set wildignore+=*.class

" ctrlp-funky
let g:ctrlp_extensions = ['funky']
nmap <Leader>f :CtrlPFunky<CR>

" set clipboard=unnamed
set tags=./tags,tags,../tags

set mouse=
let g:airline_powerline_fonts = 1
" let g:airline_theme             = 'powerlineish'
let g:airline_theme             = 'solarized'
let g:airline#extensions#branch#enabled = 1
let g:airline#extensions#syntastic#enabled = 1
"let g:airline_detect_modified=1
set laststatus=2

" Trailing whitespace
function! TrimWhiteSpace()
    %s/\s\+$//e
endfunction

nnoremap <silent> <Leader>rts :call TrimWhiteSpace()<CR>
filetype plugin on

" JSON
set conceallevel=0

" PyMode
let g:pymode_breakpoint = 0
let g:pymode_folding = 0

" Merginal
nmap <Leader>m :Merginal<CR>

fun! Html2haml()
  %!html2haml -r
  save %:r.haml
  setf haml
  !git rm %:r.erb
endfun

let html_use_css = 1 " Use stylesheet instead of inline style
let html_number_lines = 0 " don't show line numbers
let html_no_pre = 1 " don't wrap lines in <pre>

function! OpenHtml(line1, line2)
  exec a:line1.','.a:line2.'TOhtml'
  %s/monospace/Monaco/g
  %s/bold/normal/g
  save! /tmp/__OpenHtml.html
  !open %
  q
endfunction
command! -range=% OpenHtml :call OpenHtml(<line1>,<line2>)

" Tidy an HTML/XML file inline
command! Tidy :%! tidy -indent -quiet -wrap 100

" Align all colon-separated content (CSS rules) in a file
command! AlignColons execute 'g/:/Tabularize colon' | noh

" via: http://rails-bestpractices.com/posts/60-remove-trailing-whitespace
" Strip trailing whitespace
function! <SID>StripTrailingWhitespaces()
    " Preparation: save last search, and cursor position.
    let _s=@/
    let l = line(".")
    let c = col(".")
    " Do the business:
    %s/\s\+$//e
    " Clean up: restore previous search history, and cursor position
    let @/=_s
    call cursor(l, c)
endfunction
command! StripTrailingWhitespaces call <SID>StripTrailingWhitespaces()

" required for several plugins
  set nocompatible

" enable syntax highlighting
  syntax on

" default color scheme
  set background=dark

" don't wrap long lines
  set nowrap

" show commands as we type them
  set showcmd

" highlight matching brackets
  set showmatch

" scroll the window when we get near the edge
  set scrolloff=4 sidescrolloff=10

" use 2 spaces for tabs
  set expandtab tabstop=2 softtabstop=2 shiftwidth=2

" enable line numbers, and don't make them any wider than necessary
  set number numberwidth=2

" show the first match as search strings are typed
  set incsearch

" highlight the search matches
  set hlsearch

" searching is case insensitive when all lowercase
  set ignorecase smartcase

" assume the /g flag on substitutions to replace all matches in a line
"  set gdefault

" set temporary directory (don't litter local dir with swp/tmp files)
  set directory=/tmp/

" pick up external file modifications
  set autoread

" don't abandon buffers when unloading
  set hidden

" match indentation of previous line
  set autoindent

" perform autoindenting based on filetype plugin
  filetype plugin indent on

" don't blink the cursor
  set guicursor=a:blinkon0

" show current line info (current/total)
  set ruler rulerformat=%=%l/%L

" show status line
  set laststatus=2

" augment status line
  function! ETry(function, ...)
    if exists('*'.a:function)
      return call(a:function, a:000)
    else
      return ''
    endif
  endfunction
  set statusline=[%n]\ %<%.99f\ %h%w%m%r%{ETry('CapsLockStatusline')}%y%{ETry('rails#statusline')}%{ETry('fugitive#statusline')}%#ErrorMsg#%*%=%-16(\ %l,%c-%v\ %)%P

" When lines are cropped at the screen bottom, show as much as possible
  set display=lastline

" flip the default split directions to sane ones
  set splitright
  set splitbelow

" don't beep for errors
  set visualbell

" make backspace work in insert mode
  set backspace=indent,eol,start

" highlight trailing whitespace
  set listchars=tab:>\ ,trail:-,extends:>,precedes:<,nbsp:+
  set list

" use tab-complete to see a list of possiblities when entering commands
  set wildmode=list:longest,full

" allow lots of tabs
  set tabpagemax=20

" remember last position in file
  au BufReadPost * if line("'\"") > 0 && line("'\"") <= line("$") | exe "normal g'\"" | endif

" Thorfile, Rakefile, Vagrantfile, and Gemfile are Ruby
  au BufRead,BufNewFile {Gemfile,Rakefile,Vagrantfile,Thorfile,config.ru} set ft=ruby


" easy wrap toggling
  nmap <Leader>w :set wrap!<cr>
  nmap <Leader>W :set nowrap<cr>

" go to the alternate file (previous buffer) with g-enter
"  nmap g

" shortcuts for frequenly used files
  nmap gs :e db/schema.rb<cr>
  nmap gr :e config/routes.rb<cr>
  nmap gm :e Gemfile<cr>

" shortcut for =>
  imap <C-l> <Space>=><Space>

  abbrev hte the

" clean up trailing whitespace
  map <Leader>c :StripTrailingWhitespaces<cr>

" compress excess whitespace on current line
  map <Leader>e :s/\v(\S+)\s+/\1 /<cr>:nohl<cr>

" delete all buffers
  map <Leader>d :bufdo bd<cr>

" map spacebar to clear search highlight
  nnoremap <Leader><space> :noh<cr>

" buffer resizing mappings (shift + arrow key)
  nnoremap <S-Up> <c-w>+
  nnoremap <S-Down> <c-w>-
  nnoremap <S-Left> <c-w><
  nnoremap <S-Right> <c-w>>

" reindent the entire file
  map <Leader>I gg=G``<cr>

" insert the path of currently edited file into a command
" Command mode: Ctrl-P
  cmap <C-S-P> <C-R>=expand("%:p:h") . "/" <cr>


set nolist
let g:NERDTreeMinimalUI=1
" let g:NERDTreeDirArrows=0
" let g:NERDTreeWinPos = "right"
" let g:NERDChristmasTree=1
let g:fuf_file_exclude = '\v\~$|\.o$|\.exe$|\.bak$|\.swp|\.svn|\.class$'
set wrap
set linebreak
set nolist  " list disables linebreak
let g:ctrlp_max_files=0
let g:ctrlp_arg_map = 1
let g:ctrlp_match_window = 'bottom,order:btt,min:1,max:30,results:100'
autocmd QuickFixCmdPost *grep* cwindow
nmap \ ,
let g:syntastic_javascript_checkers = ['jsl']

command! -nargs=0 -bar Qargs execute 'args' QuickfixFilenames()
" populate the argument list with each of the files named in the quickfix list
function! QuickfixFilenames()
  let buffer_numbers = {}
  for quickfix_item in getqflist()
    let buffer_numbers[quickfix_item['bufnr']] = bufname(quickfix_item['bufnr'])
  endfor
  return join(map(values(buffer_numbers), 'fnameescape(v:val)'))
endfunction
nmap <Leader>gg :Gstatus<CR>
nmap <Leader>gw :Gwrite<CR>
nmap <Leader>gb :Gblame<CR>
nmap <Leader>gs :w<CR>:Git add %<CR>
" imap jk <Esc>
" imap jj <Esc>

" noremap <Up> <NOP>
" noremap <Down> <NOP>
" noremap <Left> <NOP>
" noremap <Right> <NOP>
"
" let g:airline_powerline_fonts = 1

let loaded_matchparen = 0

function! TwiddleCase(str)
  if a:str ==# toupper(a:str)
    let result = tolower(a:str)
  elseif a:str ==# tolower(a:str)
    let result = substitute(a:str,'\(\<\w\+\>\)', '\u\1', 'g')
  else
    let result = toupper(a:str)
  endif
  return result
endfunction
vnoremap ~ y:call setreg('', TwiddleCase(@"), getregtype(''))<CR>gv""Pgv

autocmd BufWritePost * if &diff == 1 | diffupdate | endif
let g:vim_json_syntax_conceal=0
set tags=./tags;
let g:easytags_dynamic_files = 1
let g:easytags_auto_highlight = 0
let g:easytags_async = 1
nmap <leader>rh :%s/\v:(\w+) \=\>/\1:/g<cr>

if executable('ag')
  " Use ag over grep
  set grepprg=ag\ --nogroup\ --nocolor

  " Use ag in CtrlP for listing files. Lightning fast and respects .gitignore
  let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'

  " ag is fast enough that CtrlP doesn't need to cache
  let g:ctrlp_use_caching = 0
endif

" Supertab
inoremap <expr> <Space> pumvisible() ? "\<C-y>" : " "

" diff coloscheme changes
" if &diff
"   colorscheme jellybean
" endif
" au FilterWritePre * if &diff | colorscheme jellybean | endif

" Ruby hash syntax conversion
nnoremap <Leader>hc :%s/:\([^ ]*\)\(\s*\)=>/\1:/g<return>
autocmd FileType ruby let b:vcm_tab_complete = "tags"
autocmd Syntax * syn match ExtraWhitespace /\s\+$\| \+\ze\\t/
set ttyfast
au FileWritePost * :redraw!
au TermResponse * :redraw!
au TextChanged * :redraw!
au QuickFixCmdPre * :redraw!
au QuickFixCmdPost * :redraw!

nmap <Leader>di a[disabled='disabled']<ESC>

function! UnMinify()
    %s/{\ze[^\r\n]/{\r/g
    %s/){/) {/g
    %s/};\?\ze[^\r\n]/\0\r/g
    %s/;\ze[^\r\n]/;\r/g
    %s/[^\s]\zs[=&|]\+\ze[^\s]/ \0 /g
    normal ggVG=
endfunction

if has("gui_macvim")
  set clipboard=unnamed
endif

let g:ale_statusline_format = ['⨉ %d', '⚠ %d', '⬥ ok']

Comments (0)

HTTPS SSH

You can clone a snippet to your computer for local editing. Learn more.