<code><code><code> set nocompatible " 關閉 vi 相容模式 syntax on " 自動文法高亮 set number " 顯示行号 set ruler " 打開狀态欄标尺 set shiftwidth=4 " 設定 << 和 >> 指令移動時的寬度為 4 set textwidth=80 " 設定每行80個字元自動換行 set fo+=mm " 中文40個字換行 set autoread " 當檔案被外部編輯器更改後,自動載入 set autoindent " 繼承前一行的縮進方式,特别适用于多行注釋 set softtabstop=4 " 使得按倒退鍵時可以一次删掉 4 個空格 set tabstop=4 " 設定 tab 長度為 4 set nobackup " 覆寫檔案時不備份 set autochdir " 自動切換目前目錄為目前檔案所在的目錄 filetype plugin indent on " 開啟插件 set backupcopy=yes " 設定備份時的行為為覆寫 set ignorecase smartcase " 搜尋時忽略大小寫,但在有一個或以上大寫字母時仍保持對大小寫敏感 set nowrapscan " 禁止在搜尋到檔案兩端時重新搜尋 set incsearch " 輸入搜尋内容時就顯示搜尋結果 set hlsearch " 搜尋時高亮顯示被找到的文本 set noerrorbells " 關閉錯誤資訊響鈴 set history=80 " 記錄曆史指令行數 set iskeyword+=_,$,@,%,#,- " 帶有_,$,@,%,#,-這些字元的串,不被換行分割 set mouse=a " 設定滑鼠一直可用 set shortmess=ati " 啟動的時候不顯示那個援助索馬裡兒童的提示 set novisualbell " 關閉使用可視響鈴代替呼叫 set t_vb= " 置空錯誤鈴聲的終端代碼 set noswapfile " 禁用swap檔案 " set showmatch " 插入括号時,短暫地跳轉到比對的對應括号 " set matchtime=2 " 短暫跳轉到比對括号的時間 set magic " 設定魔術 set hidden " 允許在有未儲存的修改時切換緩沖區,此時的修改由 vim 負責儲存 set smartindent " 開啟新行時使用智能自動縮進 set backspace=indent,eol,start " 不設定在插入狀态無法用倒退鍵和 delete 鍵删除回車符 set cmdheight=1 " 設定指令行的行數為 1 set laststatus=2 " 顯示狀态欄 (預設值為 1, 無法顯示狀态欄) set statusline=\ %<%f[%1*%m%*%n%r%h]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%l%)\ " 設定在狀态行顯示的資訊 set foldenable " 開始折疊 set foldmethod=syntax " 設定文法折疊 set foldcolumn=0 " 設定折疊區域的寬度 setlocal foldlevel=1 " 設定折疊層數為 " set foldclose=all " 設定為自動關閉折疊 " nnoremap <space> @=((foldclosed(line(‘.‘)) < 0) ? ‘zc‘ : ‘zo‘)<cr> " 用空格鍵來開關折疊 colorscheme desert " 設定配色方案 if has("gui_running") "au guienter * simalt ~x " 視窗啟動時自動最大化 "set guioptions-=m " 隐藏菜單欄 set guioptions-=t " 隐藏工具欄 set guioptions-=l " 隐藏左側滾動條 set guioptions-=r " 隐藏右側滾動條 set guioptions-=b " 隐藏底部滾動條 "set showtabline=0 " 隐藏tab欄 "set cursorline " 突出顯示目前行 colorscheme default " 設定配色方案 winpos 250 80 "視窗位置 set lines=30 columns=100 "視窗大小 set textwidth=80 endif "傳回作業系統類型(windows, linux等) function! mysys() if has("win16") || has("win32") || has("win64") || has("win95") return "windows" elseif has("unix") return "linux" endif endfunction " 使用者目錄變量$vimfiles <b>if</b> mysys() == "windows" let $vimfiles = $vim.‘/vimfiles‘ elseif mysys() == "linux" let $vimfiles = $home.‘/.vim‘ endif " 設定doc文檔目錄 let helptags=$vimfiles.‘/doc‘ "設定中文幫助文檔 <b>if</b> version >= 603 set helplang=cn endif " 設定字型 以及中文支援 if has("win32") || has("win64") set guifont=courier_new:h10:cansi:b elseif has("unix") set guifont=courier\ 10\ pitch\ 10 endif " 配置多語言環境 <b>if</b> has("multi_byte") " utf-8 編碼 set encoding=utf-8 set termencoding=utf-8 set formatoptions+=mm set fencs=utf-8,gbk if v:lang =~? ‘^\(zh\)\|\(ja\)\|\(ko\)‘ set ambiwidth=double endif if has("win32") source $vimruntime/delmenu.vim source $vimruntime/menu.vim language messages zh_cn.utf-8 endif else echoerr "sorry, this version of (g)vim was not compiled with +multi_byte" endif " buffers操作快捷方式! nnoremap <c-return> :bnext<cr> nnoremap <c-s-return> :bprevious<cr> " tab操作快捷方式! nnoremap <c-tab> :tabnext<cr> nnoremap <c-s-tab> :tabprev<cr> "視窗分割時,進行切換的按鍵熱鍵需要連接配接兩次,比如從下方視窗移動 "光标到上方視窗,需要<c-w><c-w>k,非常麻煩,現在重映射為<c-k>,切換的 "時候會變得非常友善. nnoremap <c-h> <c-w>h nnoremap <c-j> <c-w>j nnoremap <c-k> <c-w>k nnoremap <c-l> <c-w>l "一些不錯的映射轉換文法(如果在一個檔案中混合了不同語言時有用) nnoremap <leader>1 :set filetype=xhtml<cr> nnoremap <leader>2 :set filetype=css<cr> nnoremap <leader>3 :set filetype=javascript<cr> nnoremap <leader>4 :set filetype=php<cr> set fileformats=unix,dos,mac " nmap <leader>fd :se fileformat=dos<cr> " nmap <leader>fu :se fileformat=unix<cr> " use ctrl+[l|n|p|cc] to list|next|previous|jump to count the result " map <c-x>l <esc>:cl<cr> " map <c-x>n <esc>:cn<cr> " map <c-x>p <esc>:cp<cr> " map <c-x>c <esc>:cc<cr> " 讓 tohtml 産生有 css 文法的 html " syntax/2html.vim,可以用:runtime! syntax/2html.vim let html_use_css=0 " python 檔案的一般設定,比如不要 tab 等 autocmd filetype python set tabstop=4 shiftwidth=4 expandtab autocmd filetype python map <f12> :!python %<cr> " 選中狀态下 ctrl+c 複制 vmap <c-c> "+y " 打開javascript折疊 let b:javascript_fold=1 " 打開javascript對dom、html和css的支援 let javascript_enable_domhtmlcss=1 "----------------------------------------------------------------- ""括号自動補全 "----------------------------------------------------------------- :inoremap " ""<esc>i :inoremap ( ()<esc>i :inoremap ) <c-r>=closepair(‘)‘)<cr> :inoremap { {}<esc>i :inoremap } <c-r>=closepair(‘}‘)<cr> :inoremap [ []<esc>i :inoremap ] <c-r>=closepair(‘]‘)<cr> ":inoremap < <><esc>i ":inoremap > <c-r>=closepair(‘>‘)<cr> function closepair(char) <b>if</b> getline(‘.‘)[col(‘.‘) - 1] == a:char return "\<right>" <b>else</b> return a:char endif endf "----------------------------------------------------------------- " plugin – checksyntax.vim javascript常見文法錯誤檢查 " 預設快捷方式為 f5 "----------------------------------------------------------------- let g:checksyntax_auto = 0 " 不自動檢查 "----------------------------------------------------------------- "plugin - bashsupport "----------------------------------------------------------------- let g:bash_author = ‘wlxxsj‘ let g:bash_email = ‘[email protected]‘ let g:bash_organization = ‘open source corporation‘ "----------------------------------------------------------------- " plugin - nerd_tree.vim 以樹狀方式浏覽系統中的檔案和目錄 " :erdtree 打開nerd_tree :nerdtreeclose 關閉nerd_tree " o 打開關閉檔案或者目錄 t 在标簽頁中打開 " t 在背景标簽頁中打開 ! 執行此檔案 " p 到上層目錄 p 到根目錄 " k 到第一個節點 j 到最後一個節點 " u 打開上層目錄 m 顯示檔案系統菜單(添加、删除、移動操作) " r 遞歸重新整理目前目錄 r 遞歸重新整理目前根目錄 "----------------------------------------------------------------- " f3 nerdtree 切換 map <f3> :nerdtreetoggle<cr> imap <f3> <esc>:nerdtreetoggle<cr> " 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 autocmd filetype java setlocal omnifunc=javacomplete#complete autocmd filetype ruby setlocal omnifunc=rubycomplete#complete " ======= 編譯 && 運作 ======= " " 編譯c源檔案 func! compilegcc() exec "w" let compilecmd="!gcc -wall -pedantic -std=c99 " let compileflag="-o %<" exec compilecmd." % ".compileflag endfunc " 編譯c++源檔案 func! compilecpp() exec "w" let compilecmd="!g++ -wall -pedantic -std=c++98 " let compileflag="-o %<" exec compilecmd." % ".compileflag endfunc " 編譯java源檔案 func! compilejava() exec "w" exec "!javac %" endfunc " 根據檔案類型自動選擇相應的編譯函數 func! compilecode() exec "w" <b>if</b> &filetype == "c" exec "call compilegcc()" elseif &filetype == "cpp" exec "call compilecpp()" elseif &filetype == "java" exec "call compilejava()" elseif &filetype == "lua" exec "!lua %<.lua" elseif &filetype == "perl" exec "!perl %<.pl" elseif &filetype == "python" exec "!python %<.py" elseif &filetype == "ruby" exec "!ruby %<.rb" endif endfunc " 運作可執行檔案 func! runresult() exec "w" if &filetype == "c" exec "! %<" elseif &filetype == "cpp" exec "! %<" elseif &filetype == "java" exec "!java %<" elseif &filetype == "lua" exec "!lua %<.lua" elseif &filetype == "perl" exec "!perl %<.pl" elseif &filetype == "python" exec "!python %<.py" elseif &filetype == "ruby" exec "!ruby %<.rb" endif endfunc </code></code></code>
