set nocompatible source $VIMRUNTIME/vimrc_example.vim source $VIMRUNTIME/mswin.vim behave mswin set nocompatible " 去除VI一致性,必須 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 set guifont=Courier\ 10\ Pitch\ Regular\ 15 set nu set lines=35 columns=118 " An example for a vimrc file. " " Maintainer: Bram Moolenaar <Bram@vim.org> " Last change: 2002 Sep 19 " " To use it, copy it to " for Unix and OS/2: ~/.vimrc " for Amiga: s:.vimrc " for MS-DOS and Win32: $VIM\_vimrc " for OpenVMS: sys$login:.vimrc " When started as "evim", evim.vim will already have done these settings. if v:progname =~? "evim" finish endif " 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 if has("vms") set nobackup " do not keep a backup file, use versions instead else set backup " keep a backup file endif set history=50 " keep 50 lines of command line history set ruler " show the cursor position all the time set showcmd " display incomplete commands set incsearch " do incremental searching " For Win32 GUI: remove 't' flag from 'guioptions': no tearoff menu entries " let &guioptions = substitute(&guioptions, "t", "", "g") " Don't use Ex mode, use Q for formatting map Q gq " This is an alternative that also works in block mode, but the deleted " text is lost and it only works for putting the current register. "vnoremap p "_dp " 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 " Only do this part when compiled with support for autocommands. if has("autocmd") " Enable file type detection. " Use the default filetype settings, so that mail gets 'tw' set to 72, " 'cindent' is on in C files, etc. " Also load indent files, to automatically do language-dependent indenting. filetype plugin indent on " Put these in an autocmd group, so that we can delete them easily. augroup vimrcEx au! " For all text files set 'textwidth' to 78 characters. autocmd FileType text setlocal textwidth=78 " 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). autocmd BufReadPost * \ if line("'\"") > 0 && line("'\"") <= line("$") | \ exe "normal g`\"" | \ endif augroup END else set autoindent " always set autoindenting on endif " has("autocmd") set autoindent set sw=4 set tabstop=4 set noexpandtab set shiftwidth=4 set list abbr deb #define DEBUG cerr << "Call out: " << __func__ << "\t" << "Line: " << __LINE__ << "\t :" set listchars=tab:>\ abbr btf !astyle --style=ansi --indent=force-tab -c % colo zellner abbr inc #include<bits/stdc++.h> abbr rep #define repeat(a,b,c,g) for (int a=b,abck=(g>=0?1:-1);abck*(a)<=abck*(c);a+=g) abbr usi using namespace std; abbr frin freopen(".in","r",stdin); abbr frout freopen(".out","w",stdout); abbr fc fclose(stdin);fclose(stdout); abbr sc scanf abbr pr printf abbr ll long long " %F 完整文件路徑名 " %m 當前緩衝被修改標記 " %m 當前緩衝只讀標記 " %h 幫助緩衝標記 " %w 預覽緩衝標記 " %Y 文件類型 " %b ASCII值 " %B 十六進制值 " %l 行數 " %v 列數 " %p 當前行數佔總行數的的百分比 " %L 總行數 " %{...} 評估表達式的值,並用值代替 " %{"[fenc=".(&fenc==""?&enc:&fenc).((exists("+bomb") && &bomb)?"+":"")."]"} 顯示文件編碼 " %{&ff} 顯示文件類型 " 設置 laststatus = 0 ,不顯式狀態行 " 設置 laststatus = 1 ,僅當窗口多於 "------------------------------------------------------------------------------ " < 判斷操做系統是不是 Windows 仍是 Linux > "------------------------------------------------------------------------------ if(has("win32") || has("win64") || has("win95") || has("win16")) let g:iswindows = 1 else let g:iswindows = 0 endif "------------------------------------------------------------------------------ " < 判斷是終端仍是 Gvim > "------------------------------------------------------------------------------ if has("gui_running") let g:isGUI = 1 else let g:isGUI = 0 endif set cursorcolumn set cursorline highlight CursorLine cterm=NONE ctermbg=lightgrey guibg=NONE guifg=NONE highlight CursorColumn cterm=NONE ctermbg=lightgrey guibg=NONE guifg=NONE "------------------------------------------------------------------------------ " < 編譯、鏈接、運行配置 > "------------------------------------------------------------------------------ " F9 一鍵保存、編譯、鏈接存並運行 map <F9> :call Run()<CR> imap <F9> <ESC>:call Run()<CR> " Ctrl + F9 一鍵保存並編譯 map <c-F9> :call Compile()<CR> imap <c-F9> <ESC>:call Compile()<CR> " Ctrl + F10 一鍵保存並鏈接 map <c-F10> :call Link()<CR> imap <c-F10> <ESC>:call Link()<CR> let s:LastShellReturn_C = 0 let s:LastShellReturn_L = 0 let s:ShowWarning = 1 let s:Obj_Extension = '.o' let s:Exe_Extension = '.exe' let s:Sou_Error = 0 let s:windows_CFlags = 'gcc\ -fexec-charset=gbk\ -g\ -O0\ -c\ %\ -Wl,--stack=size -o\ %<.o' let s:linux_CFlags = 'gcc\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o' let s:windows_CPPFlags = 'g++\ -std=c++11\ -fexec-charset=gbk\ -g\ -Wl,--stack=16777216\ -O0\ -c\ %\ -o\ %<.o' let s:linux_CPPFlags = 'g++\ -std=c++11\ -Wall\ -g\ -O0\ -c\ %\ -o\ %<.o' func! Compile() exe ":ccl" exe ":update" if expand("%:e") == "c" || expand("%:e") == "cpp" || expand("%:e") == "cxx" let s:Sou_Error = 0 let s:LastShellReturn_C = 0 let Sou = expand("%:p") let Obj = expand("%:p:r").s:Obj_Extension let Obj_Name = expand("%:p:t:r").s:Obj_Extension let v:statusmsg = '' if !filereadable(Obj) || (filereadable(Obj) && (getftime(Obj) < getftime(Sou))) redraw! if expand("%:e") == "c" if g:iswindows exe ":setlocal makeprg=".s:windows_CFlags else exe ":setlocal makeprg=".s:linux_CFlags endif echohl WarningMsg | echo " compiling..." silent make elseif expand("%:e") == "cpp" || expand("%:e") == "cxx" if g:iswindows exe ":setlocal makeprg=".s:windows_CPPFlags else exe ":setlocal makeprg=".s:linux_CPPFlags endif echohl WarningMsg | echo " compiling..." silent make endif redraw! if v:shell_error != 0 let s:LastShellReturn_C = v:shell_error endif if g:iswindows if s:LastShellReturn_C != 0 exe ":bo cope" echohl WarningMsg | echo " compilation failed" else if s:ShowWarning exe ":bo cw" endif echohl WarningMsg | echo " compilation successful" endif else if empty(v:statusmsg) echohl WarningMsg | echo " compilation successful" else exe ":bo cope" endif endif else echohl WarningMsg | echo ""Obj_Name"is up to date" endif else let s:Sou_Error = 1 echohl WarningMsg | echo " please choose the correct source file" endif exe ":setlocal makeprg=make" endfunc func! Link() call Compile() if s:Sou_Error || s:LastShellReturn_C != 0 return endif let s:LastShellReturn_L = 0 let Sou = expand("%:p") let Obj = expand("%:p:r").s:Obj_Extension if g:iswindows let Exe = expand("%:p:r").s:Exe_Extension let Exe_Name = expand("%:p:t:r").s:Exe_Extension else let Exe = expand("%:p:r") let Exe_Name = expand("%:p:t:r") endif let v:statusmsg = '' if filereadable(Obj) && (getftime(Obj) >= getftime(Sou)) redraw! if !executable(Exe) || (executable(Exe) && getftime(Exe) < getftime(Obj)) if expand("%:e") == "c" setlocal makeprg=gcc\ -o\ %<\ %<.o echohl WarningMsg | echo " linking..." silent make elseif expand("%:e") == "cpp" || expand("%:e") == "cxx" setlocal makeprg=g++\ -o\ %<\ %<.o echohl WarningMsg | echo " linking..." silent make endif redraw! if v:shell_error != 0 let s:LastShellReturn_L = v:shell_error endif if g:iswindows if s:LastShellReturn_L != 0 exe ":bo cope" echohl WarningMsg | echo " linking failed" else if s:ShowWarning exe ":bo cw" endif echohl WarningMsg | echo " linking successful" endif else if empty(v:statusmsg) echohl WarningMsg | echo " linking successful" else exe ":bo cope" endif endif else echohl WarningMsg | echo ""Exe_Name"is up to date" endif endif setlocal makeprg=make endfunc func! Run() let s:ShowWarning = 0 call Link() let s:ShowWarning = 1 if s:Sou_Error || s:LastShellReturn_C != 0 || s:LastShellReturn_L != 0 return endif let Sou = expand("%:p") let Obj = expand("%:p:r").s:Obj_Extension if g:iswindows let Exe = expand("%:p:r").s:Exe_Extension else let Exe = expand("%:p:r") endif if executable(Exe) && getftime(Exe) >= getftime(Obj) && getftime(Obj) >= getftime(Sou) redraw! echohl WarningMsg | echo " running..." if g:iswindows exe ":!%<.exe" else if g:isGUI exe ":!gnome-terminal -e ./%<" else exe ":!./%<" endif endif redraw! echohl WarningMsg | echo " running finish" endif endfunc