默認(rèn)的配置文件
安裝vim 之后席覆,默認(rèn)只會(huì)有 $ vim ~/.viminfo
, 是沒(méi)有 $ vim ~/.vimrc
文件的。
如果需要,可以自行創(chuàng)建 .vimrc 文件姆泻。
比如:
修改前:
$ vim a.py
修改前.png
創(chuàng)建并修改 ~/.vimrc 文件:
$ vim ~/.vimrc
修改vimrc文件.png
修改后:
$ vim a.py
xxx.png
小馬哥的配置文件
set sw=4
set ts=4
set et
set smarttab
set smartindent
set lbr
set fo+=mB
set sm
set selection=inclusive
set wildmenu
set mousemodel=popup
au FileType php setlocal dict+=~/.vim/dict/php_funclist.dict
au FileType css setlocal dict+=~/.vim/dict/css.dict
au FileType c setlocal dict+=~/.vim/dict/c.dict
au FileType cpp setlocal dict+=~/.vim/dict/cpp.dict
au FileType scale setlocal dict+=~/.vim/dict/scale.dict
au FileType javascript setlocal dict+=~/.vim/dict/javascript.dict
au FileType html setlocal dict+=~/.vim/dict/javascript.dict
au FileType html setlocal dict+=~/.vim/dict/css.dict
"
"syntastic相關(guān)
execute pathogen#infect()
let g:syntastic_python_checkers=['pylint']
let g:syntastic_php_checkers=['php', 'phpcs', 'phpmd']
"golang
"Processing... % (ctrl+c to stop)
let g:fencview_autodetect=0
set rtp+=$GOROOT/misc/vim
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" 顯示相關(guān)
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
syntax on
set cul "高亮光標(biāo)所在行
set cuc
set shortmess=atI " 啟動(dòng)的時(shí)候不顯示那個(gè)援助烏干達(dá)兒童的提示
set go= " 不要圖形按鈕
"color desert " 設(shè)置背景主題
color ron " 設(shè)置背景主題
"color torte " 設(shè)置背景主題
"set guifont=Courier_New:h10:cANSI " 設(shè)置字體
"autocmd InsertLeave * se nocul " 用淺色高亮當(dāng)前行
autocmd InsertEnter * se cul " 用淺色高亮當(dāng)前行
set ruler " 顯示標(biāo)尺
set showcmd " 輸入的命令顯示出來(lái)火窒,看的清楚些
"set whichwrap+=<,>,h,l " 允許backspace和光標(biāo)鍵跨越行邊界(不建議)
set scrolloff=3 " 光標(biāo)移動(dòng)到buffer的頂部和底部時(shí)保持3行距離
set statusline=%F%m%r%h%w\ [FORMAT=%{&ff}]\ [TYPE=%Y]\ [POS=%l,%v][%p%%]\ %{strftime(\"%d/%m/%y\ -\ %H:%M\")} "狀態(tài)行顯示的內(nèi)容
set laststatus=2 " 啟動(dòng)顯示狀態(tài)行(1),總是顯示狀態(tài)行(2)
"set foldenable " 允許折疊
""set foldmethod=manual " 手動(dòng)折疊
set nocompatible "去掉討厭的有關(guān)vi一致性模式硼补,避免以前版本的一些bug和局限
" 顯示中文幫助
if version >= 603
set helplang=cn
set encoding=utf-8
endif
" 自動(dòng)縮進(jìn)
set autoindent
set cindent
" Tab鍵的寬度
set tabstop=4
" 統(tǒng)一縮進(jìn)為4
set softtabstop=4
set shiftwidth=4
" 使用空格代替制表符
set expandtab
" 在行和段開(kāi)始處使用制表符
set smarttab
" 顯示行號(hào)
set number
" 歷史記錄數(shù)
set history=1000
"搜索逐字符高亮
set hlsearch
set incsearch
"語(yǔ)言設(shè)置
set langmenu=zh_CN.UTF-8
set helplang=cn
" 總是顯示狀態(tài)行
set cmdheight=2
" 偵測(cè)文件類(lèi)型
filetype on
" 載入文件類(lèi)型插件
filetype plugin on
" 為特定文件類(lèi)型載入相關(guān)縮進(jìn)文件
filetype indent on
" 保存全局變量
set viminfo+=!
" 帶有如下符號(hào)的單詞不要被換行分割
set iskeyword+=_,$,@,%,#,-
" 字符間插入的像素行數(shù)目
"markdown配置
au BufRead,BufNewFile *.{md,mdown,mkd,mkdn,markdown,mdwn} set filetype=mkd
au BufRead,BufNewFile *.{go} set filetype=go
au BufRead,BufNewFile *.{js} set filetype=javascript
"rkdown to HTML
nmap md :!~/.vim/markdown.pl % > %.html <CR><CR>
nmap fi :!firefox %.html & <CR><CR>
nmap \ \cc
vmap \ \cc
"將tab替換為空格
nmap tt :%s/\t/ /g<CR>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"""""新文件標(biāo)題
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"新建.c,.h,.sh,.java文件,自動(dòng)插入文件頭
autocmd BufNewFile *.cpp,*.[ch],*.sh,*.rb,*.java,*.py exec ":call SetTitle()"
""定義函數(shù)SetTitle沛鸵,自動(dòng)插入文件頭
func SetTitle()
"如果文件類(lèi)型為.sh文件
if &filetype == 'sh'
call setline(1,"\#!/bin/bash")
call append(line("."), "")
elseif &filetype == 'python'
call setline(1,"#!/usr/bin/env python")
call append(line("."),"# coding=utf-8")
call append(line(".")+1, "")
elseif &filetype == 'ruby'
call setline(1,"#!/usr/bin/env ruby")
call append(line("."),"# encoding: utf-8")
call append(line(".")+1, "")
" elseif &filetype == 'mkd'
" call setline(1,"<head><meta charset=\"UTF-8\"></head>")
else
call setline(1, "/*************************************************************************")
call append(line("."), " > File Name: ".expand("%"))
call append(line(".")+1, " > Author: ")
call append(line(".")+2, " > Mail: ")
call append(line(".")+3, " > Created Time: ".strftime("%c"))
call append(line(".")+4, " ************************************************************************/")
call append(line(".")+5, "")
endif
if expand("%:e") == 'cpp'
call append(line(".")+6, "#include<iostream>")
call append(line(".")+7, "using namespace std;")
call append(line(".")+8, "")
endif
if &filetype == 'c'
call append(line(".")+6, "#include<stdio.h>")
call append(line(".")+7, "")
endif
if expand("%:e") == 'h'
call append(line(".")+6, "#ifndef _".toupper(expand("%:r"))."_H")
call append(line(".")+7, "#define _".toupper(expand("%:r"))."_H")
call append(line(".")+8, "#endif")
endif
if &filetype == 'java'
call append(line(".")+6,"public class ".expand("%:r"))
call append(line(".")+7,"")
endif
"新建文件后括勺,自動(dòng)定位到文件末尾
endfunc
autocmd BufNewFile * normal G
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"鍵盤(pán)命令
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
:nmap <silent> <F9> <ESC>:Tlist<RETURN>
" shift tab pages
map <S-Left> :tabp<CR>
map <S-Right> :tabn<CR>
map! <C-Z> <Esc>zzi
map! <C-O> <C-Y>,
map <C-A> ggVG$"+y
map <Esc><Esc> :w<CR>
map <F12> gg=G
map <C-w> <C-w>w
imap <C-k> <C-y>,
imap <C-t> <C-q><TAB>
imap <C-j> <ESC>
" 選中狀態(tài)下 Ctrl+c 復(fù)制
"map <C-v> "*pa
imap <C-v> <Esc>"*pa
imap <C-a> <Esc>^
imap <C-e> <Esc>$
vmap <C-c> "+y
set mouse=v
"set clipboard=unnamed
"去空行
nnoremap <F2> :g/^\s*$/d<CR>
"比較文件
nnoremap <C-F2> :vert diffsplit
"nnoremap <Leader>fu :CtrlPFunky<Cr>
"nnoremap <C-n> :CtrlPFunky<Cr>
"列出當(dāng)前目錄文件
map <F3> :NERDTreeToggle<CR>
imap <F3> <ESC> :NERDTreeToggle<CR>
"打開(kāi)樹(shù)狀文件目錄
map <C-F3> \be
:autocmd BufRead,BufNewFile *.dot map <F5> :w<CR>:!dot -Tjpg -o %<.jpg % && eog %<.jpg <CR><CR> && exec "redr!"
"C,C++ 按F5編譯運(yùn)行
map <F5> :call CompileRunGcc()<CR>
func! CompileRunGcc()
exec "w"
if &filetype == 'c'
exec "!g++ % -o %<"
exec "!time ./%<"
elseif &filetype == 'cpp'
exec "!g++ % -std=c++11 -o %<"
exec "!time ./%<"
elseif &filetype == 'java'
exec "!javac %"
exec "!time java %<"
elseif &filetype == 'sh'
:!time bash %
elseif &filetype == 'python'
exec "!time python2.7 %"
elseif &filetype == 'html'
exec "!firefox % &"
elseif &filetype == 'go'
" exec "!go build %<"
exec "!time go run %"
elseif &filetype == 'mkd'
exec "!~/.vim/markdown.pl % > %.html &"
exec "!firefox %.html &"
endif
endfunc
"C,C++的調(diào)試
map <F8> :call Rungdb()<CR>
func! Rungdb()
exec "w"
exec "!g++ % -std=c++11 -g -o %<"
exec "!gdb ./%<"
endfunc
"代碼格式優(yōu)化化
map <F6> :call FormartSrc()<CR><CR>
"定義FormartSrc()
func FormartSrc()
exec "w"
if &filetype == 'c'
exec "!astyle --style=ansi -a --suffix=none %"
elseif &filetype == 'cpp' || &filetype == 'hpp'
exec "r !astyle --style=ansi --one-line=keep-statements -a --suffix=none %> /dev/null 2>&1"
elseif &filetype == 'perl'
exec "!astyle --style=gnu --suffix=none %"
elseif &filetype == 'py'||&filetype == 'python'
exec "r !autopep8 -i --aggressive %"
elseif &filetype == 'java'
exec "!astyle --style=java --suffix=none %"
elseif &filetype == 'jsp'
exec "!astyle --style=gnu --suffix=none %"
elseif &filetype == 'xml'
exec "!astyle --style=gnu --suffix=none %"
else
exec "normal gg=G"
return
endif
exec "e! %"
endfunc
"結(jié)束定義FormartSrc
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
""實(shí)用設(shè)置
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
if has("autocmd")
autocmd BufReadPost *
\ if line("'\"") > 0 && line("'\"") <= line("$") |
\ exe "normal g`\"" |
\ endif
endif
"當(dāng)打開(kāi)vim且沒(méi)有文件時(shí)自動(dòng)打開(kāi)NERDTree
autocmd vimenter * if !argc() | NERDTree | endif
" 只剩 NERDTree時(shí)自動(dòng)關(guān)閉
autocmd bufenter * if (winnr("$") == 1 && exists("b:NERDTreeType") && b:NERDTreeType == "primary") | q | endif
" 設(shè)置當(dāng)文件被改動(dòng)時(shí)自動(dòng)載入
set autoread
" quickfix模式
autocmd FileType c,cpp map <buffer> <leader><space> :w<cr>:make<cr>
"代碼補(bǔ)全
set completeopt=preview,menu
"允許插件
"filetype plugin on
"共享剪貼板
"set clipboard+=unnamed
"自動(dòng)保存
set autowrite
"set ruler " 打開(kāi)狀態(tài)欄標(biāo)尺
"set cursorline " 突出顯示當(dāng)前行
set magic " 設(shè)置魔術(shù)
set guioptions-=T " 隱藏工具欄
set guioptions-=m " 隱藏菜單欄
""set foldcolumn=0
""set foldmethod=indent
""set foldlevel=3
" 不要使用vi的鍵盤(pán)模式曲掰,而是vim自己的
set nocompatible
" 去掉輸入錯(cuò)誤的提示聲音
set noeb
" 在處理未保存或只讀文件的時(shí)候疾捍,彈出確認(rèn)
set confirm
"禁止生成臨時(shí)文件
set nobackup
set noswapfile
"搜索忽略大小寫(xiě)
set ignorecase
set linespace=0
" 增強(qiáng)模式中的命令行自動(dòng)完成操作
set wildmenu
" 使回格鍵(backspace)正常處理indent, eol, start等
set backspace=2
" 允許backspace和光標(biāo)鍵跨越行邊界
set whichwrap+=<,>,h,l
" 可以在buffer的任何地方使用鼠標(biāo)(類(lèi)似office中在工作區(qū)雙擊鼠標(biāo)定位)
set mouse=a
set selection=exclusive
set selectmode=mouse,key
" 通過(guò)使用: commands命令,告訴我們文件的哪一行被改變過(guò)
set report=0
" 在被分割的窗口間顯示空白栏妖,便于閱讀
set fillchars=vert:\ ,stl:\ ,stlnc:\
" 高亮顯示匹配的括號(hào)
set showmatch
" 匹配括號(hào)高亮的時(shí)間(單位是十分之一秒)
set matchtime=1
" 光標(biāo)移動(dòng)到buffer的頂部和底部時(shí)保持3行距離
set scrolloff=3
" 為C程序提供自動(dòng)縮進(jìn)
"自動(dòng)補(bǔ)全
"":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 ' ''<ESC>i
""function! ClosePair(char)
"" if getline('.')[col('.') - 1] == a:char
"" return "\<Right>"
"" else
"" return a:char
"" endif
""endfunction
filetype plugin indent on
"打開(kāi)文件類(lèi)型檢測(cè), 加了這句才可以用智能補(bǔ)全
set completeopt=longest,menu
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
" CTags的設(shè)定
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
let Tlist_Sort_Type = "name" " 按照名稱(chēng)排序
let Tlist_Use_Right_Window = 1 " 在右側(cè)顯示窗口
let Tlist_Compart_Format = 1 " 壓縮方式
let Tlist_Exist_OnlyWindow = 1 " 如果只有一個(gè)buffer乱豆,kill窗口也kill掉buffer
""let Tlist_File_Fold_Auto_Close = 0 " 不要關(guān)閉其他文件的tags
""let Tlist_Enable_Fold_Column = 0 " 不要顯示折疊樹(shù)
"let Tlist_Show_One_File=1 "不同時(shí)顯示多個(gè)文件的tag,只顯示當(dāng)前文件的
"設(shè)置tags
set tags=tags;
set autochdir
""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"其他東東
"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
"默認(rèn)打開(kāi)Taglist
let Tlist_Auto_Open=0
""""""""""""""""""""""""""""""
" Tag list (ctags)
""""""""""""""""""""""""""""""""
let Tlist_Ctags_Cmd = '/usr/local/bin/ctags'
let Tlist_Show_One_File = 1 "不同時(shí)顯示多個(gè)文件的tag吊趾,只顯示當(dāng)前文件的
let Tlist_File_Fold_Auto_Close = 1
let Tlist_Exit_OnlyWindow = 1 "如果taglist窗口是最后一個(gè)窗口宛裕,則退出vim
let Tlist_Use_Right_Window = 1 "在右側(cè)窗口中顯示taglist窗口
" minibufexpl插件的一般設(shè)置
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1
nmap tl :Tlist<cr>
"python補(bǔ)全
let g:pydiction_location = '~/.vim/after/complete-dict'
let g:pydiction_menu_height = 20
let Tlist_Ctags_Cmd='/usr/local/bin/ctags'
let g:miniBufExplMapWindowNavVim = 1
let g:miniBufExplMapWindowNavArrows = 1
let g:miniBufExplMapCTabSwitchBufs = 1
let g:miniBufExplModSelTarget = 1
set iskeyword+=.
set termencoding=utf-8
set encoding=utf8
set fileencodings=utf8,ucs-bom,gbk,cp936,gb2312,gb18030
autocmd FileType python set omnifunc=pythoncomplete#Complete
"set nocompatible " be iMproved
"filetype off " required!
set rtp+=~/.vim/bundle/vundle/
call vundle#rc()
" let Vundle manage Vundle
" required!
Bundle 'gmarik/vundle'
" My Bundles here:
"
" original repos on github
Bundle 'tpope/vim-fugitive'
Bundle 'rstacruz/sparkup', {'rtp': 'vim/'}
Bundle 'Yggdroot/indentLine'
let g:indentLine_char = '┊'
"ndle 'tpope/vim-rails.git'
" vim-scripts repos
Bundle 'L9'
Bundle 'FuzzyFinder'
" non github repos
Bundle 'https://github.com/wincent/command-t.git'
Bundle 'Auto-Pairs'
Bundle 'python-imports.vim'
Bundle 'CaptureClipboard'
Bundle 'ctrlp-modified.vim'
Bundle 'last_edit_marker.vim'
Bundle 'synmark.vim'
"Bundle 'Python-mode-klen'
Bundle 'SQLComplete.vim'
Bundle 'Javascript-OmniCompletion-with-YUI-and-j'
"Bundle 'JavaScript-Indent'
"Bundle 'Better-Javascript-Indentation'
Bundle 'jslint.vim'
Bundle "pangloss/vim-javascript"
Bundle 'Vim-Script-Updater'
Bundle 'ctrlp.vim'
Bundle 'tacahiroy/ctrlp-funky'
Bundle 'jsbeautify'
Bundle 'The-NERD-Commenter'
"django
Bundle 'django_templates.vim'
Bundle 'Django-Projects'
"Bundle 'FredKSchott/CoVim'
"Bundle 'djangojump'
" ...
let g:html_indent_inctags = "html,body,head,tbody"
let g:html_indent_script1 = "inc"
let g:html_indent_style1 = "inc"
filetype plugin indent on " required!
"
"ctrlp設(shè)置
"
set wildignore+=*/tmp/*,*.so,*.swp,*.zip,*.pyc,*.png,*.jpg,*.gif " MacOSX/Linux
set wildignore+=*\\tmp\\*,*.swp,*.zip,*.exe,*.pyc,*.png,*.jpg,*.gif " Windows
let g:ctrlp_custom_ignore = '\v[\/]\.(git|hg|svn)$'
let g:ctrlp_custom_ignore = '\v\.(exe|so|dll)$'
let g:ctrlp_extensions = ['funky']
let NERDTreeIgnore=['\.pyc']
擴(kuò)展閱讀
vim配置文件和插件
https://github.com/ma6174/vim
簡(jiǎn)介:
小馬哥在github上vim最新內(nèi)容的托管论泛。