" vgod's vimrc " Tsung-Hsiang (Sean) Chang " Fork me on GITHUB https://github.com/vgod/vimrc " read https://github.com/vgod/vimrc/blob/master/README.md for more info " For pathogen.vim: auto load all plugins in .vim/bundle let g:pathogen_disabled = [] if !has('gui_running') call add(g:pathogen_disabled, 'powerline') endif call pathogen#runtime_append_all_bundles() call pathogen#helptags() " General Settings 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 off " necessary to make ftdetect work on Linux syntax on 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 syntax on " syntax highlight set hlsearch " search highlighting if has("gui_running") " GUI color and font settings set guifont=Osaka-Mono:h20 set background=dark set t_Co=256 " 256 color mode set cursorline " highlight current line colors moria highlight CursorLine guibg=#003853 ctermbg=24 gui=none cterm=none else " terminal color settings colors vgod endif set clipboard=unnamed " yank to the system register (*) by default set showmatch " Cursor shows matching ) and } set showmode " Show current mode set wildchar= " start wild expansion in the command line using set wildmenu " wild char completion menu " ignore these files while expanding wild chars set wildignore=*.o,*.class,*.pyc 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 smarttab " insert tabs on the start of a line according to context " disable sound on errors set noerrorbells set novisualbell set t_vb= set tm=500 " TAB setting{ set expandtab "replace with spaces set softtabstop=3 set shiftwidth=3 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 and replace with input() in all open buffers "--------------------------------------------------------------------------- fun! Replace() let s:word = input("Replace " . expand('') . " with:") :exe 'bufdo! %s/\<' . expand('') . '\>/' . s:word . '/ge' :unlet! s:word endfun "--------------------------------------------------------------------------- " USEFUL SHORTCUTS "--------------------------------------------------------------------------- " set leader to , let mapleader="," let g:mapleader="," "replace the current word in all opened buffers map r :call Replace() " open the error console map cc :botright cope " move to next error map ] :cn " move to the prev error map [ :cp " --- move around splits { " move to and maximize the below split map j_ " move to and maximize the above split map k_ " move to and maximize the left split nmap h " move to and maximize the right split nmap l 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 " } " move around tabs. conflict with the original screen top/bottom " comment them out if you want the original H/L " go to prev tab map gT " go to next tab map gt " new tab map :tabnew " close tab map :tabclose " ,/ turn off search highlighting nmap / :nohl " Bash like keys for the command line cnoremap cnoremap cnoremap " ,p toggles paste mode nmap p :set paste!set paste? " allow multiple indentation/deindentation in visual mode vnoremap < >gv " :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 1 yyPVr#yyjp inoremap 1 yyPVr#yyjpA " Ctrl-u 2: underline Chapters w/ *'s noremap 2 yyPVr*yyjp inoremap 2 yyPVr*yyjpA " Ctrl-u 3: underline Section Level 1 w/ ='s noremap 3 yypVr= inoremap 3 yypVr=A " Ctrl-u 4: underline Section Level 2 w/ -'s noremap 4 yypVr- inoremap 4 yypVr-A " Ctrl-u 5: underline Section Level 3 w/ ^'s noremap 5 yypVr^ inoremap 5 yypVr^A "} "--------------------------------------------------------------------------- " PROGRAMMING SHORTCUTS "--------------------------------------------------------------------------- " Ctrl-[ jump out of the tag stack (undo Ctrl-]) map :po " ,g generates the header guard map g :call IncludeGuard() 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 set cot-=preview "disable doc preview in omnicomplete " 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' "} " --- AutoClose - Inserts matching bracket, paren, brace or quote " fixed the arrow key problems caused by AutoClose if !has("gui_running") set term=linux imap OA ki imap OB ji imap OC li imap OD hi nmap OA k nmap OB j nmap OC l nmap OD h endif " --- Command-T let g:CommandTMaxHeight = 15 " --- SuperTab let g:SuperTabDefaultCompletionType = "context" let g:SuperTabCompletionContexts = ['s:ContextText', 's:ContextDiscover'] let g:SuperTabContextDiscoverDiscovery = ["&completefunc:", "&omnifunc:"] " --- EasyMotion "let g:EasyMotion_leader_key = 'm' " default is w hi link EasyMotionTarget ErrorMsg hi link EasyMotionShade Comment " --- TagBar " toggle TagBar with F7 nnoremap :TagbarToggle " set focus to TagBar when opening it let g:tagbar_autofocus = 1 " --- PowerLine " let g:Powerline_symbols = 'fancy' " require fontpatcher " " --- SnipMate let g:snipMateAllowMatchingDot = 0 " --- coffee-script au BufWritePost *.coffee silent CoffeeMake! -b | cwindow | redraw! " recompile coffee scripts on write " --- vim-gitgutter let g:gitgutter_enabled = 1 " set ejs filetype to html au BufNewFile,BufRead *.ejs set filetype=html