- "Use Vim settings, rather then Vi settings (much better!).
- "This must be first, because it changes other options as a side effect.
- set nocompatible
- source $VIMRUNTIME/mswin.vim
- behave mswin
- " Change home directory
- let $HOME = $VIM . '/home'
- " Disable localvimrc if it's here because we will load it later in the script
- let hasLvimrc = filereadable('_lvimrc')
- if hasLvimrc
- let g:pathogen_disabled = ['localvimrc']
- endif
- " Start Pathogen First!
- source $VIM/bundle/pathogen.vim
- runtime $VIM/bundle/pathogen.vim
- call pathogen#infect('$VIM/bundle')
- " Put these in an autocmd group, so that we can delete them easily.
- augroup vimrcEx
- au!
- " When editing a file, always jump to the last known cursor position.
- " Don't do it when the position is invalid or when inside an event handler
- " (happens when dropping a file on gvim).
- " Also don't do it when the mark is in the first line, that is the default
- " position when opening a file.
- autocmd BufReadPost *
- \ if line("'\"") > 1 && line("'\"") <= line("$") |
- \ exe "normal! g`\"" |
- \ endif
- augroup END
- " ----- ----- ----- -----
- " Behavior
- " ----- ----- ----- -----
- filetype plugin indent on " Important for a lot of things
- set incsearch " Do incremental searching
- set ignorecase " Ignore case when searching, but search capital if used
- set smartcase " But use it when there is uppercase
- set grepprg=grep\ -rnH " Use grep instead of findstr
- set history=50 " Keep 50 lines of command line history
- set wildmenu " Auto complete on command line
- set wildignore+=*.swp,.git,.svn,*.pyc,*.png,*.jpg,*.gif,*.psd,desktop.ini " Ignore these files when searching
- " Disable backup litters
- set nobackup
- set writebackup
- set hidden " Don't unload buffer when it's hidden
- " Delete empty buffers, specially for files opened with --remote option
- autocmd BufAdd * :call <SID>DeleteBufferIfEmpty()
- function s:DeleteBufferIfEmpty()
- if bufname('%') == ''
- bwipe
- " This will trigger filetype detection, mainly to trigger syntax highlighting
- doautocmd BufRead
- endif
- endfunction
- autocmd BufWritePre *.js,*.php :%s/\s\+$//e " Remove trailing space before saving
- autocmd BufWritePre *.js,*.php :%s/^\s\+$//e " Remove empty line
- " ----- ----- ----- -----
- " GUI
- " ----- ----- ----- -----
- if has('gui_running')
- set guifont=Consolas:h10:cANSI
- colorscheme molokus
- endif
- " In many terminal emulators the mouse works just fine, thus enable it.
- if has('mouse')
- set mouse=a
- endif
- " Switch syntax highlighting on, when the terminal has colors
- " Also switch on highlighting the last used search pattern.
- if &t_Co > 2 || has("gui_running")
- syntax on
- set hlsearch
- endif
- " Give alt key control to Windows
- au GUIEnter * simalt ~x
- " Make the cursor look nicer
- set guicursor=i:ver1
- set guicursor=v:hor50
- " Highlight current line
- " set cursorline " this will cause MiniBufferExpl to have problem
- autocmd InsertLeave * set nocursorline
- autocmd InsertEnter * set cursorline
- " Line number
- set number
- set nuw=5
- set guioptions+=emrb " menu, right & bottom scrollbar
- set guioptions-=LtT
- set guitablabel=%-0.12t%M " format of tab label
- set showtabline=1 " show tabs only if there are more than one
- set ruler " show the cursor position all the time
- set showcmd " display incomplete commands
- " ----- ----- ----- -----
- " Text
- " ----- ----- ----- -----
- " Wordwrap
- set lbr
- " Indentation
- set tabstop=4
- set shiftwidth=4
- set softtabstop=4
- set smartindent
- set autoindent
- set nocindent
- " Folding
- set foldmethod=indent
- set foldnestmax=5
- set foldlevel=9 " prefer to be open by default
- set nofoldenable " disable by default
- " ----- ----- ----- -----
- " Remapping
- " ----- ----- ----- -----
- " Use 0 to move to first non-whitespace since I already have home button
- nnoremap 0 ^
- vnoremap 0 ^
- " Auto complete
- inoremap <c-space> <c-x><c-o>
- imap <expr> <tab> pumvisible() ? "<c-n>" : "<tab>"
- imap <expr> <s-tab> pumvisible() ? "<c-p>" : "<s-tab>"
- " Swap quote with backtick so it's easier to move to column
- noremap ' `
- vnoremap ' `
- noremap ` '
- vnoremap ` '
- " Don't use Ex mode, use Q for formatting
- map Q gq
- " Shorter undo sequence. Use CTRL-G u to break undo sequence. :h i_CTRL-G_u http://vim.wikia.com/wiki/Modified_undo_behavior
- inoremap <c-u> <c-g>u<c-u>
- inoremap <c-w> <c-g>u<c-w>
- inoremap <cr> <c-g>u<cr>
- inoremap ' <c-g>u'
- inoremap " <c-g>u"
- inoremap . <c-g>u.
- inoremap , <c-g>u,
- inoremap = <c-g>u=
- inoremap ( <c-g>u(
- inoremap [ <c-g>u[
- inoremap { <c-g>u{
- " inoremap ) <c-g>u)
- " inoremap ] <c-g>u]
- " inoremap } <c-g>u}
- " ----- ----- ----- -----
- " Plugins
- " ----- ----- ----- -----
- " Sessions
- ca SO SessionOpen
- ca SS SessionSave
- " au VimLeave * :SessionSave " auto-save
- " ctrlp
- let g:ctrlp_open_multiple_files = 'i'
- let g:ctrlp_by_filename = 1
- " EasyMotion
- let g:EasyMotion_leader_key = '<Leader>'
- let g:EasyMotion_keys = 'abcdefghijklmnopqrstuvwxyz'
- " Zen Coding
- let g:user_zen_leader_key = '<c-y>'
- let g:user_zen_expandabbr_key = '<c-e>'
- let g:use_zen_complete_tag = 1
- " Comments
- nmap <leader>c <c-_><c-_>
- imap <leader>c <c-o><c-_><c-_>
- vmap <leader>c <c-_><c-_>
- " localvimrc
- let g:localvimrc_name = '_lvimrc'
- let g:localvimrc_count = 1
- let g:localvimrc_sandbox = 0
- let g:localvimrc_ask = 0
- " neocomplcache
- let g:neocomplcache_enable_at_startup = 1
- let g:neocomplcache_enable_smart_case = 1
- let g:neocomplcache_enable_camel_case_completion = 1
- " higher value = higher priority
- " swap priority of syntax and buffer complete
- let g:neocomplcache_source_rank = {
- \ 'buffer_complete': 7,
- \ 'syntax_complete': 5
- \ }
- " MiniBufferExpl
- inoremap <c-tab> <esc>:bn!<cr>
- vnoremap <c-tab> <esc>:bn!<cr>
- nnoremap <c-tab> :bn!<cr>
- inoremap <c-s-tab> <esc>:bp!<cr>
- vnoremap <c-s-tab> <esc>:bp!<cr>
- nnoremap <c-s-tab> :bp!<cr>
- let g:miniBufExplUseSingleClick = 1
- let g:miniBufExplMapWindowNavVim = 1 " ctrl hjkl
- hi MBEVisibleActive guifg=#000000 guibg=#a0a0a0 gui=bold
- hi MBEVisibleChangedActive guifg=#000000 guibg=#a0a0a0 gui=bold,italic
- hi MBEVisibleNormal guifg=#d0d0d0 guibg=#444444 gui=bold
- hi MBEVisibleChanged guifg=#f0f0f0 guibg=#444444 gui=bold,italic
- hi MBENormal guifg=#d0d0d0 guibg=#000000
- hi MBEChanged guifg=#f0f0f0 guibg=#000000 gui=bold,italic
- let g:miniBufExplCheckDupeBufs = 0
- " Toggle g:miniBufExplCheckDupeBufs because sometimes it get very slow
- map <F12> :call ToggleMiniBufExplCheckDupeBufs()<cr>
- function ToggleMiniBufExplCheckDupeBufs()
- if g:miniBufExplCheckDupeBufs == 1
- let g:miniBufExplCheckDupeBufs = 0
- else
- let g:miniBufExplCheckDupeBufs = 1
- endif
- endfunction
- " supertab
- " I prefer this order of cycling through
- " let g:SuperTabMappingBackward = '<tab>'
- " let g:SuperTabMappingForward = '<s-tab>'
- " Auto highlight first match
- " let g:SuperTabLongestHighlight = 1
- " ----- ----- ----- -----
- " Others
- " ----- ----- ----- -----
- " Get syntax under cursor
- " map <F4> :echo "hi<" . synIDattr(synID(line("."),col("."),1),"name") . '> trans<' . synIDattr(synID(line("."),col("."),0),"name") . "> lo<" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"name") . ">" . " FG:" . synIDattr(synIDtrans(synID(line("."),col("."),1)),"fg#")<CR>
- " Vim default diff does not work well
- set diffexpr=MyDiff()
- function MyDiff()
- let opt = '-a --binary '
- if &diffopt =~ 'icase' | let opt = opt . '-i ' | endif
- if &diffopt =~ 'iwhite' | let opt = opt . '-b ' | endif
- let arg1 = v:fname_in
- if arg1 =~ ' ' | let arg1 = '\"' . arg1 . '\"' | endif
- let arg2 = v:fname_new
- if arg2 =~ ' ' | let arg2 = '\"' . arg2 . '\"' | endif
- let arg3 = v:fname_out
- if arg3 =~ ' ' | let arg3 = '\"' . arg3 . '\"' | endif
- let eq = ''
- if $VIMRUNTIME =~ ' '
- if &sh =~ '\<cmd'
- let cmd = '\"' . $VIMRUNTIME . '\diff\"'
- let eq = '\"\"'
- else
- let cmd = substitute($VIMRUNTIME, ' ', '\" ', '') . '\diff\"'
- endif
- else
- let cmd = $VIMRUNTIME . '\diff'
- endif
- silent execute '!' . cmd . ' ' . opt . arg1 . ' ' . arg2 . ' > ' . arg3 . eq
- endfunction
- " ----- ----- ----- -----
- " _lvimrv
- " ----- ----- ----- -----
- " we still need this becuase localvimrc does not load fast enough
- if hasLvimrc
- source _lvimrc
- endif