set enc=utf-8 set fileencoding=utf-8 set fileencodings=ucs-bom,utf8,prc set guifont=Monaco:h11 set guifontwide=NSimsun:h12 set history=700 filetype plugin on filetype indent on set autoread let mapleader = "," let g:mapleader = "," nmap w :w! set so=7 set wildmenu set wildignore=*.o,*~,*.pyc set ruler set cmdheight=2 set hid set backspace=eol,start,indent set whichwrap+=<,>,h,l set ignorecase set smartcase set hlsearch set incsearch set lazyredraw set magic set showmatch set mat=2 set noerrorbells set novisualbell set t_vb= set tm=500 syntax enable colorscheme desert set background=dark if has("gui_running") set guioptions-=T set guioptions+=e set t_Co=256 set guitablabel=%M\ %t endif set encoding=utf8 set ffs=unix,dos,mac set nobackup set nowb set noswapfile set expandtab set smarttab set shiftwidth=4 set tabstop=4 set lbr set tw=500 set ai "Auto indent set si "Smart indent set wrap "Wrap lines cnoreabbrev hex %!xxd vnoremap * :call VisualSelection('f') vnoremap # :call VisualSelection('b') map j gj map k gk map / map ? map :noh map j map k map h map l map bd :Bclose map ba :1,1000 bd! map tn :tabnew map to :tabonly map tc :tabclose map tm :tabmove map te :tabedit =expand("%:p:h")/ map cd :cd %:p:h:pwd try set switchbuf=useopen,usetab,newtab set stal=2 catch endtry autocmd BufReadPost * \ if line("'\"") > 0 && line("'\"") <= line("$") | \ exe "normal! g`\"" | \ endif set viminfo^=% set laststatus=2 set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l/%L\ \ Column:\ %c map 0 ^ nmap mz:m+`z nmap mz:m-2`z vmap :m'>+`mzgv`yo`z vmap :m'<-2`>my` nmap vmap vmap endif func! DeleteTrailingWS() exe "normal mz" %s/\s\+$//ge exe "normal `z" endfunc autocmd BufWrite *.py :call DeleteTrailingWS() autocmd BufWrite *.coffee :call DeleteTrailingWS() vnoremap gv :call VisualSelection('gv') map g :vimgrep // **/*. map :vimgrep // % vnoremap r :call VisualSelection('replace') map cc :botright cope map co ggVGy:tabnew:set syntax=qfpgg map n :cn map p :cp map ss :setlocal spell! map sn ]s map sp [s map sa zg map s? z= noremap m mmHmt:%s///ge'tzt'm map q :e ~/buffer map pp :setlocal paste! function! CmdLine(str) exe "menu Foo.Bar :" . a:str emenu Foo.Bar unmenu Foo endfunction function! VisualSelection(direction) range let l:saved_reg = @" execute "normal! vgvy" let l:pattern = escape(@", '\\/.*$^~[]') let l:pattern = substitute(l:pattern, "\n$", "", "") if a:direction == 'b' execute "normal ?" . l:pattern . "^M" elseif a:direction == 'gv' call CmdLine("vimgrep " . '/'. l:pattern . '/' . ' **/*.') elseif a:direction == 'replace' call CmdLine("%s" . '/'. l:pattern . '/') elseif a:direction == 'f' execute "normal /" . l:pattern . "^M" endif let @/ = l:pattern let @" = l:saved_reg endfunction function! HasPaste() if &paste return 'PASTE MODE ' en return '' endfunction command! Bclose call BufcloseCloseIt() function! BufcloseCloseIt() let l:currentBufNum = bufnr("%") let l:alternateBufNum = bufnr("#") if buflisted(l:alternateBufNum) buffer # else bnext endif if bufnr("%") == l:currentBufNum new endif if buflisted(l:currentBufNum) execute("bdelete! ".l:currentBufNum) endif endfunction " Commenting blocks of code. autocmd FileType c,cpp,java,scala,javascript let b:comment_leader = '// ' autocmd FileType sh,ruby,python let b:comment_leader = '# ' autocmd FileType conf,fstab let b:comment_leader = '# ' autocmd FileType tex let b:comment_leader = '% ' autocmd FileType vim let b:comment_leader = '" ' noremap cc :s/^/=escape(b:comment_leader,'\/')/:nohlsearch noremap cu :s/^\V=escape(b:comment_leader,'\/')//e:nohlsearch vnoremap cc :s/^/=escape(b:comment_leader,'\/')/:nohlsearch vnoremap cu :s/^\V=escape(b:comment_leader,'\/')//e:nohlsearch highlight ColorColumn ctermbg=magenta call matchadd('ColorColumn', '\%80v', 100) nnoremap n n:call HLNext(0.4) nnoremap N N:call HLNext(0.4) highlight WhiteOnRed ctermbg=red ctermfg=white function! HLNext(blinktime) let [bufnum, lnum, col, off] = getpos('.') let machlen = strlen(matchstr(strpart(getline('.'), col-1),@/)) let target_pat = '\c\%#'.@/ let blinks = 3 for n in range(1, blinks) let red = matchadd('WhiteOnRed', target_pat, 101) redraw exec 'sleep ' . float2nr(a:blinktime / (2*blinks) * 1000) . 'm' call matchdelete(red) redraw exec 'sleep ' . float2nr(a:blinktime / (2*blinks) * 1000) . 'm' endfor endfunction " VimScript Highlighting is so fucking distracting augroup VimNoHighlight autocmd! autocmd BufEnter .vimrc syntax off augroup END augroup NoEdits autocmd! autocmd SwapExists * let v:swapchoice = 'o' autocmd SwapExists * echomsg ErrorMsg autocmd SwapExists * echo 'Duplicate edit session (you are now editing readonly)' autocmd SwapExists * echohl None augroup END inoremap ShowDigraphs function! ShowDigraphs() digraphs call getchar() return "\" endfunction