Created
May 23, 2011 20:07
-
-
Save lightcap/987476 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" Needed on some linux distros. | |
" see http://www.adamlowe.me/2009/12/vim-destroys-all-other-rails-editors.html | |
filetype off | |
call pathogen#runtime_append_all_bundles() | |
call pathogen#helptags() | |
syntax on | |
filetype plugin indent on | |
set nocompatible | |
let leader = "," | |
let g:rails_menu=2 | |
let g:gist_clip_command = 'pbcopy' | |
let g:gist_detect_filetype = 1 | |
let g:gist_open_browser_after_post = 1 | |
" Better surround | |
let g:surround_40 = "(\r)" | |
let g:surround_91 = "[\r]" | |
let g:surround_60 = "<\r>" | |
set backspace=indent,eol,start | |
set backup " keep a backup file | |
set backupdir=~/.vim/backups | |
set history=100 " keep 50 lines of command line history | |
set ruler " show the cursor position all the time | |
"set showcmd " display incomplete commands | |
set incsearch " do incremental searching | |
set expandtab | |
set shiftwidth=2 | |
set tabstop=2 | |
set helpheight=1000 | |
set completeopt=longest,menu,preview | |
set wildmode=longest,list:longest | |
set complete=.,t | |
" .vimrc help | |
let mapleader = "," | |
nmap <leader>v :tabedit $MYVIMRC<CR> | |
" Source the vimrc file after saving it | |
if has("autocmd") | |
autocmd bufwritepost .vimrc source $MYVIMRC | |
endif | |
" Peepopen | |
map gb <C-^> | |
vmap gl :<C-U>!blame <C-R>=expand("%:p") <CR> <C-R>=line("'<") <CR> <C-R>=line("'>") <CR> <CR> | |
vmap # :TComment<CR> | |
map - :Tabularize hash | |
" Make j/k move to next visual line instead of physical line | |
" http://yubinkim.com/?p=6 | |
nnoremap k gk | |
nnoremap j gj | |
nnoremap gk k | |
nnoremap gj j | |
" Use ack | |
nnoremap <leader>a :Ack | |
set grepprg=ack | |
set grepformat=%f:%l:%m | |
" NERDTree | |
nnoremap <leader>d :NERDTreeToggle<CR> | |
set hlsearch | |
set listchars=tab:>-,trail:- | |
hi IncSearch term=reverse gui=underline guibg=Blue guifg=Yellow | |
hi Search term=reverse gui=underline guibg=Black guifg=Yellow | |
hi Visual term=reverse cterm=reverse ctermbg=9 guibg=#555577 guifg=Black | |
hi Pmenu guifg=White guibg=Blue | |
hi PmenuSel gui=italic guifg=Yellow guibg=Blue | |
hi PmenuSbar ctermbg=Black guibg=Grey | |
hi PmenuThumb guifg=Yellow guibg=Black | |
if has("gui_running") | |
set lines=80 | |
set columns=180 | |
endif | |
if has("gui_macvim") | |
" CommandT | |
macmenu &File.New\ Tab key=<nop> | |
map <D-t> :CommandT<CR> | |
" write on pretty much any event (including :q) | |
set autowriteall | |
set tabpagemax=100 | |
set guifont=Inconsolata:h16,\ DejaVu\ Sans\ Mono:h13 | |
" set guifont=Consolas:h18 | |
" Fun with line numbering | |
set relativenumber | |
set fuopt=maxvert,maxhorz | |
" toggle between number and relative number on ,l | |
nnoremap <C-L> :call ToggleRelativeAbsoluteNumber()<CR> | |
function! ToggleRelativeAbsoluteNumber() | |
if &number | |
set relativenumber | |
else | |
set number | |
endif | |
endfunction | |
endif | |
" Nice statusbar | |
set laststatus=2 | |
set statusline= | |
" set statusline+=%2*%-3.3n%0*\ " buffer number | |
set statusline+=%f\ " file name | |
set statusline+=%h%1*%m%r%w%0* " flags | |
set statusline+=%= " right align | |
set statusline+=%-14.(%l,%c%V%)\ %<%P " offset | |
"{{{ Ruby block delimiter conversion: do end <=> { } | |
"Copyright © 2005 Mauricio Fernandez | |
"Subject to same licensing terms as Ruby. | |
" requires matchit and friends | |
" since it uses the % and = bindings | |
function! s:String_Strip(str) | |
let s = substitute(a:str, '\v^\s*', '', '') | |
return substitute(s, '\v\s*$', '', '') | |
endfunction | |
function! s:RubyBlockBraceToDoEnd(lineno) | |
" { } => do end | |
let oldz = getreg("z") | |
call setreg("z", "") | |
execute 'normal ^f{%l"zd$' | |
let suffix = s:String_Strip(getreg("z")) | |
call setreg("z", oldz) | |
let orig = getline(".") | |
let repl = substitute(orig, '\v\s*\{\s*(\|[^|]*\|)?.*', ' do \1', '') | |
call setline(".", repl) | |
let nextline = substitute(orig, '\v[^{]*\v\s*\{\s*(\|[^|]*\|)?', '', '') | |
let nextline = substitute(nextline, '\}[^}]*$', '', '') | |
let numlines = 0 | |
" uncomment one of the following: | |
" (1) just insert the body without splitting the lines on ; | |
"call append(a:lineno, nextline) | |
"call append(a:lineno+1, 'end' . suffix) | |
" | |
" (2) try to split on ; ... | |
call append(a:lineno, 'end' . suffix) | |
" this is what we would want to do: | |
"let nextline = substitute(nextline, ';', "\n", 'g') | |
while stridx(nextline, ";") != -1 | |
let eom = stridx(nextline, ";") | |
let line = s:String_Strip(strpart(nextline, 0, eom)) | |
call append(a:lineno + numlines, line) | |
let numlines = numlines + 1 | |
let nextline = strpart(nextline, eom+1, strlen(nextline) - eom - 1) | |
endwhile | |
let nextline = s:String_Strip(nextline) | |
if strlen(nextline) > 0 | |
call append(a:lineno + numlines, nextline) | |
let numlines = numlines + 1 | |
endif | |
" this is what it all began with... | |
"execute 'normal :s/\v\s*\{\s*(\|.*\|)?/ do \1\r/ | |
' | |
"execute 'normal g_cw | |
end' | |
execute 'normal V' . (1 + numlines) . 'j=' | |
"echo "{ } => do end" | |
endfunction | |
function! s:RubyBlockDoEndToBrace(_firstline, _lastline) | |
" do end => { } | |
let linenum = a:_firstline + 1 | |
let orig = getline(".") | |
while linenum < a:_lastline - 1 | |
let addline = getline(linenum) | |
if '\v^\s*$' !~ addline | |
let addline = substitute(addline, '\v^\s*', '', '') | |
let addline = substitute(addline, '\s*$', '; ', '') | |
let orig = orig . addline | |
endif | |
let linenum = linenum + 1 | |
endwhile | |
let l = substitute(getline(a:_lastline-1), '\v^\s*', '', '') | |
let l = substitute(l, '\s*$', '', '') | |
let orig = orig . l | |
let l = substitute(getline(a:_lastline), '\v^\s*end(\.|\s|$)@=', ' }', '') | |
let l = substitute(l, '\s*$', '', '') | |
let orig = orig . l | |
"echo orig | |
"input(orig) | |
let repl = substitute(orig, '\v\s*do\s*(\|[^|]*\|)?', ' {\1 ', '') | |
"execute 'normal d' . (a:_lastline - a:_firstline) . 'j' | |
execute ':' . a:_firstline . ',' . a:_lastline . 'd' | |
call append(a:_firstline - 1, repl) | |
execute ':' . a:_firstline | |
"echo "do end => { }" | |
endfunction | |
map <SID>xx <SID>xx | |
let s:sid = maparg("<SID>xx") | |
unmap <SID>xx | |
let s:sid = substitute(s:sid, 'xx', '', '') | |
function! <SID>RubyBlockSwitchDelimiters() range | |
set nofoldenable | |
if a:firstline == a:lastline | |
let braceidx = match(getline("."), '{') | |
let doidx = match(getline("."), '\<do\>') | |
if braceidx != -1 && (doidx == -1 || braceidx < doidx) | |
call s:RubyBlockBraceToDoEnd(a:firstline) | |
elseif doidx != -1 | |
execute 'normal /\<do\>' . "\n" . 'V%:call ' . | |
\ s:sid . 'RubyBlockSwitchDelimiters()' . "\n" | |
else | |
echo "No block found" | |
end | |
else | |
call s:RubyBlockDoEndToBrace(a:firstline, a:lastline) | |
endif | |
"execute 'normal V2k=' | |
"execute 'normal v5j' | |
endfunction | |
command! -range B <line1>,<line2>call <SID>RubyBlockSwitchDelimiters() | |
vmap <Leader>B :call <SID>RubyBlockSwitchDelimiters()<cr> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment