vim自動補全等文件編輯配置

一:代碼提示的

     找到一個插件:AutoComplPop。從下面的網址中下載該工具的最新版 
      http://www.vim.org/scripts/script.php?script_id=1879
     解壓文件得到兩個文件,一個是autoload目錄下的acp.vim,另一個是plugin下的acp.vim。 
     將分別放到/usr/share/vim/vim73下的autoload和plugin目錄下。

     重啓就ok了。

     ps:vim裏面有個快捷鍵可以用來補全代碼 C-n  (Ctrl+n)




二:括號自動生成

在.vimrc 文件裏面加上下面的內容

" 爲C程序提供自動縮進
set smartindent 
"代碼補全
set completeopt=preview,menu 
"自動補全
:inoremap ( ()<ESC>i 
:inoremap ) <c-r>=ClosePair(')')<CR> 
:inoremap { {<CR>}<ESC>O 
: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) 
if getline('.')[col('.') - 1] == a:char 
return "\<Right>" 
else 
return a:char 
endif 
endfunction 
filetype plugin indent on 
"打開文件類型檢測, 加了這句纔可以用智能補全
set completeopt=longest,menu 

 

 

三:我的vim配置文件內容(.vimrc)" All system-wide defaults are set in $VIMRUNTIME/debian.vim (usually just
" /usr/share/vim/vimcurrent/debian.vim) and sourced by the call to :runtime
" you can find below.  If you wish to change any of those settings, you should
" do it in this file (/etc/vim/vimrc), since debian.vim will be overwritten
" everytime an upgrade of the vim packages is performed.  It is recommended to
" make changes after sourcing debian.vim since it alters the value of the
" 'compatible' option.


" This line should not be removed as it ensures that various options are
" properly set to work with the Vim-related packages available in Debian.
runtime! debian.vim


" Uncomment the next line to make Vim more Vi-compatible
" NOTE: debian.vim sets 'nocompatible'.  Setting 'compatible' changes numerous
" options, so any other options should be set AFTER setting 'compatible'.
"set compatible


" Vim5 and later versions support syntax highlighting. Uncommenting the next
" line enables syntax highlighting by default.
if has("syntax")
  syntax on
endif


" If using a dark background within the editing area and syntax highlighting
" turn on this option as well
"set background=dark


" Uncomment the following to have Vim jump to the last position when
" reopening a file
"if has("autocmd")
"  au BufReadPost * if line("'\"") > 1 && line("'\"") <= line("$") | exe "normal! g'\"" | endif
"endif


" Uncomment the following to have Vim load indentation rules and plugins
" according to the detected filetype.
"if has("autocmd")
"  filetype plugin indent on
"endif


" The following are commented out as they cause vim to behave a lot
" differently from regular Vi. They are highly recommended though.
"set showcmd " Show (partial) command in status line.
"set showmatch " Show matching brackets.
"set ignorecase " Do case insensitive matching
"set smartcase " Do smart case matching
"set incsearch " Incremental search
"set autowrite " Automatically save before commands like :next and :make
"set hidden             " Hide buffers when they are abandoned
"set mouse=a " Enable mouse usage (all modes)


" Source a global configuration file if available
if filereadable("/etc/vim/vimrc.local")
  source /etc/vim/vimrc.local
endif






"以上爲原有配置


set confirm
set clipboard+=unnamed 
"set scrolloff=5
lcd /home/lzy/vim


"高亮顯示當前
set cursorline


" 啓用鼠標  
set mouse=a  
  
" 啓用行號  
set nu 




" 設置編碼自動識別, 中文引號顯示  
set fileencodings=utf-8,gbk


set ambiwidth=double 


"ColorScheme
syntax enable
syntax on
set hlsearch
colorscheme desert


"取消VIM的自動備份功能
set nobackup


"自動補全  
filetype plugin indent on
set completeopt=longest,menu
"自動補全命令時候使用菜單式匹配列表  
set wildmenu
autocmd FileType ruby,eruby set omnifunc=rubycomplete#Complete
autocmd FileType python set omnifunc=pythoncomplete#Complete
autocmd FileType javascript set omnifunc=javascriptcomplete#CompleteJS
autocmd FileType html set omnifunc=htmlcomplete#CompleteTags
autocmd FileType css set omnifunc=csscomplete#CompleteCSS
autocmd FileType xml set omnifunc=xmlcomplete#CompleteTags
autocmd FileType java set omnifunc=javacomplete#Complet


"Pydiction
"let g:pydiction_location = 'C:\Program Files\Vim\vim73\ftplugin\complete-dict'


" 允許退格鍵刪除和tab操作  
set smartindent  
set smarttab  
set expandtab  
set tabstop=4  
set softtabstop=4  
set shiftwidth=4  
set backspace=2
set textwidth=79
set nobackup


""if has("win32")
 ""   set guif
  ""  ont=Nimbus_Mono_l:h15:cANSI
   "" "set guifontwide=楷體_GB2312:h10
    "set guifontwide=YaHei Consolas Hybrid:h10
    ""au GUIEnter * simalt ~x   " 窗口最大化
""endif


map <C-D> :!python %<cr>




"Pydiction
let g:pydiction_location = 'C:\Program Files\Vim\vim73\ftplugin\complete-dict'


"TagList
let Tlist_Show_One_File=1


let Tlist_Show_One_File = 1 
let Tlist_Exit_OnlyWindow = 1


"tags
set tags=tags
set autochdir


"WinManager
let g:winManagerWindowLayout='FileExplorer|TagList'
nmap wm :WMToggle<cr>


"cscope show in quickfix
set cscopequickfix=s-,c-,d-,i-,t-,e-


"MiniBufExplorer
let g:miniBufExplMapWindowNavVim = 1 
let g:miniBufExplMapWindowNavArrows = 1 
let g:miniBufExplMapCTabSwitchBufs = 1 
let g:miniBufExplModSelTarget = 1


"Grep
nnoremap <silent> <F3> :Grep<CR>




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


map Q gq


inoremap <C-U> <C-G>u<C-U>


"括號匹配
vnoremap $1 <esc>`>a)<esc>`<i(<esc>


vnoremap $2 <esc>`>a]<esc>`<i[<esc>


vnoremap $3 <esc>`>a}<esc>`<i{<esc>


vnoremap $$ <esc>`>a"<esc>`<i"<esc>


vnoremap $q <esc>`>a'<esc>`<i'<esc>


vnoremap $e <esc>`>a"<esc>`<i"<esc>


autocmd BufNewFile *.py,*.cc,*.sh,*.java exec ":call SetTitle()"        
"新建.py,.cc,.java,.sh,  
""定義函數SetTitle,自動插入文件頭  
func SetTitle()  
        "如果文件類型爲.sh文件  
        if &filetype == 'python'  
                call setline(1, "\#-*- encoding: utf-8 -*- ")  
                call setline(2, "\"\"\"")  
                call setline(3, "\# @Author: elizhongyang")  
                call setline(4, "\# Created Time : ".strftime("%c"))  
                call setline(5, "")  
                call setline(6, "\# File Name: ".expand("%"))  
                call setline(7, "\# Description:")  
                call setline(8, "")  
                call setline(9, "\"\"\"")  
                call setline(10,"")  
        endif  
        if &filetype == 'java'  
                call setline(1, "//coding=utf8")  
                call setline(2, "/*************************************************************************")  
                call setline(3, "\ @Author: elizhongyang")  
                call setline(4, "\ @Created Time : ".strftime("%c"))  
                call setline(5, "")  
                call setline(6, "\ @File Name: ".expand("%"))  
                call setline(7, "\ @Description:")  
                call setline(8, "")  
                call setline(9, " ************************************************************************/")  
                call setline(10,"")  
        endif  
endfunc  
"以上是陳鵬的配置。
"以下是我的配置。


" 語法高亮
set syntax=on


" 自動縮進
set autoindent
set cindent


" Tab鍵的寬度
set tabstop=4


" 統一縮進爲4
set softtabstop=4
set shiftwidth=4


" 不要用空格代替製表符
set noexpandtab


" 在行和段開始處使用製表符
set smarttab


" 顯示行號
set number


" 歷史記錄數
set history=1000


"禁止生成臨時文件
set nobackup
set noswapfile


"搜索逐字符高亮
set hlsearch
set incsearch


"行內替換
set gdefault


" 總是顯示狀態行
set laststatus=2


" 命令行(在狀態行下)的高度,默認爲1,這裏是2
set cmdheight=2


" 偵測文件類型
filetype on


" 載入文件類型插件
filetype plugin on


" 爲特定文件類型載入相關縮進文件
filetype indent on


" 保存全局變量
set viminfo+=!


" 增強模式中的命令行自動完成操作
set wildmenu


" 使回格鍵(backspace)正常處理indent, eol, start等
set backspace=2


" 允許backspace和光標鍵跨越行邊界
set whichwrap+=<,>,h,l




" 可以在buffer的任何地方使用鼠標(類似office中在工作區雙擊鼠標定位)
set mouse=a
set selection=exclusive
set selectmode=mouse,key


" 通過使用: commands命令,告訴我們文件的哪一行被改變過
set report=0


" 啓動的時候不顯示那個援助索馬里兒童的提示
set shortmess=atI


" 在被分割的窗口間顯示空白,便於閱讀
set fillchars=vert:\ ,stl:\ ,stlnc:\


" 高亮顯示匹配的括號
set showmatch


" 匹配括號高亮的時間(單位是十分之一秒)
set matchtime=5


" 光標移動到buffer的頂部和底部時保持3行距離
set scrolloff=3


" 爲C程序提供自動縮進
set smartindent
"代碼補全
set completeopt=preview,menu 
"自動補全
:inoremap ( ()<ESC>i
:inoremap ) <c-r>=ClosePair(')')<CR>
:inoremap { {<CR>}<ESC>O
: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)
if getline('.')[col('.') - 1] == a:char
return "\<Right>"
else
return a:char
endif
endfunction
filetype plugin indent on 


"打開文件類型檢測, 加了這句纔可以用智能補全
set completeopt=longest,menu  

發佈了25 篇原創文章 · 獲贊 7 · 訪問量 7萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章