Skip to content

Instantly share code, notes, and snippets.

@fredv
Created November 26, 2015 17:17
Show Gist options
  • Save fredv/3ba3cf5275c0cd35d9de to your computer and use it in GitHub Desktop.
Save fredv/3ba3cf5275c0cd35d9de to your computer and use it in GitHub Desktop.
.vimrc
filetype plugin off
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
Plugin 'gmarik/Vundle.vim'
Plugin 'fatih/vim-go'
Plugin 'tpope/vim-fugitive'
Plugin 'rking/ag.vim'
Plugin 'scrooloose/syntastic'
Plugin 'kien/ctrlp.vim'
Plugin 'Rip-Rip/clang_complete'
Plugin 'b4winckler/vim-objc'
Plugin 'eraserhd/vim-ios'
Plugin 'LanguageTool'
Plugin 'SirVer/ultisnips'
Plugin 'honza/vim-snippets'
Plugin 'tpope/vim-abolish'
Plugin 'benmills/vimux'
Plugin 'tpope/vim-markdown'
Plugin 'tpope/vim-surround'
Plugin 'toyamarinyon/vim-swift'
Plugin 'honza/dockerfile.vim'
Plugin 'majutsushi/tagbar'
Plugin 'scrooloose/nerdtree'
Plugin 'slim-template/vim-slim'
Plugin 'tpope/vim-rake'
Plugin 'elzr/vim-json'
Plugin 'jamessan/vim-gnupg'
Bundle 'mileszs/ack.vim'
Plugin 'bling/vim-airline'
Plugin 'morhetz/gruvbox'
"Plugin 'Valloric/YouCompleteMe'
Plugin 'ervandew/supertab'
Plugin 'kchmck/vim-coffee-script'
Plugin 'thoughtbot/vim-rspec'
Plugin 'sjl/tslime.vim'
call vundle#end() " required
filetype plugin indent on " required
colorscheme gruvbox
set background=dark
" let g:vim_json_syntax_conceal = 0
let g:UltiSnipsExpandTrigger="<tab>"
let g:UltiSnipsJumpForwardTrigger="<tab>"
let g:UltiSnipsJumpBackwardTrigger="<s-tab>"
let g:lastspec = 0
let g:lastspecline = 0
let s:code = "print ($: + begin; require %q{rubygems}; Gem::Specification.map(&:lib_dirs_glob).sort.uniq; rescue LoadError; []; end).join(%q{,})"
hi cursorline cterm=NONE ctermbg=grey ctermfg=black guibg=darkred guifg=white
hi cursorcolumn cterm=NONE ctermbg=grey ctermfg=black guibg=darkred guifg=white
set t_Co=256
set relativenumber
set nolinebreak
set showmatch
set showcmd
set ruler
set incsearch
set backspace=indent,eol,start
set wildmenu
set wildignore+=tmp/*,log/*,*.o,*.obj,.git,*.txt,*.sql,*.gz
set nocompatible
set nofoldenable
set dir=~/.vim.swp
let g:ctrlp_custom_ignore = {
\ 'dir': '\v[\/]\.(git|hg|svn)|[\/](Godeps\/_workspace|static|public|app\/assets)$',
\ 'file': '\v\.(exe|so|dll|js|log|sql|gz|txt)$',
\ 'link': 'some_bad_symbolic_links',
\ }
let g:ctrlp_max_files = 25000
autocmd BufNewFile,BufRead *.ego set ft=html
autocmd BufNewFile,BufRead *.go set ft=go
autocmd BufNewFile,BufRead *.json set ft=json nolist tabstop=2 shiftwidth=2 expandtab autoindent
autocmd BufNewFile,BufRead *.swift set ft=swift
autocmd BufNewFile,BufRead *.md set ft=markdown noexpandtab
function! ResetColorline()
exec(":hi CursorLine cterm=NONE ctermbg=darkgrey ctermfg=black guibg=darkred guifg=white")
exec(":colorscheme gruvbox")
endfunction
autocmd BufWritePre * call ResetColorline()
autocmd FileType go nnoremap <buffer> gd :GoDef<cr>
autocmd FileType go nnoremap <buffer> K :GoDoc<cr>
autocmd FileType go nmap ,i <Plug>(go-info)
autocmd FileType go set makeprg=make
autocmd FileType go nmap ,e <Plug>(go-rename)
autocmd FileType go set tabstop=4 shiftwidth=4
autocmd FileType go map <C-]> gd
autocmd FileType html set expandtab
autocmd FileType ruby set expandtab
autocmd FileType ruby set shiftwidth=2
autocmd FileType ruby set tabstop=2
autocmd FileType make set noexpandtab nolist shiftwidth=4 tabstop=4 softtabstop=4
" expand to current directory
cnoremap %% <C-R>=expand('%:h').'/'<CR>
map tt :TagbarToggle<CR>
" set completeopt=longest,menuone
" set hidden " remember more commands and search history
" if has("autocmd")
" :filetype indent plugin on
"endif
filetype plugin on
set ignorecase
set smartcase
set hidden
set laststatus=2
set tw=0
syntax on
set shell=bash
set history=10000
set expandtab
set tabstop=2
set shiftwidth=2
set softtabstop=2
set smartindent
set grepprg=ack
let g:ackprg= 'ag --nogroup --nocolor --column'
set vb
set directory=/tmp
set backupdir=/tmp
set gfn=Monaco:h16
map <Left> <Nop>
map <Right> <Nop>
map <Up> <Nop>
map <Down> <Nop>
scriptencoding=utf-8
set encoding=utf-8
let mapleader=","
command! -nargs=* Make make <args> | cwindow 3
autocmd QuickFixCmdPost [^l]* nested cwindow
autocmd QuickFixCmdPost l* nested lwindow
let g:godef_split=0
let g:go_fmt_command='goimports'
map <leader>v :VimuxPromptCommand<CR>
map <leader><cr> :VimuxRunLastCommand<CR>
map <leader>/ :VimuxRunLastCommand<CR>
setlocal spell spelllang=en_us
map <leader>s :setlocal spell!<CR>
command! -range AddJsonTags <line1>,<line2>normal ^vEyA `json:""crsA,omitempty"`^j
command! -range AddXmlTags <line1>,<line2>normal ^vEyA `xml:""guawA,attr"`^j
command! -range JsonToStruct <line1>,<line2>normal ^wvi"yI" string `json:f:s` //^crmj^
command! -range StripComments <line1>,<line2>normal ^/\/\/^j
command! -range StructToMap <line1>,<line2>normal vEyI"": m.Ea, CI"lcrsj^
command! -range XmlToStruct <line1>,<line2>normal ^xvt>yI" string `xml:"f>s"` //^crmj
command! -range InlineErr <line1>,<line2>normal ^wi:Iif A; err != nil {jdd
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" RENAME CURRENT FILE
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! RenameFile()
let old_name = expand('%')
let new_name = input('New file name: ', expand('%'), 'file')
if new_name != '' && new_name != old_name
exec ':saveas ' . new_name
exec ':silent !rm ' . old_name
redraw!
endif
endfunction
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" SWITCH BETWEEN TEST AND PRODUCTION CODE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! OpenTestAlternate()
let new_file = AlternateForCurrentFile()
exec ':e ' . new_file
endfunction
function! Expectify()
exec ':%s/\ \ \([^\ ].\+\)\.should\ ==\ \(.\+\)/\ \ expect(\1).to eql(\2)/'
endfunction
function! AlternateForCurrentFile()
let current_file = expand("%")
let new_file = current_file
let in_spec = match(current_file, '^spec/') != -1
let in_app = match(current_file, '\<controllers\>') != -1 || match(current_file, '\<models\>') != -1 || match(current_file, '\<views\>') != -1 || match(current_file, '\<jobs\>') != -1 || match(current_file, '\<observers\>') != -1 || match(current_file, '\<serializers\>') != -1 || match(current_file, '\<services\>') != -1 || match(current_file, '\<serializers\>') != -1
if !in_spec
if in_app
let new_file = substitute(new_file, '^app/', '', '')
end
let new_file = substitute(new_file, '\.rb$', '_spec.rb', '')
let new_file = 'spec/' . new_file
else
let new_file = substitute(new_file, '_spec\.rb$', '.rb', '')
let new_file = substitute(new_file, '^spec/', '', '')
if in_app
let new_file = 'app/' . new_file
end
endif
return new_file
endfunction
command! -nargs=* Make make <args> | cwindow 3
autocmd QuickFixCmdPost [^l]* nested cwindow
autocmd QuickFixCmdPost l* nested lwindow
map <c-l> <space>=><space>
"ruby
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
autocmd FileType ruby,eruby let g:rubycomplete_buffer_loading = 1
autocmd FileType ruby,eruby let g:rubycomplete_rails = 1
autocmd FileType ruby,eruby let g:rubycomplete_classes_in_global = 1
""improve autocomplete menu color
"highlight Pmenu ctermbg=238 gui=bold
""Multipurpose TAB KEY
" Indent if we're at the beginning of a line. Else, do completion.
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
function! InsertTabWrapper()
let col = col('.') - 1
if !col || getline('.')[col - 1] !~ '\k'
return "\<tab>"
else
return "\<c-p>"
endif
endfunction
inoremap <tab> <c-r>=InsertTabWrapper()<cr>
inoremap <s-tab> <c-n>
""""""""""""""""""""""""""""""""""""""""""""""
" RROW KEYS ARE UNACCEPTABLE
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
map <Left> :echo "no!"<cr>
map <Right> :echo "no!"<cr>
map <Up> :echo "no!"<cr>
map <Down> :echo "no!"<cr>
function! PromoteToSubject()
:normal! dd
:normal! P
:.s/\([^\ ]\+.*\)$/subject { \1 }/
:normal ==
endfunction
:command! PromoteToSubject :call PromoteToSubject()
function! PromoteToLet()
:normal! dd
:normal! P
:.s/\(\w\+\)\s*=\s*\(.*\)$/let(:\1){ \2 }/
:normal ==
endfunction
:command! PromoteToLet :call PromoteToLet()
function! PromoteToIt()
:normal! dd
:normal! P
:.s/\([^\ ]\+.*\)$/it { should \1 }/
:normal ==
endfunction
:command! PromoteToIt :call PromoteToIt()
function! RemoveEndlineWhitespaces()
:normal! dd
:normal! P
:%s/^\(.*[^\ ]\+.*\)\([\ ]\+\)$/\1/
endfunction
:command! RemoveEndlineWhitespaces :call RemoveEndlineWhitespaces()
function! ReplaceHashrockets()
:%s/:\([a-z_A-Z]\+\)\(\ \)\?=>/\1:/Ig
:normal ==
endfunction
:command! ReplaceHashrockets :call ReplaceHashrockets()
function! SubnaviHelper()
:%s/render "application\/\([a-z_A-Z]\+\)\/\([a-z_A-Z]\+\)"/\1(:\2)/Ig
:normal ==
endfunction
:command! SubnaviHelper :call SubnaviHelper()
function! RequestIt()
:.s/expect(response)\.to\ \(.\+\)/it { is_expected.to \1 }/Ig
:normal ==
endfunction
:command! RequestIt :call RequestIt()
function! RequestJSON()
:.s/expect(JSON\.parse(response\.body))\.to\ eq(\(\[{\|{\)/it { is_expected.to be_json_of(\2/Ig
:normal ==
endfunction
:command! RequestJSON :call RequestJSON()
function! ReplaceHashrocketStringKeys()
:%s/"\([a-z_]\+\)"\(\ \)\?=>/\1:/Ig
:normal ==
endfunction
:command! ReplaceHashrocketStringKeys :call ReplaceHashrocketStringKeys()
function! Replace19Hash()
:%s/\([a-z_]\+\):\ /"\1"\ =>\ /Ig
:normal ==
endfunction
:command! Replace19Hash :call Replace19Hash()
function! RemoveDivs()
:%s/%div\([\.#]\)/\1/Ig
:normal ==
endfunction
:command! RemoveDivs :call RemoveDivs()
:inoremap <C-space> <esc>
""""""""""""""""""
"" RSPEC
""""""""""""""""""
let g:rspec_command = 'call Send_to_Tmux("bundle exec rspec --color --no-drb --format d {spec}\n")'
" vim-rspec mappings
map <Leader>t :call RunCurrentSpecFile()<CR>
map <Leader>s :call RunNearestSpec()<CR>
map <Leader>l :call RunLastSpec()<CR>
map <Leader>a :call RunAllSpecs()<CR>
nnoremap <leader>tt :call OpenTestAlternate()<cr>
map <leader><leader> <c-^><cr>
map <leader>. :w<CR>:make -f Makefile.wip<CR>
map <leader>, :w<CR>:VimuxRunLastCommand<CR>
map <leader>n :call RenameFile()<cr>
map <leader>t :CtrlPBuffer<cr>
map <leader>f :CtrlP<cr>
map <leader>F :CtrlP %%<cr>
map <leader>ff :CtrlPClearCache<CR>
map <leader>w :call RemoveEndlineWhitespaces()<cr><Esc>
map <leader>h :call ReplaceHashrockets()<cr>
map <leader>nt :NERDTreeToggle<CR>
map <leader>t :CtrlP .<CR>
map <leader>w :w<CR>
map <leader>x :x<CR>
map <leader>q :q<CR>
map <leader>p :set paste!<CR>
map <leader>c :set relativenumber!<CR>
map <leader>ff :CtrlPClearCache<CR>
map <leader>vl :VimuxRunLastCommand<CR>
:map <leader>ss :PromoteToSubject<cr><Esc>
:map <leader>p :PromoteToLet<cr><Esc>
:map <leader>i :PromoteToIt<cr><Esc>
:map <leader>s :RequestIt<cr>
:map <leader>j :RequestJSON<cr>
:map <leader>H :ReplaceHashrocketStringKeys<cr>
:map <leader>g :Replace19Hash<cr>
:map <leader>d :RemoveDivs<cr>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment