例子:/\<hello\> 精準匹配,之查找hello, \<表示開頭 \>表示結尾,因此/\<hello\>表示匹配以hello開頭和hello結尾的單詞。
vim配置:
vim ~/.vimrc文件
"讓vimrc配置變更立即生效
autocmd BufWritePost $MYVIMRC source $MYVIMRC
set number
syntax on
set autoindent
set smartindent
set background=dark
set showmatch
set fileencodings=utf-8,ucs-bom,gb18030,gbk,gb2312,cp936
set termencoding=utf-8
set showcmd
set cursorline
set hlsearch
set incsearch
set smartindent
set history=1000
filetype on
set showmatch
set nohls
set nocompatible
set backspace=indent,eol,start
"設置縮進
set tabstop=4
set softtabstop=4
set shiftwidth=4 "縮進的字符個數
set autoindent "自動縮進,繼承前一行的縮進方式,特別適用於多行註釋
set smartindent "依據上面的對起格式,智能的選擇對起方式,對於類似C語言編寫上很有用
set cindent "開啓C語言縮進
set cin "C/C++ 風格的自動縮進
set cino=:0g0t0sus "設定 C/C++ 風格自動縮進的選項
set completeopt=preview,menu "代碼補全
filetype plugin on "允許插件
set tags+=/home/hughxie/.vim/cpp_src/tags
function! ClosePair(char)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endfunction
"打開文件類型檢測,加了這句纔可以使用智能補全
set completeopt=longest,menu
" CTags的設定
"let Tlist_Sort_Type = "name" " 按照名稱排序
""let Tlist_Use_Right_Window = 1 " 在右側顯示窗口
""let Tlist_Compart_Format = 1 " 壓縮方式
""let Tlist_File_Fold_Auto_Close = 0 " 不要關閉其他文件的tags
""let Tlist_Enable_Fold_Column = 0 " 不要顯示摺疊樹
""autocmd FileType h,cpp,cc,c set tags+=D:\tools\cpp\tags
""let Tlist_Show_One_File=1
""set tags=tags
"默認打開Taglist
""let Tlist_Auto_Open=1
" Tag list (ctags)
""let Tlist_Ctags_Cmd = '/usr/bin/ctags'
""let Tlist_Show_One_File = 1 "不同時顯示多個文件的tag,只顯示當前文件的
""let Tlist_Use_Right_Window = 1 "在右側窗口中顯示taglist窗口
"新建.c,.h,.sh,.java文件,自動插入文件頭
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.java,*.lua exec ":call SetTitle()"
""定義函數SetTitle,自動插入文件頭
func SetTitle()
if &filetype == 'sh'
call setline(1,"\#########################################################################")
call append(line("."), "\# File Name: ".expand("%"))
call append(line(".")+1, "\# Author: wolf")
call append(line(".")+2, "\# Created Time: ".strftime("%c"))
call append(line(".")+3, "\#########################################################################")
call append(line(".")+4, "\#!/bin/bash")
call append(line(".")+5, "")
else
call setline(1, "\/*************************************************************************")
call append(line("."), " > File Name: ".expand("%"))
call append(line(".")+1, " > Author: wolf")
call append(line(".")+2, " > Created Time: ".strftime("%c"))
call append(line(".")+3, " ************************************************************************/")
call append(line(".")+4, "")
endif
if &filetype == 'cpp'
call append(line(".")+5, "#include<iostream>")
call append(line(".")+6, "using namespace std;")
call append(line(".")+7, "")
endif
if &filetype == 'c'
call append(line(".")+5, "#include<stdio.h>")
call append(line(".")+6, "")
endif
"新建文件後,自動定位到文件末尾
autocmd BufNewFile * normal G
endfunc
set tabstop=4
set softtabstop=4
set statusline=[%F]%y%r%m%*%=[Line:%l/%L,Column:%c][%p%%] "顯示文件名:總行數,總的字符數
set laststatus=2
set ruler "在編輯過程中,在右下角顯示光標位置的狀態行
set hlsearch
"讓vim記憶上次編輯的位置
autocmd BufReadPost *
\ if line("'\"")>0&&line("'\"")<=line("$") |
\ exe "normal g'\"" |
\ endif