"是否兼容VI,compatible為兼容,nocompatible為不完全兼容 "如果設置為compatible,則tab將不會變成空格 set nocompatible "設置鼠標運行模式為WINDOWS模式 behave mswin "設置菜單語言 set encoding=chinese set langmenu=zh_CN.UTF-8 " ========= " 功能函數 " ========= " 獲取當前目錄 func GetPWD() return substitute(getcwd(), "", "", "g") endf " ===================== " 多語言環境 " 默認為 UTF-8 編碼 " ===================== if has("multi_byte") set encoding=utf-8 " English messages only "language messages zh_CN.utf-8 if has('win32') language english let &termencoding=&encoding endif set fencs=utf-8,gbk,chinese,latin1 set formatoptions+=mM set nobomb " 不使用 Unicode 簽名 if v:lang =~? '^\(zh\)\|\(ja\)\|\(ko\)' set ambiwidth=double endif else echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte" endif " ========= " 環境配置 " ========= " 保留歷史記錄 set history=400 " 命令行於狀態行 set ch=1 set stl=\ [File]\ %F%m%r%h%y[%{&fileformat},%{&fileencoding}]\ %w\ \ [PWD]\ %r%{GetPWD()}%h\ %=\ [Line]\ %l,%c\ %=\ %P set ls=2 " 始終顯示狀態行 " 制表符 set tabstop=4 "把tab轉成空格 "set expandtab set smarttab set shiftwidth=4 set softtabstop=4 " 狀態欄顯示目前所執行的指令 set showcmd " 行控制 set linebreak set nocompatible set textwidth=80 set wrap " 行號和標尺 set number set ruler set rulerformat=%15(%c%V\ %p%%%) " 控制台響鈴 :set noerrorbells :set novisualbell :set t_vb= "close visual bell " 插入模式下使用 <BS>、<Del> <C-W> <C-U> set backspace=indent,eol,start " 標簽頁 set tabpagemax=20 set showtabline=2 " 縮進 智能對齊方式 set autoindent set smartindent " 自動重新讀入 set autoread "代碼折疊 "設置折疊模式 set foldcolumn=4 "光標遇到折疊,折疊就打開 "set foldopen=all "移開折疊時自動關閉折疊 "set foldclose=all "zf zo zc zd zr zm zR zM zn zi zN "依縮進折疊 " manual 手工定義折疊 " indent 更多的縮進表示更高級別的折疊 " expr 用表達式來定義折疊 " syntax 用語法高亮來定義折疊 " diff 對沒有更改的文本進行折疊 " marker 對文中的標志折疊 set foldmethod=syntax "啟動時不要自動折疊代碼 set foldlevel=100 "依標記折疊 set foldmethod=marker "語法高亮 syntax enable syntax on "設置配色 set guifont=Courier\ New:h12 colorscheme desert "設定文件瀏覽器目錄為當前目錄 set bsdir=buffer " 自動切換到文件當前目錄 set autochdir "在查找時忽略大小寫 set ignorecase set incsearch set hlsearch "設置命令行的高度 set cmdheight=2 "顯示匹配的括號 set showmatch "增強模式中的命令行自動完成操作 set wildmenu "使PHP識別EOT字符串 hi link phpheredoc string "php語法折疊 let php_folding = 1 "允許在有未保存的修改時切換緩沖區 set hidden "實現全能補全功能,需要打開文件類型檢測 "filetype plugin indent on "打開vim的文件類型自動檢測功能 "filetype on "保存文件的格式順序 set fileformats=dos,unix "置粘貼模式,這樣粘貼過來的程序代碼就不會錯位了。 set paste "在所有模式下都允許使用鼠標,還可以是n,v,i,c等 set mouse=a " 恢復上次文件打開位置 set viminfo='10,\"100,:20,%,n~/.viminfo au BufReadPost * if line("'\"") > 0|if line("'\"") <= line("$")|exe("norm '\"")|else|exe "norm $"|endif|endif "取得光標處的匹配 function! GetPatternAtCursor(pat) let col = col('.') - 1 let line = getline('.') let ebeg = -1 let cont = match(line, a:pat, 0) while (ebeg >= 0 || (0 <= cont) && (cont <= col)) let contn = matchend(line, a:pat, cont) if (cont <= col) && (col < contn) let ebeg = match(line, a:pat, cont) let elen = contn - ebeg break else let cont = match(line, a:pat, contn) endif endwh if ebeg >= 0 return strpart(line, ebeg, elen) else return "" endif endfunction " ========= " 圖形界面 " ========= if has('gui_running') " 只顯示菜單 set guioptions=mcr " 高亮光標所在的行 set cursorline " 編輯器配色 colorscheme desert "colorscheme zenburn "colorscheme dusk if has("win32") " Windows 兼容配置 source $VIMRUNTIME/vimrc_example.vim source $VIMRUNTIME/mswin.vim "設置鼠標運行模式為WINDOWS模式 behave mswin " f11 最大化 map <f11> :call libcallnr('fullscreen.dll', 'ToggleFullScreen', 0)<cr> " 字體配置 exec 'set guifont='.iconv('Courier_New', &enc, 'gbk').':h12:cANSI' "exec 'set guifontwide='.iconv('微軟雅黑', &enc, 'gbk').':h12' endif if has("unix") && !has('gui_macvim') set guifont=Courier\ 10\ Pitch\ 11 set guifontwide=YaHei\ Consolas\ Hybrid\ 11 endif if has("mac") || has("gui_macvim") set guifont=Courier\ New:h16.00 "set guifontwide=YaHei\ Consolas\ Hybrid:h16.00 "set guifont=Monaco:h16 "set guifont=Droid\ Sans\ Mono:h14 set guifontwide=YouYuan:h14 if has("gui_macvim") "set transparency=4 set lines=200 columns=142 let s:lines=&lines let s:columns=&columns func! FullScreenEnter() set lines=999 columns=999 set fu endf func! FullScreenLeave() let &lines=s:lines let &columns=s:columns set nofu endf func! FullScreenToggle() if &fullscreen call FullScreenLeave() else call FullScreenEnter() endif endf endif endif endif " Under the Mac(MacVim) if has("gui_macvim") " Mac 下,按 \ff 切換全屏 map <Leader><Leader> :call FullScreenToggle()<cr> " Set input method off set imdisable " Set QuickTemplatePath let g:QuickTemplatePath = $HOME.'/.vim/templates/' lcd ~/Desktop/ " 自動切換到文件當前目錄 set autochdir " Set QuickTemplatePath let g:QuickTemplatePath = $HOME.'/.vim/templates/' endif "設置VIM狀態欄 set laststatus=2 "顯示狀態欄(默認值為1, 無法顯示狀態欄) set statusline= "[%F]%y%r%m%*%=[Line:%l/%L,Column:%c][%p%%] set statusline+=%2*%-3.3n%0*\ " buffer number set statusline+=%f\ " file name set statusline+=%h%1*%m%r%w%0* " flag set statusline+=[ if v:version >= 600 set statusline+=%{strlen(&ft)?&ft:'none'}, " filetype set statusline+=%{&fileencoding}, " encoding endif set statusline+=%{&fileformat}] " file format set statusline+=%= " right align "set statusline+=%2*0x%-8B\ " current char set statusline+=0x%-8B\ " current char set statusline+=%-14.(%l,%c%V%)\ %<%P " offset if filereadable(expand("~/vimfiles/plugin/vimbuddy.vim")) set statusline+=\ %{VimBuddy()} " vim buddy endif " ========= " 插件 " ========= filetype plugin indent on "html自動輸入匹配標簽,輸入>之后自動完成匹配標簽 au FileType xhtml,xml so ~/.vim/plugin/html_autoclosetag.vim "Auto completion using the TAB key " 自動補全括號,引號 "This function determines, wether we are on "the start of the line text(then tab indents) "or if we want to try auto completion function! InsertTabWrapper() let col=col('.')-1 if !col || getline('.')[col-1] !~ '\k' return "\<TAB>" else return "\<C-N>" endif endfunction "Remap the tab key to select action with InsertTabWrapper inoremap <TAB> <C-R>=InsertTabWrapper()<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> :inoremap < <><ESC>i :inoremap > <c-r>=ClosePair('>')<CR> :inoremap " ""<ESC>i :inoremap ' ''<ESC>i function! ClosePair(char) if getline('.')[col('.') - 1] == a:char return "\<Right>" else return a:char endif endf " ========= " AutoCmd " ========= if has("autocmd") filetype plugin indent on " 括號自動補全 func! AutoClose() :inoremap ( ()<ESC>i ":inoremap " ""<ESC>i ":inoremap ' ''<ESC>i :inoremap { {}<ESC>i :inoremap [ []<ESC>i :inoremap ) <c-r>=ClosePair(')')<CR> :inoremap } <c-r>=ClosePair('}')<CR> :inoremap ] <c-r>=ClosePair(']')<CR> endf func! ClosePair(char) if getline('.')[col('.') - 1] == a:char return "\<Right>" else return a:char endif endf augroup vimrcEx au! autocmd FileType text setlocal textwidth=80 autocmd BufReadPost * \ if line("'\"") > 0 && line("'\"") <= line("$") | \ exe "normal g`\"" | \ endif augroup END "auto close quotation marks for PHP, Javascript, etc, file au FileType php,c,python,javascript exe AutoClose() " Auto Check Syntax au BufWritePost,FileWritePost *.js,*.php call CheckSyntax(1) " JavaScript 語法高亮 au FileType html,javascript let g:javascript_enable_domhtmlcss = 1 " 給 Javascript 文件添加 Dict if has('gui_macvim') || has('unix') au FileType javascript setlocal dict+=~/.vim/dict/javascript.dict else au FileType javascript setlocal dict+=$VIM/vimfiles/dict/javascript.dict endif " 格式化 JavaScript 文件 "au FileType javascript map <f12> :call g:Jsbeautify()<cr> au FileType javascript set omnifunc=javascriptcomplete#CompleteJS " 給 CSS 文件添加 Dict if has('gui_macvim') || has('unix') au FileType css setlocal dict+=~/.vim/dict/css.dict else au FileType css setlocal dict+=$VIM/vimfiles/dict/css.dict endif " 增加 ActionScript 語法支持 au BufNewFile,BufRead *.as setf actionscript " 自動最大化窗口 if has('gui_running') if has("win32") au GUIEnter * simalt ~x "elseif has("unix") "au GUIEnter * winpos 0 0 "set lines=999 columns=999 endif endif endif let g:SuperTabDefaultCompletionType = '<c-x><c-u>' let g:SuperTabDefaultCompletionType = "context" let g:SuperTabRetainCompletionType=2 " Disable AutoComplPop. let g:acp_enableAtStartup = 0 " Use neocomplcache. let g:neocomplcache_enable_at_startup = 1 " Use smartcase. let g:neocomplcache_enable_smart_case = 1 " Use camel case completion. let g:neocomplcache_enable_camel_case_completion = 1 " Use underbar completion. let g:neocomplcache_enable_underbar_completion = 1 " Set minimum syntax keyword length. let g:neocomplcache_min_syntax_length = 3 let g:neocomplcache_lock_buffer_name_pattern = '\*ku\*' " Define dictionary. let g:neocomplcache_dictionary_filetype_lists = { \ 'default' : '', \ 'css' : '~/.vim/dist/css.dic', \ 'php' : '~/.vim/dict/php.dic', \ 'javascript' : '~/.vim/dict/javascript.dic', \ 'vimshell' : $HOME.'/.vimshell_hist', \ 'scheme' : $HOME.'/.gosh_completions' \ } let g:neocomplcache_snippets_dir="~/.vim/snippets" inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>" inoremap <expr><S-TAB> pumvisible() ? "\<C-p>" : "\<TAB>" " Define keyword. if !exists('g:neocomplcache_keyword_patterns') let g:neocomplcache_keyword_patterns = {} endif let g:neocomplcache_keyword_patterns['default'] = '\h\w*' " Plugin key-mappings. imap <C-k> <Plug>(neocomplcache_snippets_expand) smap <C-k> <Plug>(neocomplcache_snippets_expand) inoremap <expr><C-g> neocomplcache#undo_completion() inoremap <expr><C-l> neocomplcache#complete_common_string() " Recommended key-mappings. " <CR>: close popup and save indent. inoremap <expr><CR> neocomplcache#smart_close_popup() . "\<CR>" " <TAB>: completion. inoremap <expr><TAB> pumvisible() ? "\<C-n>" : "\<TAB>" " <C-h>, <BS>: close popup and delete backword char. inoremap <expr><C-h> neocomplcache#smart_close_popup()."\<C-h>" inoremap <expr><BS> neocomplcache#smart_close_popup()."\<C-h>" inoremap <expr><C-y> neocomplcache#close_popup() inoremap <expr><C-e> neocomplcache#cancel_popup() " AutoComplPop like behavior. "let g:neocomplcache_enable_auto_select = 1 " Shell like behavior(not recommended). "set completeopt+=longest let g:neocomplcache_enable_auto_select = 1 let g:neocomplcache_disable_auto_complete = 1 inoremap <expr><TAB> pumvisible() ? "\<Down>" : "\<TAB>" inoremap <expr><CR> neocomplcache#smart_close_popup() . "\<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 " Enable heavy omni completion. if !exists('g:neocomplcache_omni_patterns') let g:neocomplcache_omni_patterns = {} endif let g:neocomplcache_omni_patterns.ruby = '[^. *\t]\.\w*\|\h\w*::' "autocmd FileType ruby setlocal omnifunc=rubycomplete#Complete let g:neocomplcache_omni_patterns.php = '[^. \t]->\h\w*\|\h\w*::' let g:neocomplcache_omni_patterns.c = '\%(\.\|->\)\h\w*' let g:neocomplcache_omni_patterns.cpp = '\h\w*\%(\.\|->\)\h\w*\|\h\w*::' """""""""""""""""""""""""""""" " Tag list (ctags) """""""""""""""""""""""""""""" if has("win32") "設定windows系統中ctags程序的位置 let Tlist_Ctags_Cmd = 'ctags' elseif has("linux") "設定linux系統中ctags程序的位置 let Tlist_Ctags_Cmd = '/usr/bin/ctags' endif let Tlist_Show_One_File = 1 "不同時顯示多個文件的tag,只顯示當前文件的 let Tlist_Exit_OnlyWindow = 1 "如果taglist窗口是最后一個窗口,則退出vim let Tlist_Use_Right_Window = 1 "在右側窗口中顯示taglist窗口 " ========= " 快捷鍵 " ========= map cal :Calendar<cr> map cse :ColorSchemeExplorer "==== F3 NERDTree 切換 ==== let NERDTreeWinSize=22 "map ntree :NERDTree <cr> "map nk :NERDTreeClose <cr> "map <leader>n :NERDTreeToggle<cr> map <F3> :NERDTreeToggle<CR> imap <F3> <ESC>:NERDTreeToggle<CR> "==== F4 Tag list 切換 ==== map <silent> <F4> :TlistToggle<cr> " 標簽相關的快捷鍵 Ctrl map tn :tabnext<cr> map tp :tabprevious<cr> map tc :tabclose<cr> map <C-t> :tabnew<cr> map <C-p> :tabprevious<cr> map <C-n> :tabnext<cr> map <C-k> :tabclose<cr> map <C-Tab> :tabnext<cr> " 新建 XHTML 、PHP、Javascript 文件的快捷鍵 nmap <C-c><C-h> :NewQuickTemplateTab xhtml<cr> nmap <C-c><C-p> :NewQuickTemplateTab php<cr> nmap <C-c><C-j> :NewQuickTemplateTab javascript<cr> nmap <C-c><C-c> :NewQuickTemplateTab css<cr> " 在文件名上按gf時,在新的tab中打開 map gf :tabnew <cfile><cr> "jquery 配色 au BufRead,BufNewFile *.js set syntax=jquery " jsLint for Vim let g:jslint_highlight_color = '#996600' " 指定 jsLint 調用路徑,通常不用更改 let g:jslint_command = $HOME . '\/.vim\/jsl\/jsl' " 指定 jsLint 的啟動參數,可以指定相應的配置文件 let g:jslint_command_options = '-nofilelisting -nocontext -nosummary -nologo -process' " 返回當前時間 func! GetTimeInfo() "return strftime('%Y-%m-%d %A %H:%M:%S') return strftime('%Y-%m-%d %H:%M:%S') endfunction " 插入模式按 Ctrl + D(ate) 插入當前時間 imap <C-d> <C-r>=GetTimeInfo()<cr> "缺省不產生備份文件 set nobackup set nowritebackup " autoload _vimrc autocmd! bufwritepost _vimrc source % " ================== " plugin list " ================== "Color Scheme Explorer "jsbeauty \ff "NERDTree "Calendar "conquer_term "nerd_commenter "/*========================================*\ " 常用指令收集 "\*========================================*/ " 系統時間 " :map <F7> a<C-R>=strftime("%c")<CR><esc> " :s/__date__/\=strftime("%c")/ "/*---------------------------------------*\ " 基礎命令 "/*---------------------------------------*\ " ctrl+q 可以聯合復制,粘貼,替換用 行操作 " ctrl+w+j ctrl+w+k (:bn :bp :bd) " '. 它移動光標到上一次的修改行 " `. 它移動光標到上一次的修改點 " . 重復上次命令 " <C-O> : 依次沿着你的跳轉記錄向回跳 (從最近的一次開始) " <C-I> : 依次沿着你的跳轉記錄向前跳 " ju(mps) : 列出你跳轉的足跡 " :history : 列出歷史命令記錄 " :his c : 命令行命令歷史 " :his s : 搜索命令歷史 " q/ : 搜索命令歷史的窗口 " q: : 命令行命令歷史的窗口 " g ctrl+g 計算文件字符 " {,} 前進至上一段落前進至后一段落 " gg,G(2G) 文件首 " gd dw gf ga(進制轉化) " gg=G 全篇自動縮進 , =G 單行縮進 "* ci[ 刪除一對 [] 中的所有字符並進入插入模式 "* ci( 刪除一對 () 中的所有字符並進入插入模式 "* ci< 刪除一對 <> 中的所有字符並進入插入模式 "* ci{ 刪除一對 {} 中的所有字符並進入插入模式 "* cit 刪除一對 HTML/XML 的標簽內部的所有字符並進入插入模式 "* ci” ci’ ci` 刪除一對引號字符 (” 或 ‘ 或 `) 中所有字符並進入插入模式 " "* vi[ 選擇一對 [] 中的所有字符 "* vi( 選擇一對 () 中的所有字符 "* vi< 選擇一對 <> 中的所有字符 "* vi{ 選擇一對 {} 中的所有字符 "* vit 選擇一對 HTML/XML 的標簽內部的所有字符 "* vi” vi’ vi` 選擇一對引號字符 (” 或 ‘ 或 `) 中所有字符 " crl+] 函數原型處 crl+t 回 ( ctags ) " ctl+p 自動補全( 編輯狀態 ) " :X 加密保存( 要輸入密碼 ) " ? / (N n) " f(F,t) 查找字符 " w(e) 移動光標到下一個單詞. " 5fx 表示查找光標后第 5 個 x 字符. " 5w(e) 移動光標到下五個單詞. " b 移動光標到上一個單詞. " 0 移動光標到本行最開頭. " ^ 移動光標到本行最開頭的字符處. " $ 移動光標到本行結尾處. " H 移動光標到屏幕的首行. " M 移動光標到屏幕的中間一行. " L 移動光標到屏幕的尾行. " c-f (即 ctrl 鍵與 f 鍵一同按下) " c-b (即 ctrl 鍵與 b 鍵一同按下) 翻頁 " c-d (下半頁) c-u(上半頁) c-e (一行滾動) " zz 讓光標所在的行居屏幕中央 " zt 讓光標所在的行居屏幕最上一行 " zb 讓光標所在的行居屏幕最下一行 " 在 vi 中 y 表示拷貝, d 表示刪除, p 表示粘貼. 其中拷貝與刪除是與光標移動命令 " yw 表示拷貝從當前光標到光標所在單詞結尾的內容. " dw 表示刪除從當前光標到光標所在單詞結尾的內容. " y0 表示拷貝從當前光標到光標所在行首的內容. " d0 表示刪除從當前光標到光標所在行首的內容. " y$(Y) 表示拷貝從當前光標到光標所在行尾的內容. " d$(D) 表示刪除從當前光標到光標所在行尾的內容. " yfa 表示拷貝從當前光標到光標后面的第一個a字符之間的內容. " dfa 表示刪除從當前光標到光標后面的第一個a字符之間的內容. " s(S),a(A),x(X),D " yy 表示拷貝光標所在行. " dd 表示刪除光標所在行. " 5yy 表示拷貝光標以下 5 行. " 5dd 表示刪除光標以下 5 行. " y2fa 表示拷貝從當前光標到光標后面的第二個a字符之間的內容. " :12,24y 表示拷貝第12行到第24行之間的內容. " :12,y 表示拷貝第12行到光標所在行之間的內容. " :,24y 表示拷貝光標所在行到第24行之間的內容. 刪除類似. " TAB 就是制表符, 單獨拿出來做一節是因為這個東西確實很有用. " << 輸入此命令則光標所在行向左移動一個 tab. " >> 輸入此命令則光標所在行向右移動一個 tab. " 5>> 輸入此命令則光標后 5 行向右移動一個 tab. " :5>>(>>>) :>>(>>>)5 " :12,24> 此命令將12行到14行的數據都向右移動一個 tab. " :12,24>> 此命令將12行到14行的數據都向右移動兩個 tab. " :set shiftwidth=4 設置自動縮進 4 個空格, 當然要設自動縮進先. " :set sts=4 即設置 softtabstop 為 4. 輸入 tab 后就跳了 4 格. " :set tabstop=4 實際的 tab 即為 4 個空格, 而不是缺省的 8 個. " :set expandtab 在輸入 tab 后, vim 用恰當的空格來填充這個 tab. " :g/^/exec 's/^/'.strpart(line('.').' ', 0, 4) 在行首插入行號 " set ai 設置自動縮進 " 5ia<esc> 重復插入5個a字符 "/*---------------------------------------*\ " 替換命令 "/*---------------------------------------*\ " 替換文字 2009-02-34 ----> 2009-02-34 00:00:00 " :%s/\(\d\{4\}-\d\{2\}-\d\{2\}\)/\1 00:00:00/g " :s/aa/bb/g 將光標所在行出現的所有包含 aa 的字符串中的 aa 替換為 bb " :s/\/bb/g 將光標所在行出現的所有 aa 替換為 bb, 僅替換 aa 這個單詞 " :%s/aa/bb/g 將文檔中出現的所有包含 aa 的字符串中的 aa 替換為 bb " :12,23s/aa/bb/g 將從12行到23行中出現的所有包含 aa 的字符串中的 aa 替換為 bb " :12,23s/^/#/ 將從12行到23行的行首加入 # 字符 " :%s/fred/joe/igc 一個常見的替換命令,修飾符igc和perl中一樣意思 " s/dick/joe/igc則 對於這些滿足條件的行進行替換 " :g/^\s*$/d 空行(空格也不包含)刪除. " :%s/\r//g 刪除DOS方式的回車^M " :%s/ *$// 刪除行尾空白(%s/\s*$//g) " :g!/^dd/d 刪除不含字符串'dd'開頭的行 " :v/^dd/d 同上,譯釋:v == g!,就是不匹配! " :v/./.,/./-1join 壓縮空行(多行空行合並為一行) " :g/^$/,/./-j 壓縮空行(多行空行合並為一行) " :g/^/pu _ 把文中空行擴增一倍 (pu = put),原來兩行間有一個空行,現在變成2個 " :g/^/m0 按行翻轉文章 (m = move) " :g/fred/,/joe/d not line based (very powerfull) " :g/<input\|<form/p 或者 要用\| " :g/fred/t$ 拷貝行,從fred到文件末尾(EOF) " :%norm jdd 隔行刪除,譯釋:%指明是對所有行進行操作,norm指出后面是normal模式的指令,j是下移一行,dd是刪除行 " :'a,'bg/fred/s/dick/joe/igc ('a,'b指定一個范圍:mark a ~ mark b) " g//用一個正則表達式指出了進行操作的行必須可以被fred匹配,g//是一個全局顯示命令 " /joe/e 光標停留在匹配單詞最后一個字母處 " /joe/e+1 光標停留在匹配單詞最后一個字母的下一個字母處 " /joe/s 光標停留在匹配單詞第一個字母處 " /^joe.*fred.*bill/ 標准正則表達式 " /^[A-J]\+/ 找一個以A~J中一個字母重復兩次或以上開頭的行 " /forum\(\_.\)*pent 多行匹配 " /fred\_s*joe/i 中間可以有任何空白,包括換行符\n " /fred\|joe 匹配FRED或JOE " /\<fred\>/i 匹配fred,fred必須是一個獨立的單詞,而不是子串 " /\<\d\d\d\d\> 匹配4個數字 \<\d\{4}\> " 列,替換所有在第三列中的str1 " :%s:\(\(\w\+\s\+\)\{2}\)str1:\1str2: " 交換第一列和最后一列 (共4列) " :%s:\(\w\+\)\(.*\s\+\)\(\w\+\)$:\3\2\1: " 全局(global)顯示命令,就是用 :g+正則表達式 " 譯釋: :g/{pattern}/{cmd} 就是全局找到匹配的,然后對這些行執行命令{cmd} " :g/\<fred\>/ 顯示所有能夠為單詞fred所匹配的行 " :g/<pattern>/z#.5 顯示內容,還有行號 " :g/<pattern>/z#.5|echo '==========' 漂亮的顯示 "/*---------------------------------------*\ " 多文檔操作 (基礎) "/*---------------------------------------*\ " 用 :ls! 可以顯示出當前所有的buffer " :bn 跳轉到下一個buffer " :bp 跳轉到上一個buffer " :wn 存盤當前文件並跳轉到下一個 " :wp 存盤當前文件並跳轉到上一個 " :bd 把這個文件從buffer列表中做掉 " :b 3 跳到第3個buffer " :b main 跳到一個名字中包含main的buffer "/*---------------------------------------*\ " 列復制 "/*---------------------------------------*\ " 譯注:@#%&^#*^%#$! " :%s= [^ ]\+$=&&= : 復制最后一列 " :%s= \f\+$=&&= : 一樣的功能 " :%s= \S\+$=&& : ft,還是一樣 " 反向引用,或稱記憶 " :s/\(.*\):\(.*\)/\2 : \1/ : 顛倒用:分割的兩個字段 " :%s/^\(.*\)\n\1/\1$/ : 刪除重復行 " 非貪婪匹配,\{-} " :%s/^.\{-}pdf/new.pdf/ : 只是刪除第一個pdf " 跨越可能的多行 " :%s/<!--\_.\{-}-->// : 又是刪除多行注釋(咦?為什么要說「又」呢?) " :help /\{-} : 看看關於 非貪婪數量符 的幫助 " :s/fred/<c-r>a/g : 替換fred成register a中的內容,呵呵 " 寫在一行里的復雜命令 " :%s/\f\+\.gif\>/\r&\r/g | v/\.gif$/d | %s/gif/jpg/ " 譯注:就是用 | 管道啦 "/*---------------------------------------*\ " 大小寫轉換 "/*---------------------------------------*\ " g~~ : 行翻轉 " vEU : 字大寫(廣義字) " vE~ : 字翻轉(廣義字) " ~ 將光標下的字母改變大小寫 " 3~ 將下3個字母改變其大小寫 " g~w 字翻轉 " U 將可視模式下的字母全改成大寫字母 " gUU 將當前行的字母改成大寫 " u 將可視模式下的字母全改成小寫 " guu 將當前行的字母全改成小寫 " gUw 將光標下的單詞改成大寫。 " guw 將光標下的單詞改成小寫。 " 文件瀏覽 " :Ex : 開啟目錄瀏覽器,注意首字母E是大寫的 " :Sex : 在一個分割的窗口中開啟目錄瀏覽器 " :ls : 顯示當前buffer的情況 " :cd .. : 進入父目錄 " :pwd " :args : 顯示目前打開的文件 " :lcd %:p:h : 更改到當前文件所在的目錄 " 譯釋:lcd是緊緊改變當前窗口的工作路徑,% 是代表當前文件的文件名, " 加上 :p擴展成全名(就是帶了路徑),加上 :h析取出路徑
