" require python " require lua 5.2 " recompile vim with python and lua support " require git " require vundle " require solarized theme " require microsoft yahei mono font " require download latex suit from sourceforg """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " if need youCompleteMe Plugin """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " require download you complete me from bitbucket " require download libclang.dll from http://www.ishani.org/ " require visual studio express for windows desktop " useful repo(download vim with python,vim,ruby support) " https://bitbucket.org/Haroogan """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Load Vundle """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set nocompatible " be iMproved filetype off " required! set rtp+=~/.vim/bundle/vundle/ call vundle#rc() """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Bundle (run BundleInstall to work) """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" Bundle 'jlanzarotta/bufexplorer' Bundle 'altercation/vim-colors-solarized' Bundle 'klen/python-mode' Bundle 'scrooloose/nerdtree' " Bundle 'https://bitbucket.org/Haroogan/vim-youcompleteme-for-windows.git' Bundle 'Shougo/neocomplete.vim' Bundle 'mattn/emmet-vim' Bundle 'mileszs/ack.vim' Bundle 'Lokaltog/vim-easymotion' Bundle 'Lokaltog/vim-powerline' Bundle 'scrooloose/nerdcommenter' Bundle 'wincent/Command-T' Bundle 'L9' Bundle 'FuzzyFinder' Bundle 'mru' Bundle 'tComment' set rtp+=$VIMRUNTIME\extra-bundle\vim-latex-1.8.23 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => General """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Sets how many lines of history VIM has to remember set history=700 " Enable filetype plugin filetype plugin on filetype indent on " Set to auto read when a file is changed from the outside set autoread " With a map leader it's possible to do extra key combinations " like w saves the current file let mapleader = "," let g:mapleader = "," set confirm "Y-N-C prompt if closing with unsaved changes. set report=0 " : commands always print changed line count. set showcmd " Show incomplete normal mode commands as I type. set shortmess+=a " Use [+]/[RO]/[w] for modified/readonly/written. " don't outdent hashes " inoremap # # " fold set foldmethod=syntax set foldlevel=10 set laststatus=2 " Fast editing of the .vimrc map e :e! ~/.vim_runtime/vimrc " When vimrc is edited, reload it autocmd! bufwritepost vimrc source ~/.vim_runtime/vimrc autocmd BufNewFile,BufWritePre *.sh set fileformat=unix autocmd BufWritePre * retab " Removes trailing spaces function! TrimWhiteSpace() let previous_search=@/ let previous_cursor_line=line('.') let previous_cursor_column=col('.') %s/\s\+$//e %s/^\n\+/\r/e let @/=previous_search call cursor(previous_cursor_line, previous_cursor_column) endfunction """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => VIM user interface """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Set 7 lines to the curors - when moving vertical.. set so=7 set wildmenu "Turn on WiLd menu set ruler "Always show current position set cmdheight=2 "The commandbar height set hid "Change buffer - without saving " Set backspace config set backspace=eol,start,indent set whichwrap+=<,>,h,l set ignorecase "Ignore case when searching set smartcase set hlsearch "Highlight search things set incsearch "Make search act like search in modern browsers set nolazyredraw "Don't redraw while executing macros set magic "Set magic on, for regular expressions set showmatch "Show matching bracets when text indicator is over them set mat=2 "How many tenths of a second to blink " No sound on errors set noerrorbells set novisualbell set t_vb= " disable beep set tm=500 """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Colors and Fonts """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "colorscheme corporation colorscheme solarized let g:rehash256 = 1 " when using molokai in console version "set background=dark syntax on " Enable syntax highlight set nu " line number set encoding=utf8 set guifont=Microsoft\ YaHei\ Mono:h11:cANSI set termencoding=utf-8 set fileencoding=utf-8 set fileencodings=ucs-bom,utf-8,chinese,latin1,big5,euc-jp,euc-kr set langmenu=en_US.utf-8 language messages en_US.utf-8 language messages en_US.utf-8 if has("win32") set shellslash source $VIMRUNTIME/delmenu.vim source $VIMRUNTIME/menu.vim endif if has('gui_running') set go = " Maximising Screen Space set t_Co=256 set guitablabel=%t endif try lang en_US catch endtry """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Files, backups and undo """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set nobackup " No Backup file set nowb " No nowrithbackup set noswapfile set noautowrite " Never write a file unless I request it. set noautowriteall " NEVER. "Persistent undo try if MySys() == "windows" set undodir=C:\Windows\Temp else set undodir=~/.vim_runtime/undodir endif set undofile catch endtry """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Text, tab and indent related """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" set expandtab set shiftwidth=4 set tabstop=4 set softtabstop=4 set smarttab " want to meet the gold ratio, but ... set lines=30 " gui window height set columns=135 " gui window width set lbr "Linebreak " set textwidth=78 fo+=Mm " text width set ai "Auto indent set si "Smart indet set wrap "Wrap lines """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Visual mode related """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Really useful! " In visual mode when you press * or # to search for the current selection vnoremap * :call VisualSearch('f') vnoremap # :call VisualSearch('b') " When you press gv you vimgrep after the selected text vnoremap gv :call VisualSearch('gv') map g :vimgrep // **/*. function! CmdLine(str) exe "menu Foo.Bar :" . a:str emenu Foo.Bar unmenu Foo endfunction " From an idea by Michael Naumann function! VisualSearch(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 == 'f' execute "normal /" . l:pattern . "^M" endif let @/ = l:pattern let @" = l:saved_reg endfunction """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Command mode related """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" cno $c e eCurrentFileDir("e") " $q is super useful when browsing on the command line cno $q eDeleteTillSlash() " Bash like keys for the command line cnoremap cnoremap cnoremap func! Cwd() let cwd = getcwd() return "e " . cwd endfunc func! DeleteTillSlash() let g:cmd = getcmdline() if MySys() == "linux" || MySys() == "mac" let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*", "\\1", "") else let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\]\\).*", "\\1", "") endif if g:cmd == g:cmd_edited if MySys() == "linux" || MySys() == "mac" let g:cmd_edited = substitute(g:cmd, "\\(.*\[/\]\\).*/", "\\1", "") else let g:cmd_edited = substitute(g:cmd, "\\(.*\[\\\\\]\\).*\[\\\\\]", "\\1", "") endif endif return g:cmd_edited endfunc func! CurrentFileDir(cmd) return a:cmd . " " . expand("%:p:h") . "/" endfunc """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Moving around, tabs, windows and buffers """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" map :noh " Close the current buffer map bd :Bclose " Close all the buffers map ba :1,300 bd! " Smart way to move btw. windows map j map k map h map l " Use the arrows to something usefull map :bn map :bp map :tabnext map :tabprevious " Tab configuration map tn :tabnew map te :tabedit map tc :tabclose map tm :tabmove " When pressing cd switch to the directory of the open buffer map cd :cd %:p:h 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 " Specify the behavior when switching between buffers try set switchbuf=usetab set stal=2 catch endtry """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Parenthesis/bracket expanding """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" vnoremap $1 `>a)` vnoremap $2 `>a]` vnoremap $3 `>a}` vnoremap $$ `>a"` vnoremap $q `>a'` vnoremap $e `>a"` " Map auto complete of (, ", ', [ inoremap $1 ()i inoremap $2 []i inoremap $3 {}i inoremap $4 {o}O inoremap $q ''i inoremap $e ""i inoremap $t <>i """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => General Abbrevs """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" inoremap `now =strftime("%d/%m/%y %H:%M:%S") inoremap `fn =expand("%:t:r") """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Editing mappings """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "Remap VIM 0 map 0 ^ "Move a line of text using ALT+[jk] or Comamnd+[jk] on mac nmap mz:m+`z nmap mz:m-2`z vmap :m'>+`mzgv`yo`z vmap :m'<-2`>my` Cope for quickfix window """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " Do :help cope if you are unsure what cope is. It's super useful! nmap cc :cclose nmap co :copen map cn :cn map cp :cp """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Spell checking """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " "Pressing ,ss will toggle and untoggle spell checking map ss :setlocal spell! " " "Shortcuts using map sn ]s map sp [s map sa zg map s? z= """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => MISC """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " sudo write this cmap W! w !sudo tee % >/dev/null " Fast saving nmap w :w! " Quit window on q nnoremap q :q " Paste from clipboard map p "+gP " Copy to clipboard vmap y "+y " Clip to clipboard vmap d "+d " Replace a word with yanked text vmap S "_d"0P " Remove trailing whitespace on S nnoremap tt :%s/\s\+$// " Compressing empty lines nnoremap cs :%s/^\n\+/\r/ " auto format code nnoremap ff gg=G map gm :call cursor(0, virtcol('$')/2) " Remove the Windows ^M - when the encodings gets messed up noremap m mmHmt:%s///ge'tzt'm " json map :%!python -m json.tool " redir message function! TabMessage(cmd) redir => message silent execute a:cmd redir END tabnew silent put=message set nomodified endfunction command! -nargs=+ -complete=command TabMessage call TabMessage() " remember last edit location autocmd BufReadPost * \ if line("'\"")>0&&line("'\"")<=line("$") | \ exe "normal g'\"" | \ endif nnoremap :silent! let &guifont = substitute( \ &guifont, \ ':h\zs\d\+', \ '\=eval(submatch(0)+1)', \ 'g') nnoremap :silent! let &guifont = substitute( \ &guifont, \ ':h\zs\d\+', \ '\=eval(submatch(0)-1)', \ 'g') 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 =~ '\ ' . arg3 . eq endfunction """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Config NerdTree Plugin """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" map nd :NERDTreeToggle " Open NerdTree """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Config buffer explore Plugin """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" let g:bufExplorerDefaultHelp=0 " Do not show default help. let g:bufExplorerShowRelativePath=1 " Show relative paths. let g:bufExplorerSortBy='mru' " Sort by most recently used. let g:bufExplorerSplitRight=0 " Split left. let g:bufExplorerSplitVertical=1 " Split vertically. let g:bufExplorerSplitVertSize = 30 " Split width let g:bufExplorerUseCurrentWindow=1 " Open in new window. autocmd BufWinEnter \[Buf\ List\] setl nonumber map o :BufExplorer """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Config vim latex Plugin """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " tex target autocmd FileType tex TTarget pdf " 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' """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" " => Config neoComplete Plugin """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" "Note: This option must set it in .vimrc(_vimrc). NOT IN .gvimrc(_gvimrc)! " Disable AutoComplPop. let g:acp_enableAtStartup = 0 " Use neocomplete. let g:neocomplete#enable_at_startup = 1 " Use smartcase. let g:neocomplete#enable_smart_case = 1 " Set minimum syntax keyword length. let g:neocomplete#sources#syntax#min_keyword_length = 3 let g:neocomplete#lock_buffer_name_pattern = '\*ku\*' " Define dictionary. let g:neocomplete#sources#dictionary#dictionaries = { \ 'default' : '', \ 'vimshell' : $HOME.'/.vimshell_hist', \ 'scheme' : $HOME.'/.gosh_completions' \ } " Define keyword. if !exists('g:neocomplete#keyword_patterns') let g:neocomplete#keyword_patterns = {} endif let g:neocomplete#keyword_patterns['default'] = '\h\w*' " Plugin key-mappings. inoremap neocomplete#undo_completion() inoremap neocomplete#complete_common_string() " Recommended key-mappings. " : close popup and save indent. inoremap =my_cr_function() function! s:my_cr_function() return neocomplete#close_popup() . "\" " For no inserting key. "return pumvisible() ? neocomplete#close_popup() : "\" endfunction " : completion. inoremap pumvisible() ? "\" : "\" " , : close popup and delete backword char. inoremap neocomplete#smart_close_popup()."\" inoremap neocomplete#smart_close_popup()."\" inoremap neocomplete#close_popup() inoremap neocomplete#cancel_popup() " Close popup by . "inoremap pumvisible() ? neocomplete#close_popup() : "\" " For cursor moving in insert mode(Not recommended) "inoremap neocomplete#close_popup() . "\" "inoremap neocomplete#close_popup() . "\" "inoremap neocomplete#close_popup() . "\" "inoremap neocomplete#close_popup() . "\" " Or set this. "let g:neocomplete#enable_cursor_hold_i = 1 " Or set this. "let g:neocomplete#enable_insert_char_pre = 1 " AutoComplPop like behavior. "let g:neocomplete#enable_auto_select = 1 " Shell like behavior(not recommended). "set completeopt+=longest "let g:neocomplete#enable_auto_select = 1 "let g:neocomplete#disable_auto_complete = 1 "inoremap pumvisible() ? "\" : "\\" " Enable omni completion. autocmd FileType css setlocal omnifunc=csscomplete#CompleteCSS 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 " Enable heavy omni completion. if !exists('g:neocomplete#sources#omni#input_patterns') let g:neocomplete#sources#omni#input_patterns = {} endif "let g:neocomplete#sources#omni#input_patterns.php = '[^. \t]->\h\w*\|\h\w*::' "let g:neocomplete#sources#omni#input_patterns.c = '[^.[:digit:] *\t]\%(\.\|->\)' "let g:neocomplete#sources#omni#input_patterns.cpp = '[^.[:digit:] *\t]\%(\.\|->\)\|\h\w*::' " For perlomni.vim setting. " https://github.com/c9s/perlomni.vim let g:neocomplete#sources#omni#input_patterns.perl = '\h\w*->\h\w*\|\h\w*::'