Skip to content

Instantly share code, notes, and snippets.

@dinglixiang
Created April 22, 2014 05:48
Show Gist options
  • Save dinglixiang/11166599 to your computer and use it in GitHub Desktop.
Save dinglixiang/11166599 to your computer and use it in GitHub Desktop.
" Aesthetics
" set background=light
" color mustang
" color railscasts2
" let g:solarized_termcolors=256
set t_Co=16
set background=dark
colorscheme solarized
nmap \ ,
nnoremap / /\v
vnoremap / /\v
nnoremap <leader><space> :noh<cr>
au FocusLost * :wa
map <Leader>w :w<CR>
map <Leader>q :q<CR>
map <Leader>qq :q!<CR>
map <Leader>em :e ~/.vimrc.after<CR>
nnoremap <Leader>re :source %<CR>
set pastetoggle=<C-g>p
vmap <Leader>b :<C-U>!git blame <C-R>=expand("%:p") <CR> \| sed -n <C-R>=line("'<") <CR>,<C-R>=line("'>") <CR>p <CR>'")
map <Leader>e :e <C-R>=expand("%:p:h") . '/'<CR>
map <Leader>s :split <C-R>=expand("%:p:h") . '/'<CR>
map <Leader>v :vnew <C-R>=expand("%:p:h") . '/'<CR>
map <Leader>nn :sp ~/Dropbox/notes/programming_notes.txt<cr>
map <Leader>nf :sp ~/Dropbox/notes/workflow_notes.txt<cr>
" Quickfix
map <Leader>co :copen<CR>
map <Leader>cr :cr<CR>
map <Leader>cl :ccl<CR>
map <Leader>cn :cn<CR>
map <Leader>cp :cp<CR>
map gp `[v`]
" Git
map <Leader>gr :Gread
" Syntax Highlighting
au BufNewFile,BufRead *.god set filetype=ruby
" Janus overwrites
nnoremap <Leader>hs :nohlsearch<CR>
" Fix below
" cnoremap %% <C-R>=expand('%:h').'/'<CR>
" map <Leader>gk :edit %%
" Basic Config
set cmdheight=1
set hidden
set nobackup
set noswapfile
" Screen movements
set scrolloff=3
" File navigation
map <leader>an :next<CR>
map <leader>ap :prev<CR>
" Tabs
map <C-n> :tabnext<CR>
map <C-p> :tabprev<CR>
map <leader>tt :tabnew<cr>
map <leader>te :tabedit
map <leader>tk :tabclose<cr>
map <leader>tm :tabmove
" Snippet
map ,sn :e ~/.vim/janus/vim/tools/snipmate-snippets/snippets/ruby.snippets<cr>
" vim-turbux, depends on TSlime
"let g:turbux_command_rspec = 'script/test' " use Gary Bernhardt's script
let g:no_turbux_mappings = 1
let g:turbux_command_rspec = 's'
let g:turbux_command_cucumber = 'cucumber'
" Tmux / turbux
let g:no_turbux_mappings = 1
let g:turbux_runner = 'tslime' " default: vimux OR tslime OR vim
map <leader>T <Plug>SendTestToTmux
map <leader>t <Plug>SendFocusedTestToTmux
"map ,R :SweetVimRspecRunFile<CR>
"map ,r :SweetVimRspecRunFocused<CR>
"map <M-D-r> :SweetVimRspecRunPrevious<CR> "(OPT-CMD-r)
"
vmap <C-c><C-c> <Plug>SendSelectionToTmux
nmap <C-c><C-c> <Plug>NormalModeSendToTmux
nmap <C-c>r <Plug>SetTmuxVars
" General keyboard mappings
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l
inoremap <C-j> <Esc><C-w>j
inoremap <C-k> <Esc><C-w>k
inoremap jj <ESC>
inoremap kk <ESC>
" unmap! <Leader><Leader>
" set autosave true
" why is below slow??
map <Leader><Leader> <C-^>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" Ruby Refactoring
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
:nnoremap <leader>rap :RAddParameter<cr>
:nnoremap <leader>rcpc :RConvertPostConditional<cr>
:nnoremap <leader>rel :RExtractLet<cr>
:vnoremap <leader>rec :RExtractConstant<cr>
:vnoremap <leader>relv :RExtractLocalVariable<cr>
:nnoremap <leader>rit :RInlineTemp<cr>
:vnoremap <leader>rrlv :RRenameLocalVariable<cr>
:vnoremap <leader>rriv :RRenameInstanceVariable<cr>
:vnoremap <leader>rem :RExtractMethod<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" FILE NAVIGATION
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" map <Leader>g :CtrlPMRU<CR>
map <leader>gv :CtrlP app/views<cr>
map <leader>gc :CtrlP app/controllers<cr>
map <leader>gm :CtrlP app/models<cr>
map <leader>gh :CtrlP app/helpers<cr>
map <leader>gl :CtrlP lib<cr>
map <leader>gp :CtrlP public<cr>
map <leader>gt :CtrlP spec<cr>
" map <leader>gf :CtrlP features<cr>
map <leader>gg :split Gemfile<cr>
" map <leader>gt :CtrlPTag<cr>
map <leader>gk :CtrlPBuffer<cr>
map <leader>f :CtrlP<cr>
map <leader>gf :CtrlP %%<cr>
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" map <leader>cp :set invpaste<CR>:set paste?<CR>
" Rails Alternate file
map <Leader>ra :A<CR>
map <Leader>rl :R<CR>
" reverse results for easier viewing
" let g:CommandTMatchWindowReverse = 1
" Ack - fin[D]
map <Leader>a :Ack<Space>
vnoremap ,a y:<C-U>Ack "<C-R>""<Space>
" Buffer switching
" nnoremap <Leader>l :buffers<CR>:buffer<Space>
" Splits
nnoremap <silent> + :exe "resize " . (winheight(0) * 3/2)<CR>
nnoremap <silent> - :exe "resize " . (winheight(0) * 2/3)<CR>
" Mappings to access buffers (don't use "\p" because a
" " delay before pressing "p" would accidentally paste).
nnoremap <Leader>1 :1b<CR>
nnoremap <Leader>2 :2b<CR>
nnoremap <Leader>3 :3b<CR>
nnoremap <Leader>4 :4b<CR>
nnoremap <Leader>5 :5b<CR>
nnoremap <Leader>6 :6b<CR>
nnoremap <Leader>7 :7b<CR>
nnoremap <Leader>8 :8b<CR>
nnoremap <Leader>9 :9b<CR>
nnoremap <Leader>0 :10b<CR>
" It's useful to show the buffer number in the status line.
" set laststatus=2 statusline=%02n:%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %P
" Cursor
if &term =~ "xterm\\|rxvt"
" use an orange cursor in insert mode
let &t_SI = "\<Esc>]12;orange\x7"
" use a red cursor otherwise
let &t_EI = "\<Esc>]12;red\x7"
silent !echo -ne "\033]12;red\007"
" reset cursor when vim exits
autocmd VimLeave * silent !echo -ne "\033]112\007"
" use \003]12;gray\007 for gnome-terminal
endif
,
" Tabularize
if exists(":Tabularize")
nmap <Leader>a= :Tabularize /=<CR>
vmap <Leader>a= :Tabularize /=<CR>
nmap <Leader>a: :Tabularize /:\zs<CR>
vmap <Leader>a: :Tabularize /:\zs<CR>
endif
" Tabularize Gherkin tables
inoremap <silent> <Bar> <Bar><Esc>:call <SID>align()<CR>a
function! s:align()
let p = '^\s*|\s.*\s|\s*$'
if exists(':Tabularize') && getline('.') =~# '^\s*|' && (getline(line('.')-1) =~# p || getline(line('.')+1) =~# p)
let column = strlen(substitute(getline('.')[0:col('.')],'[^|]','','g'))
let position = strlen(matchstr(getline('.')[0:col('.')],'.*|\s*\zs.*'))
Tabularize/|/l1
normal! 0
call search(repeat('[^|]*|',column).'\s\{-\}'.repeat('.',position),'ce',line('.'))
endif
endfunction
" Change hash synax to Ruby 1.9
function! s:ChangeHashSyntax(line1,line2)
let l:save_cursor = getpos(".")
silent! execute ':' . a:line1 . ',' . a:line2 . 's/:\([a-z0-9_]\+\)\s\+=>/\1:/g'
call setpos('.', l:save_cursor)
endfunction
command! -range=% ChangeHashSyntax call <SID>ChangeHashSyntax(<line1>,<line2>)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment