1. 程式人生 > >vim配置文件

vim配置文件

arch ble shift next visible lead you () indent

常用.vimrc配置

 " 開啟語法高亮
syntax on  

" 設置字體  
set guifont=Monaco\ 12

" 設置歷史記錄條數  
set history=2000  

" 檢測文件類型  
filetype on  

" 針對不同的文件,采用不同的縮進方式  
filetype indent on  

" 允許插件  
filetype plugin on  

" 啟動自動補全
filetype plugin indent on

" 文件修改之後自動讀入
set autoread

" 啟動後不顯示提示
"set shortmess=atI

" 設置取消備份,禁止臨時文件生成  
set nobackup  
set noswapfile  

" create undo file
set undolevels=1000 " how many undos
set undoreload=10000 " number of lines to save for undo
if v:version >= 730
    set undofile     " keep a persistent backup file
    set undodir=/tmp/vimundo/
endif

"set wildignore=*.swp,*.bak,*.pyc,*.class,.svn

" 顯示當前橫豎線  
"set cursorline  
"set cursorcolumn  

" 設置退出Vim之後內容顯示在終端屏幕,可以用於查看和復制
" 好處:誤刪什麽,如果以前屏幕打開可以用來找回
" set t_ti= t_te=

" 設置在Vim中可以使用鼠標,防止終端無法拷貝  
set mouse=a  

"==========================================
" Display Settings
"==========================================
"
" 顯示當前行號和列號
set ruler

" 在狀態欄顯示正在輸入的命令
set showcmd

" 左下角顯示當前Vim模式
set showmode

" 光標移動至少保留的行數
"set scrolloff=7

" 命令行(在狀態行下)的高度,默認為1,這裏是2
set statusline=%<%f\ %h%m%r%=%k[%{(&fenc==\"\")?&enc:&fenc}%{(&bomb?\",BOM\":\"\")}]\ %-14.(%l,%c%V%)\ %P

" 總是顯示狀態欄(Powerline需要2行)  
set laststatus=2  

" 顯示行號  
set number  

" 指定不折行
"set nowrap  

" 設置代碼匹配,包括括號匹配情況  
set showmatch  

" how many tenths of a second to blink when matching brackets
" setmatchtime=2

" 開啟及時搜索(is)  
set incsearch  

" 設置搜索高亮(hlsearch)  
set hls  

" 設置搜索時忽略大小寫  
set ignorecase  

" 當搜索的時候嘗試smart  
set smartcase  

" 設置代碼折疊
"set foldenable
" 折疊方法
" manual 手工折疊
" indent 縮進折疊
" expr 表達式折疊
" syntax 語法折疊
" diff 對沒有更改的文件折疊
" marker 標記折疊
"set foldmethod=indent
"set foldlevel=99

" 設置C/C++方式自動對齊  
set autoindent  
set cindent  
set smartindent  

" 設置tab寬度  
set tabstop=4  


" 設置自動對齊空格數  
set shiftwidth=4  

" 按退格鍵時可以一次刪除4個空格
"set softtabstop=4

 " 編輯的時候將所有的tab設置為空格(expandtab)  
 set et  

 " 使用Backspace直接刪除tab  
 set smarttab  

" 不在單詞中間折行  
set lbr  
 "==========================================
 " FileEncode Settings
 "==========================================

     


inoremap ( ()i 
inoremap [ []i 
inoremap { {}i 
inoremap < <>i 
" 設置編碼方式  
 set encoding=utf-8  

 " 設置打開文件的編碼格式  
 set fileencodings=ucs-bom,utf-8,cp936,gb18030,big5,euc-jp,euc-kr,latin1  

 set helplang=cn 

 " 只對終端影響(默認)
 set termencoding=utf-8

 " use UNIX as the standard file type
 set ffs=unix,dos,mac

" 如遇Unicode值大於255的文本,不必等到空格再折行。
set formatoptions+=m

" 合並兩行中文時,不在中間加空格:
set formatoptions+=B

"==========================================
" Other Settings
"==========================================
 " 自動補全配置讓Vim補全菜單行為跟IDE一致
 set completeopt=longest,menu

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

 " ignore compiled files
 " set wildignore=*.o,*~,*.pyc,*.class

"離開插入模式後自動關閉預覽窗口
autocmd InsertLeave * if pumvisible() == 0|pclose|endif

"回車即選中當前項
inoremap <expr> <CR>       pumvisible() ? "\<C-y>" : "\<CR>"

"上下左右鍵的行為 會顯示其他信息
inoremap <expr> <Down>     pumvisible() ? "\<C-n>" : "\<Down>"
inoremap <expr> <Up>       pumvisible() ? "\<C-p>" : "\<Up>"
inoremap <expr> <PageDown> pumvisible() ? "\<PageDown>\<C-p>\<C-n>" : "\<PageDown>"
inoremap <expr> <PageUp>   pumvisible() ? "\<PageUp>\<C-p>\<C-n>" : "\<PageUp>"

" if this not work ,make sure .viminfo is writable for you
if has("autocmd")
  au BufReadPost * if line("‘\"") > 1 && line("‘\"") <= line("$") | exe "normal! g‘\"" | endif
endif

"==========================================
" HotKey Settings
"==========================================
"
" 去掉搜索高亮
"noremap <silent><leader>/ :nohls<CR>
map <leader>/ :nohls<CR>

map <leader>tn :tabnew<cr>
map <leader>to :tabonly<cr>
map <leader>tc :tabclose<cr>
map <leader>tm :tabmove

" Opens a new tab with the current buffer‘s path
" Super useful when editing files in the same directory
map <leader>te :tabedit <c-r>=expand("%:p:h")<cr>/

" Quickly edit/reload the vimrc file
nmap <silent> <leader>ev :e $MYVIMRC<CR>
nmap <silent> <leader>sv :so $MYVIMRC<CR>

" 手動刷新tags(含cscope)
nmap tg :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q *<CR>:set tags+=./tags<CR>:!cscope -Rbq<CR>:cs add ./cscope.out .<CR>

" 切換buffer
nnoremap [b :bp<CR>
nnoremap ]b :bn<CR>

" cscope設置
if has("cscope")
    set csprg=/usr/bin/cscope   " 制定cscope命令
    set csto=0                  " ctags查找順序,0表示先cscope數據庫再標簽文件,1表示先標簽文件愛
    set cst                     " 同時搜索tag文件和cscope數據庫
    set cscopequickfix=s-,c-,d-,i-,t-,e-  "使用QucikFix窗口來顯示cscope查找結果
    set nocsverb
    if filereadable("cscope.out")  "如果當前目錄下有cscope.out則加載進Vim
        cs add cscope.out
    elseif $CSCOPE_DB != ""       "否則只要環境變量不為空就添加制定的數據庫到Vim
        cs add $CSCOPE_DB
    endif
    set csverb
endif
"map <F4>:!cscope -Rbq<CR>:cs add ./cscope.out .<CR><CR><CR> :cs reset<CR>
" 查找符號
nmap <leader>css :cs find s <C-R>=expand("<cword>")<CR><CR> :copen<CR><CR>
" 查找定義
nmap <leader>csg :cs find g <C-R>=expand("<cword>")<CR><CR>
" 查找被這個函數調用的函數
nmap <leader>csd :cs find d <C-R>=expand("<cword>")<CR><CR> :copen<CR><CR>
" 查找調用這個函數的函數
nmap <leader>csc :cs find c <C-R>=expand("<cword>")<CR><CR>:copen<CR><CR>
" 查找這個字符串
nmap <leader>cst :cs find t <C-R>=expand("<cword>")<CR><CR>:copen<CR><CR>
" 查找這個egrep匹配模式
nmap <leader>cse :cs find e <C-R>=expand("<cword>")<CR><CR>:copen<CR><CR>
" 查找這個文件
nmap <leader>csf :cs find f <C-R>=expand("<cfile>")<CR><CR>
" 查找include這個文件的文件
nmap <leader>csi :cs find i <C-R>=expand("<cfile>")<CR><CR> :copen<CR><CR>

" 設定是否使用QuickFix來顯示結果
set cscopequickfix=s-,c-,d-,i-,t-,e-

" QuickFix open and close
nnoremap <F11> :copen<CR>
nnoremap <F12> :cclose<CR>

" QucikFix next and prev
nnoremap <F9> :cn<CR>
nnoremap <F10> :cp<CR>

"==========================================
" Theme Settings
"==========================================

" Set extra options when running in GUI mode
"if has("gui_running")
"    set guifont=Monaco\ 12
"    set guioptions-=T
"    set guioptions+=e
"    set guioptions-=r
"    set guioptions-=L
"    set guitablabel=%M\ %t
"    set showtabline=1 
"    set linespace=2 
"    set noimd   
"    set t_Co=256
"endif

" 設置主題  
"set background=dark
"colorscheme molokai  
"colorscheme solarized
set t_Co=256

" 添加水平滾動條  
"set guioptions+=b  

" 取消菜單欄和導航欄  
set guioptions-=m  
set guioptions-=T  

" 去除左右兩邊滾動條
set go-=r
set go-=L

" 設置水平行數和豎直列數  
"set lines=35  
"set columns=99  

" 使pathogen生效(插件管理器,只需將插件放入bundle,將pathogen.vim放入autoload即可)  
"execute pathogen#infect()  
"
"==========================================
" Vundle Settings
"==========================================

 " 關閉vi的一致性模式,避免以前版本的一些Bug和局限  
set nocompatible  

vim配置文件