Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
448 lines (368 sloc) 11.7 KB
"avoiding annoying CSApprox warning message
let g:CSApprox_verbose_level = 0
"necessary on some Linux distros for pathogen to properly load bundles
filetype on
filetype off
"load pathogen managed plugins
call pathogen#runtime_append_all_bundles()
"Use Vim settings, rather then Vi settings (much better!).
"This must be first, because it changes other options as a side effect.
set nocompatible
"allow backspacing over everything in insert mode
set backspace=indent,eol,start
"store lots of :cmdline history
set history=1000
set showcmd "show incomplete cmds down the bottom
set showmode "show current mode down the bottom
set incsearch "find the next match as we type the search
set hlsearch "hilight searches by default
set number "add line numbers
set showbreak=...
set wrap linebreak nolist
"mapping for command key to map navigation thru display lines instead
"of just numbered lines
vmap <D-j> gj
vmap <D-k> gk
vmap <D-4> g$
vmap <D-6> g^
vmap <D-0> g^
nmap <D-j> gj
nmap <D-k> gk
nmap <D-4> g$
nmap <D-6> g^
nmap <D-0> g^
"add some line space for easy reading
set linespace=4
"disable visual bell
set visualbell t_vb=
"try to make possible to navigate within lines of wrapped lines
nmap <Down> gj
nmap <Up> gk
set fo=l
"statusline setup
set statusline=%f "tail of the filename
set statusline+=[%{GitBranch()}]
set statusline+=%{exists('g:loaded_rvm')?rvm#statusline():''}
set statusline+=%= "left/right separator
set statusline+=%c, "cursor column
set statusline+=%l/%L "cursor line/total lines
set statusline+=\ %P "percent through file
set laststatus=2
"turn off needless toolbar on gvim/mvim
set guioptions-=T
"recalculate the trailing whitespace warning when idle, and after saving
autocmd cursorhold,bufwritepost * unlet! b:statusline_trailing_space_warning
"return '[\s]' if trailing white space is detected
"return '' otherwise
function! StatuslineTrailingSpaceWarning()
if !exists("b:statusline_trailing_space_warning")
if search('\s\+$', 'nw') != 0
let b:statusline_trailing_space_warning = '[\s]'
let b:statusline_trailing_space_warning = ''
return b:statusline_trailing_space_warning
"return the syntax highlight group under the cursor ''
function! StatuslineCurrentHighlight()
let name = synIDattr(synID(line('.'),col('.'),1),'name')
if name == ''
return ''
return '[' . name . ']'
"recalculate the tab warning flag when idle and after writing
autocmd cursorhold,bufwritepost * unlet! b:statusline_tab_warning
"return '[&et]' if &et is set wrong
"return '[mixed-indenting]' if spaces and tabs are used to indent
"return an empty string if everything is fine
function! StatuslineTabWarning()
if !exists("b:statusline_tab_warning")
let tabs = search('^\t', 'nw') != 0
let spaces = search('^ ', 'nw') != 0
if tabs && spaces
let b:statusline_tab_warning = '[mixed-indenting]'
elseif (spaces && !&et) || (tabs && &et)
let b:statusline_tab_warning = '[&et]'
let b:statusline_tab_warning = ''
return b:statusline_tab_warning
"recalculate the long line warning when idle and after saving
autocmd cursorhold,bufwritepost * unlet! b:statusline_long_line_warning
"return a warning for "long lines" where "long" is either &textwidth or 80 (if
"no &textwidth is set)
"return '' if no long lines
"return '[#x,my,$z] if long lines are found, were x is the number of long
"lines, y is the median length of the long lines and z is the length of the
"longest line
function! StatuslineLongLineWarning()
if !exists("b:statusline_long_line_warning")
let long_line_lens = s:LongLines()
if len(long_line_lens) > 0
let b:statusline_long_line_warning = "[" .
\ '#' . len(long_line_lens) . "," .
\ 'm' . s:Median(long_line_lens) . "," .
\ '$' . max(long_line_lens) . "]"
let b:statusline_long_line_warning = ""
return b:statusline_long_line_warning
"return a list containing the lengths of the long lines in this buffer
function! s:LongLines()
let threshold = (&tw ? &tw : 80)
let spaces = repeat(" ", &ts)
let long_line_lens = []
let i = 1
while i <= line("$")
let len = strlen(substitute(getline(i), '\t', spaces, 'g'))
if len > threshold
call add(long_line_lens, len)
let i += 1
return long_line_lens
"find the median of the given array of numbers
function! s:Median(nums)
let nums = sort(a:nums)
let l = len(nums)
if l % 2 == 1
let i = (l-1) / 2
return nums[i]
return (nums[l/2] + nums[(l/2)-1]) / 2
"indent settings
set shiftwidth=2
set softtabstop=2
set expandtab
set autoindent
"folding settings
set foldmethod=indent "fold based on indent
set foldnestmax=3 "deepest fold is 3 levels
set nofoldenable "dont fold by default
set wildmode=list:longest "make cmdline tab completion similar to bash
set wildmenu "enable ctrl-n and ctrl-p to scroll thru matches
set wildignore=*.o,*.obj,*~ "stuff to ignore when tab completing
"display tabs and trailing spaces
"set list
"set listchars=tab:\ \ ,extends:>,precedes:<
" disabling list because it interferes with soft wrap
set formatoptions-=o "dont continue comments when pushing o/O
"vertical/horizontal scroll off settings
set scrolloff=3
set sidescrolloff=7
set sidescroll=1
"load ftplugins and indent files
filetype plugin on
filetype indent on
"turn on syntax highlighting
syntax on
"some stuff to get the mouse going in term
set mouse=a
set ttymouse=xterm2
"hide buffers when not displayed
set hidden
"Command-T configuration
let g:CommandTMaxHeight=10
let g:CommandTMatchWindowAtTop=1
if has("gui_running")
"tell the term has 256 colors
set t_Co=256
colorscheme railscasts
set guitablabel=%M%t
set lines=40
set columns=115
if has("gui_gnome")
set term=gnome-256color
colorscheme railscasts
set guifont=Monospace\ Bold\ 12
if has("gui_mac") || has("gui_macvim")
set guifont=Menlo:h14
" key binding for Command-T to behave properly
" uncomment to replace the Mac Command-T key to Command-T plugin
"macmenu &File.New\ Tab key=<nop>
"map <D-t> :CommandT<CR>
" make Mac's Option key behave as the Meta key
if has("gui_win32") || has("gui_win32s")
set guifont=Consolas:h12
set enc=utf-8
"dont load csapprox if there is no gui support - silences an annoying warning
let g:CSApprox_loaded = 1
"fixed: CSApprox needs gui support - not loading.
let g:CSApprox_verbose_level = 0
"set railscasts colorscheme when running vim in gnome terminal
if $COLORTERM == 'gnome-terminal'
set term=gnome-256color
colorscheme railscasts
colorscheme default
" PeepOpen uses <Leader>p as well so you will need to redefine it so something
" else in your ~/.vimrc file, such as:
" nmap <silent> <Leader>q <Plug>PeepOpen
silent! nmap <silent> <Leader>p :NERDTreeToggle<CR>
"nnoremap <silent> <C-f> :call FindInNERDTree()<CR>
"make <c-l> clear the highlight as well as redraw
nnoremap <C-L> :nohls<CR><C-L>
inoremap <C-L> <C-O>:nohls<CR>
"map to bufexplorer
nnoremap <leader>b :BufExplorer<cr>
"map to CommandT TextMate style finder
nnoremap <leader>t :CommandT<CR>
"map Q to something useful
noremap Q gq
"make Y consistent with C and D
nnoremap Y y$
"bindings for ragtag
inoremap <M-o> <Esc>o
inoremap <C-j> <Down>
let g:ragtag_global_maps = 1
"mark syntax errors with :signs
let g:syntastic_enable_signs=1
"key mapping for vimgrep result navigation
map <A-o> :copen<CR>
map <A-q> :cclose<CR>
map <A-j> :cnext<CR>
map <A-k> :cprevious<CR>
"key mapping for Gundo
nnoremap <F4> :GundoToggle<CR>
"snipmate setup
source ~/.vim/snippets/support_functions.vim
source ~/vimfiles/snippets/support_functions.vim
autocmd vimenter * call s:SetupSnippets()
function! s:SetupSnippets()
"if we're in a rails env then read in the rails snippets
if filereadable("./config/environment.rb")
call ExtractSnips("~/.vim/snippets/ruby-rails", "ruby")
call ExtractSnips("~/.vim/snippets/eruby-rails", "eruby")
call ExtractSnips("~/vimfiles/snippets/ruby-rails", "ruby")
call ExtractSnips("~/vimfiles/snippets/eruby-rails", "eruby")
call ExtractSnips("~/.vim/snippets/html", "eruby")
call ExtractSnips("~/.vim/snippets/html", "xhtml")
call ExtractSnips("~/.vim/snippets/html", "php")
call ExtractSnips("~/vimfiles/snippets/html", "eruby")
call ExtractSnips("~/vimfiles/snippets/html", "xhtml")
call ExtractSnips("~/vimfiles/snippets/html", "php")
"visual search mappings
function! s:VSetSearch()
let temp = @@
norm! gvy
let @/ = '\V' . substitute(escape(@@, '\'), '\n', '\\n', 'g')
let @@ = temp
vnoremap * :<C-u>call <SID>VSetSearch()<CR>//<CR>
vnoremap # :<C-u>call <SID>VSetSearch()<CR>??<CR>
"jump to last cursor position when opening a file
"dont do it when writing a commit log entry
autocmd BufReadPost * call SetCursorPosition()
function! SetCursorPosition()
if &filetype !~ 'commit\c'
if line("'\"") > 0 && line("'\"") <= line("$")
exe "normal! g`\""
normal! zz
"define :HighlightLongLines command to highlight the offending parts of
"lines that are longer than the specified length (defaulting to 80)
command! -nargs=? HighlightLongLines call s:HighlightLongLines('<args>')
function! s:HighlightLongLines(width)
let targetWidth = a:width != '' ? a:width : 79
if targetWidth > 0
exec 'match Todo /\%>' . (targetWidth) . 'v/'
echomsg "Usage: HighlightLongLines [natural number]"
" Strip trailing whitespace
function! <SID>StripTrailingWhitespaces()
" Preparation: save last search, and cursor position.
let _s=@/
let l = line(".")
let c = col(".")
" Do the business:
" Clean up: restore previous search history, and cursor position
let @/=_s
call cursor(l, c)
""autocmd BufWritePre * :call <SID>StripTrailingWhitespaces()
"key mapping for window navigation
map <C-h> <C-w>h
map <C-j> <C-w>j
map <C-k> <C-w>k
map <C-l> <C-w>l
"key mapping for saving file
nmap <C-s> :w<CR>
"key mapping for tab navigation
nmap <Tab> gt
nmap <S-Tab> gT
"Key mapping for textmate-like indentation
nmap <D-[> <<
nmap <D-]> >>
vmap <D-[> <gv
vmap <D-]> >gv
let ScreenShot = {'Icon':0, 'Credits':0, 'force_background':'#FFFFFF'}
let ScreenShot = {'Icon':0, 'Credits':0, 'force_background':'#FFFFFF'}
"Enabling Zencoding
let g:user_zen_settings = {
\ 'php' : {
\ 'extends' : 'html',
\ 'filters' : 'c',
\ },
\ 'xml' : {
\ 'extends' : 'html',
\ },
\ 'haml' : {
\ 'extends' : 'html',
\ },
\ 'erb' : {
\ 'extends' : 'html',
\ },
"ctrl + A 保存
imap <c-a> <esc>:wa<CR>
map <c-a> :wa<CR>
"Ctrl + C 退出窗口
imap <c-c> <esc>:q<CR>
map <c-c> :q<CR>
"Ctrl + S 打开vs新窗口
map <c-s> :vs<CR>
"Ctrl + N 打开sp新窗口
map <c-n> :sp<CR>
let g:yankring_replace_n_nkey = '<m-n>' "修正yankring插件<C-N>热键冲突
set noswapfile
let g:CommandTMaxDepth=50
let g:CommandTMaxFiles=50000
let g:Align_xstrlen = 3