Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
493 lines (394 sloc) 14.8 KB
" radicalbit's vimrc
" forked from vgod (https://github.com/vgod/vimrc)
if has("gui_running") " GUI color and font settings
else
let loaded_showmarks = 1 " don't use showmarks in a terminal
endif
" For pathogen.vim: auto load all plugins in .vim/bundle
call pathogen#infect()
" General Settings
set backupdir=~/.vim/backup//
set directory=~/.vim/swap//
set nocompatible " not compatible with the old-fashion vi mode
set bs=2 " allow backspacing over everything in insert mode
set history=50 " keep 50 lines of command line history
set ruler " show the cursor position all the time
set autoread " auto read when file is changed from outside
filetype on " Enable filetype detection
filetype indent on " Enable filetype-specific indenting
filetype plugin on " Enable filetype-specific plugins
" auto reload vimrc when editing it
autocmd! bufwritepost .vimrc source ~/.vimrc
augroup whitespace
au!
autocmd FileType objc,objcpp autocmd BufWritePre <buffer> :%s/\s\+$//e
augroup END
syntax on " syntax highlight
set hlsearch " search highlighting
if has("gui_running") " GUI color and font settings
set guifont=ocra10:h12
set background=dark
set t_Co=256 " 256 color mode
set cursorline " highlight current line
let g:showmarks_enable=1
colors moria
else
" terminal color settings
colors desert256
let g:showmarks_enable=0
endif
" set leader to ,
let mapleader=","
let g:mapleader=","
let maplocalleader=","
let g:maplocalleader=","
hi LineNr ctermfg=darkgray guifg=#555555 gui=none
set clipboard=unnamed " yank to the system register (*) by default
set showmatch " Cursor shows matching ) and }
set showmode " Show current mode
set wildchar=<TAB> " start wild expansion in the command line using <TAB>
set wildmenu " wild char completion menu
" ignore these files while expanding wild chars
set wildignore=*.o,*.class,*.pyc,build/**,*.xcodeproj/**,*.m,*.hi,*.png,*.dyn_hi,*.dyn_o
"set smartindent
"set autoindent " auto indentation
set incsearch " incremental search
set nobackup " no *~ backup files
set copyindent " copy the previous indentation on autoindenting
set ignorecase " ignore case when searching
set smartcase " ignore case if search pattern is all lowercase,case-sensitive otherwise
"set hidden
set number
" disable sound on errors
set noerrorbells
set vb " this removes the bells on MacVim
set t_vb=
set tm=500
" TAB setting{
"set expandtab "replace <TAB> with spaces
"set softtabstop=3
"set shiftwidth=3
set tabstop=8 "A tab is 8 spaces
set expandtab "Always uses spaces instead of tabs
set softtabstop=4 "Insert 4 spaces when tab is pressed
set shiftwidth=4 "An indent is 4 spaces
set smarttab "Indent instead of tab at start of line
set shiftround "Round spaces to nearest shiftwidth multiple
set nojoinspaces "Don't convert spaces to tabs
au FileType Makefile set noexpandtab
"}
" status line {
set laststatus=2
set statusline=\ %{HasPaste()}%<%-15.25(%f%)%m%r%h\ %w\ \
set statusline+=\ \ \ [%{&ff}/%Y]
set statusline+=\ \ \ %<%20.30(%{hostname()}:%{CurDir()}%)\
set statusline+=%=%-10.(%l,%c%V%)\ %p%%/%L
function! CurDir()
let curdir = substitute(getcwd(), $HOME, "~", "")
return curdir
endfunction
function! HasPaste()
if &paste
return '[PASTE]'
else
return ''
endif
endfunction
"}
" C/C++ specific settings
"autocmd FileType c,cpp,cc set cindent comments=sr:/*,mb:*,el:*/,:// cino=>s,e0,n0,f0,{0,}0,^-1s,:0,=s,g0,h1s,p2,t0,+2,(2,)20,*30
"Restore cursor to file position in previous editing session
set viminfo='10,\"100,:20,%,n~/.viminfo
au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif
"---------------------------------------------------------------------------
" Tip #382: Search for <cword> and replace with input() in all open buffers
"---------------------------------------------------------------------------
fun! Replace()
let s:word = input("Replace " . expand('<cword>') . " with:")
:exe 'bufdo! %s/\<' . expand('<cword>') . '\>/' . s:word . '/ge'
:unlet! s:word
endfun
"---------------------------------------------------------------------------
" OBJECTIVE-C
"---------------------------------------------------------------------------
function! ObjCTagJump()
"set lz
execute "normal mf\"fyi[`f"
let l:original = @f
let l:original = substitute(l:original, '\[.\{-}\]', "sqr", "g")
let l:original = substitute(l:original, "\(.\{-}\)", "par", "g")
let l:parts = split(l:original)
if len(l:parts) == 2
let l:result = l:parts[1]
if l:parts[1] =~ '\k\+:'
let items = split(l:parts[1],":")
let l:result = items[0] . ":"
endif
else
let l:result = ""
for i in l:parts
if i =~ '\k\+:'
let items = split(i,":")
let l:result .= items[0] . ":"
endif
endfor
endif
execute 'tjump ' . l:result
normal zz
endfunction
nnoremap gx :call ObjCTagJump()<CR>
" When on a member declaration line, add a matching property line below
function! ObjCMakeProperty()
execute "normal mf\"fyy"
execute "normal /}\<CR>"
execute "normal /^\s*$\<CR>"
execute "normal \"fp=="
let l:parts = split(@f)
let l:type = l:parts[0]
execute "normal I@property \<ESC>"
if @f =~ '\*'
execute "normal a(nonatomic, retain) \<ESC>"
endif
nohl
execute "normal `f"
endfunction
nnoremap <Leader>v :call ObjCMakeProperty()<CR>
" When on a class name, add a matching import
function! ObjCMakeImport()
execute "normal mf\"fyaw"
execute "normal ?import\<CR>"
execute "normal o#import \"\<ESC>\"fps.h\"\<ESC>"
endfunction
nnoremap <Leader>i :call ObjCMakeImport()<CR>
" When on a define-type line, insert all the gambit scheme method symbols
" (define-type TypeName mema memb memc)
function! GambitMakeTypeSymbols()
execute "normal mf^\"fd$"
let l:clean = substitute(@f, "\(", " ", "g")
let l:clean = substitute(l:clean, "\)", "", "")
let l:parts = split(l:clean)
let @g = l:parts[1]
execute "normal \"gPa? make-\<ESC>\"gp"
let i = 2
while i < len(l:parts)
let @h = l:parts[i]
execute "normal $a \<ESC>\"gp$a-\<ESC>\"hpa \<ESC>\"gpa-\<ESC>\"hpa-set!\<ESC>"
let i += 1
endwhile
endfunction
nnoremap <Leader>j :call GambitMakeTypeSymbols()<CR>
function! SwitchGambitHeader()
let l:filename = @%
let l:idx = stridx(l:filename, "#")
if l:idx > -1
let l:af = substitute(l:filename, "\\#", "", "")
execute "edit " . l:af
else
let l:af = substitute(l:filename, "\\.", "\\\\#\.", "")
execute "edit " . l:af
endif
endfunction
nnoremap <Leader>a :call SwitchGambitHeader()<CR>
"---------------------------------------------------------------------------
" USEFUL SHORTCUTS
"---------------------------------------------------------------------------
"replace the current word in all opened buffers
"noremap <leader>r :call Replace()<CR>
"reload the config
noremap <Leader>z :source $MYVIMRC<CR>:echom "~/.vimrc reloaded"<CR>
"quick grep on all files
noremap <Leader>f :vimgrep //gj *.mm<left><left><left><left><left><left><left><left>
"quick substitution
noremap <Leader>r :%s/\<<C-R><C-W>\>//ge<left><left><left>
noremap 9 $
noremap <Leader>e :call SyntaxAttr()<CR>
noremap <Leader>l :ListMethods<CR>
noremap <Leader>q <C-W><C-W>
noremap <S-Down> <C-D>zz
noremap <S-Up> <C-U>zz
noremap <C-J> <C-D>zz
noremap <C-K> <C-U>zz
noremap <Leader>f :vimgrep //gj *.mm<left><left><left><left><left><left><left><left>
nmap <BACKSPACE> <C-o>
nnoremap <leader>W :%s/\s\+$//<CR>:let @/=''<CR>``
" open the error console
noremap <leader>cc :botright cope<CR>
" move to next error
noremap <leader>] :cn<CR>
" move to the prev error
noremap <leader>[ :cp<CR>
noremap g= mfgg=G`f
" --- move around splits {
" move to and maximize the below split
"noremap <C-J> <C-W>j<C-W>_
" move to and maximize the above split
"noremap <C-K> <C-W>k<C-W>_
" move to and maximize the left split
"nmap <c-h> <c-w>h<c-w><bar>
" move to and maximize the right split
"nmap <c-l> <c-w>l<c-w><bar>
set wmw=0 " set the min width of a window to 0 so we can maximize others
set wmh=0 " set the min height of a window to 0 so we can maximize others
" }
" ,/ turn off search highlighting
nmap <leader>/ :nohl<CR>
" Bash like keys for the command line
cnoremap <C-A> <Home>
cnoremap <C-E> <End>
cnoremap <C-K> <C-U>
" open help file in vertical split to the right
cnoreabbrev vhelp vert bo help
" ,p toggles paste mode
nmap <leader>p :set paste!<BAR>set paste?<CR>
" allow multiple indentation/deindentation in visual mode
vnoremap < <gv
vnoremap > >gv
noremap Y y$
" :cd. change working directory to that of the current file
cmap cd. lcd %:p:h
" Writing Restructured Text (Sphinx Documentation) {
" Ctrl-u 1: underline Parts w/ #'s
noremap <C-u>1 yyPVr#yyjp
inoremap <C-u>1 <esc>yyPVr#yyjpA
" Ctrl-u 2: underline Chapters w/ *'s
noremap <C-u>2 yyPVr*yyjp
inoremap <C-u>2 <esc>yyPVr*yyjpA
" Ctrl-u 3: underline Section Level 1 w/ ='s
noremap <C-u>3 yypVr=
inoremap <C-u>3 <esc>yypVr=A
" Ctrl-u 4: underline Section Level 2 w/ -'s
noremap <C-u>4 yypVr-
inoremap <C-u>4 <esc>yypVr-A
" Ctrl-u 5: underline Section Level 3 w/ ^'s
noremap <C-u>5 yypVr^
inoremap <C-u>5 <esc>yypVr^A
"}
"---------------------------------------------------------------------------
" PROGRAMMING SHORTCUTS
"---------------------------------------------------------------------------
:cmap acks Ack --haskell
nnoremap <leader>d :GhcModType<CR>
"nnoremap <leader>d :call JumpToSchemeDefinition()<CR>
nnoremap <leader>s :call SearchSchemeUse()<CR>
nnoremap <leader>f :call SearchStringSchemeUse()<CR>
fun! JumpToSchemeDefinition()
"let l:info = system("ag --scheme --nocolor --nogroup --column \"\\(define[\w-]* \\(?" . escape(expand('<cword>'), '#|') . "[^\-]\"")
let l:info = system("ag --scheme --nocolor --nogroup --column \"\\(define[\w-]* \\(?" . escape(expand('<cword>'), '#|') . "[^\w-]\"")
let l:info = substitute(l:info, '\n$', '', '')
"let l:info = system("echo hi")
"echom l:info
execute "cexpr \"" . l:info . "\""
endfun
fun! ShowSchemeDefinition()
let l:info = system("ag --scheme -h --nocolor \"\\(define[\w-]* \\(?" . escape(expand('<cword>'), '#|') . "\\)? ?$?\"")
echom l:info
endfun
fun! SearchSchemeUse()
let l:keyword = escape(expand('<cword>'), '#|')
"echom l:keyword
execute "ag --scheme \"" . l:keyword . "\""
"let l:result = system("ag --scheme --nocolor --nogroup \"" . l:keyword . "\"")
"execute "cexpr \"" . l:result . "\""
endfun
fun! SearchStringSchemeUse()
let s:word = input("Scheme search: ")
execute "ag --scheme --nocolor \"" . s:word . "\""
endfun
" Ctrl-[ jump out of the tag stack (undo Ctrl-])
noremap <BACKSPACE> <ESC>:po<CR>
" ,g generates the header guard
noremap <leader>g :call IncludeGuard()<CR>
fun! IncludeGuard()
let basename = substitute(bufname(""), '.*/', '', '')
let guard = '_' . substitute(toupper(basename), '\.', '_', "H")
call append(0, "#ifndef " . guard)
call append(1, "#define " . guard)
call append( line("$"), "#endif // for #ifndef " . guard)
endfun
" Enable omni completion. (Ctrl-X Ctrl-O)
autocmd FileType html,markdown setlocal omnifunc=htmlcomplete#CompleteTags
autocmd FileType javascript setlocal omnifunc=javascriptcomplete#CompleteJS
autocmd FileType python setlocal omnifunc=pythoncomplete#Complete
autocmd FileType xml setlocal omnifunc=xmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType c set omnifunc=ccomplete#Complete
autocmd FileType java set omnifunc=javacomplete#Complete
" use syntax complete if nothing else available
if has("autocmd") && exists("+omnifunc")
autocmd Filetype *
\ if &omnifunc == "" |
\ setlocal omnifunc=syntaxcomplete#Complete |
\ endif
endif
" make CSS omnicompletion work for SASS and SCSS
autocmd BufNewFile,BufRead *.scss set ft=scss.css
autocmd BufNewFile,BufRead *.sass set ft=sass.css
"---------------------------------------------------------------------------
" ENCODING SETTINGS
"---------------------------------------------------------------------------
set encoding=utf-8
set termencoding=utf-8
set fileencoding=utf-8
set fileencodings=ucs-bom,utf-8,big5,gb2312,latin1
fun! ViewUTF8()
set encoding=utf-8
set termencoding=big5
endfun
fun! UTF8()
set encoding=utf-8
set termencoding=big5
set fileencoding=utf-8
set fileencodings=ucs-bom,big5,utf-8,latin1
endfun
fun! Big5()
set encoding=big5
set fileencoding=big5
endfun
"---------------------------------------------------------------------------
" PLUGIN SETTINGS
"---------------------------------------------------------------------------
" ------- vim-latex - many latex shortcuts and snippets {
" IMPORTANT: win32 users will need to have 'shellslash' set so that latex
" can be called correctly.
set shellslash
set grepprg=grep\ -nH\ $*
" OPTIONAL: Starting with Vim 7, the filetype of empty .tex files defaults to
" 'plaintex' instead of 'tex', which results in vim-latex not being loaded.
" The following changes the default filetype back to 'tex':
let g:tex_flavor='latex'
"}
" --- Command-T
let g:CommandTMaxHeight = 15
" --- SuperTab
let g:SuperTabDefaultCompletionType = "<c-p>"
"let g:SuperTabMappingForward = '<c-tab>'
" --- SnipMate
let g:snips_trigger_key='<c-space>'
" --- TagBar
" toggle TagBar with F7
nnoremap <silent> <F7> :TagbarToggle<CR>
" set focus to TagBar when opening it
let g:tagbar_autofocus = 1
" --- NERD_commenter
map - <Leader>c<Space>
" --- EasyMotion
"let g:EasyMotion_leader_key = '<Space>'
let g:EasyMotion_leader_key = '<Leader>m'
nmap <Space> <Leader>m
" --- vim-sexp
let g:sexp_enable_insert_mode_mappings=0
nmap <C-l> <Plug>sexp_swap_element_forward
nmap <C-h> <Plug>sexp_swap_element_backward
autocmd FileType scheme :call TurnOnSchemeFolding()
"autocmd FileType scheme :call RainbowParenthesesToggleAll()
"autocmd FileType scheme :call rainbow_parentheses#toggleall()
let g:haskell_conceal = 0
let g:showmarks_textlower = "\t"
let g:showmarks_textupper = "\t"
let g:showmarks_textother = " "
let g:syntastic_haskell_hdevtools_args = '-g-i/Users/axis/Development/haskell/Games/Hickory/ -g-L/Users/axis/Development/haskell/Games/Hickory/ -g-Wall -g-fno-warn-unused-matches -g-fno-warn-missing-signatures -g-fno-warn-unused-do-bind'
let g:syntastic_haskell_checkers = ['hdevtools']
let g:syntastic_always_populate_loc_list = 1
"let g:ghcmod_ghc_options = ['-i/Users/axis/Development/haskell/crater/', '-L/Users/axis/Development/haskell/crater/']
"let g:hdevtools_options = '-g-i/Users/axis/Development/haskell/crater/ -g-Wall -g -hide-package -g transformers'
au BufRead * normal zR