Skip to content

Instantly share code, notes, and snippets.

@puffy
Created October 23, 2018 20:09
Show Gist options
  • Save puffy/4889364b89ca72f98bf6850fc70b0b2f to your computer and use it in GitHub Desktop.
Save puffy/4889364b89ca72f98bf6850fc70b0b2f to your computer and use it in GitHub Desktop.
" load up pathogen and all bundles
call pathogen#infect()
call pathogen#helptags()
syntax on " show syntax highlighting
filetype plugin indent on
set autoindent " set auto indent
"set smartindent
set nu
set ts=2 " set indent to 2 spaces
set shiftwidth=2
set expandtab " use spaces, not tab characters
set nocompatible " don't need to be compatible with old vim
set hidden
set showmatch " show bracket matches
set ignorecase " ignore case in search
set hlsearch " highlight all search matches
set cursorline " highlight current line
set incsearch " show search results as I type
"set mouse=a " enable mouse support
set list listchars=tab:»·,trail:· " show extra space characters
set wildmenu " enable bash style tab completion
set wildmode=list:longest,full
set statusline=%<%f%m%r\ %{&fileencoding}\ Buf:%n\ Line:%l/%L\ Col:%c
set laststatus=2
colorscheme idleFingers
let mapleader = ","
set ttimeoutlen=100
let g:ctrlp_map = '<leader>p'
let g:ctrlp_working_path_mode = 0
" use silver searcher for ctrlp
let g:ctrlp_user_command = 'ag %s -l --nocolor -g ""'
" use % to jump between start/end of methods
runtime macros/matchit.vim
" map Silver Searcher
map <leader>f :Ag!<space>
" search for word under cursor with Silver Searcher
map <leader>F :Ag! "<C-r>=expand('<cword>')<CR>"
" close quick list
nmap <leader>q <C-w>j q
" clear the command line and search highlighting
noremap <C-l> :nohlsearch<CR>
noremap <silent> <leader>bd :bd<CR>
noremap <silent> <leader>bp :bp<CR>
noremap <silent> <leader>bn :bn<CR>
nmap <silent> ,ev :e $MYVIMRC<CR>
" Source the vimrc file after saving it
if has("autocmd")
autocmd bufwritepost .vimrc source $MYVIMRC
endif
nmap <silent> <leader>n :NERDTreeToggle<CR>
nmap <silent> <leader>R :e config/routes.rb<CR>
nmap <silent> <leader>S :e db/schema.rb<CR>
nmap <silent> <leader>ru :e config/locales/ru.yml<CR>
nmap <silent> <leader>en :e config/locales/en.yml<CR>
nmap <silent> <leader>w :w<CR>
" map . in visual mode
"vnoremap . :norm.<cr>
au BufRead,BufNewFile *.rabl setf ruby
au BufRead,BufNewFile *.hamlc setf haml
" Syntastic options
let g:syntastic_auto_jump = 1
" TODO: bind command for replace old ruby hashes
" %s/:\([^ ]*\)\(\s*\)=>/\1:/g
" run specs with ',t' via Gary Bernhardt
function! RunTests(filename)
" Write the file and run tests for the given filename
:w
:silent !clear
if match(a:filename, '\.feature$') != -1
exec ":!bundle exec cucumber --drb " . a:filename
elseif match(a:filename, '_test\.rb$') != -1
exec ":!ruby -Itest " . a:filename
else
if filereadable("script/test")
exec ":!script/test " . a:filename
elseif filereadable("Gemfile")
exec ":!bundle exec rspec --color --drb " . a:filename
else
exec ":!rspec --color " . a:filename
end
end
endfunction
function! SetTestFile()
" set the spec file that tests will be run for.
let t:grb_test_file=@%
endfunction
function! RunTestFile(...)
if a:0
let command_suffix = a:1
else
let command_suffix = ""
endif
" run the tests for the previously-marked file.
let in_test_file = match(expand("%"), '\(.feature\|_spec.rb\|_test.rb\)$') != -1
if in_test_file
call SetTestFile()
elseif !exists("t:grb_test_file")
return
end
call RunTests(t:grb_test_file . command_suffix)
endfunction
function! RunNearestTest()
let spec_line_number = line('.')
call RunTestFile(":" . spec_line_number . " -b")
endfunction
" run test runner
map <leader>T :call RunTestFile()<cr>
map <leader>t :call RunNearestTest()<cr>
" Show syntax highlighting groups for word under cursor
nmap <leader>s :call <SID>SynStack()<CR>
function! <SID>SynStack()
if !exists("*synstack")
return
endif
echo map(synstack(line('.'), col('.')), 'synIDattr(v:val, "name")')
endfunc
" GO settings
autocmd BufNewFile,BufRead *.go setlocal expandtab ts=2 shiftwidth=2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment