vim配置入門,到豪華版vim配置
這幾天一直研究vim的配置,許多版本總是不盡如人意,網上確實有許多優秀的文章值得參考,我的博客後面會貼上具有參考價值的博客鏈接,本文的將手把手教你配置一個功能詳盡的vim.
首先你要明白的是linux下一切皆文件的思想,因此vim的配置文件.vimrc中的內容就決定了你的vim的功能。對於新手來說首先你要做的是保證你的linux(或者是centOs)能夠連上網。我當時是這樣解決的。
流程如下
1)點擊 VM->Settings Hardware選項卡下面
2)點擊Network Adapter 設置如下圖所示,首先我們在虛擬機中將網絡配置設置成NAT,
3、進入Windows操作系統,然後右鍵點擊我們的電腦,進入到管理界面 計算機-> 管理->服務和應用程序->服務,找到如下服務進程 VMware DHCP Service, VMware NAT Service。 分別點擊右鍵->啟動
二、下載並安裝vim。
從官方網站ftp://ftp.vim.org/pub/vim/unix/中選擇一個版本下載,我這裏使用的是vim-7.4.tar.bz2centos安裝vim7.4
系統版本centos6.4;
root權限
su - root
卸載(當然你也可以不用卸載)
$ rpm -qa | grep vim
$ yum remove vim vim-enhanced vim-common vim-minimal
下載、解壓
$ wget ftp://ftp.vim.org/pub/vim/unix/vim-7.4.tar.bz2
$ wget ftp://ftp.vim.org/pub/vim/extra/vim-7.2-extra.tar.gz
$ wget ftp://ftp.vim.org/pub/vim/extra/vim-7.2-lang.tar.gz
$
$ tar jxvf vim-7.4.tar.bz2
$ tar zxvf vim-7.2-extra.tar.gz
$ tar zxvf vim-7.2-lang.tar.gz
$
$ mv vim72 vim74
安裝編譯環境
$ yum install ncurses-devel
$ yum install gcc
編譯安裝
$ cd vim74/src
$ ./configure --enable-multibyte \--with-features=huge \--disable-selinux
$ make
$ make install
測試
$ vim --version
VIM - Vi IMproved 7.4
三、接下來我們開始配置vim
1.下查看~/目錄下有沒有一個.vimrc的文件,如果沒有自己在當前目錄創建一個。
2.需要說明的是在root目錄下的.vimrc對所有用戶生效。你也可以在每個用戶下單獨配置個性化.vimrc.
3.以下是我配置的vim截圖
4.vim的功能實際上是由配置文件和插件共同決定的,這裏我提供一份配置文件源碼。大家復制到自己的.vimrc文件中即可。方法是先復制到剪貼板然後打開cd ~/.vimrc,拷貝進去就好了。保存按:
sheft+: w
退出輸入:q
5.源碼如下:
[cpp] view plain copy- set helplang=cn
- set encoding=utf-8
- set cscopequickfix=s-,c-,d-,i-,t-,e-
- nmap <C-_>s :cs find s <C-R>=expand("<cword>")<CR><CR>
- nmap <C-_>g :cs find g <C-R>=expand("<cword>")<CR><CR>
- nmap <C-_>c :cs find c <C-R>=expand("<cword>")<CR><CR>
- nmap <C-_>t :cs find t <C-R>=expand("<cword>")<CR><CR>
- nmap <C-_>e :cs find e <C-R>=expand("<cword>")<CR><CR>
- nmap <C-_>f :cs find f <C-R>=expand("<cfile>")<CR><CR>
- nmap <C-_>i :cs find i ^<C-R>=expand("<cfile>")<CR>$<CR>
- nmap <C-_>d :cs find d <C-R>=expand("<cword>")<CR><CR>
- let g:miniBufExplMapCTabSwitchBufs = 1
- let g:miniBufExplMapWindowNavVim = 1
- let g:miniBufExplMapWindowNavArrows = 1
- nnoremap <silent> <F12> :A<CR>
- nnoremap <silent> <F3> :Grep<CR>
- let g:SuperTabRetainCompletionType=2
- let g:SuperTabDefaultCompletionType="<C-X><C-O>"
- " 自動語法高亮
- syntax on
- " 檢測文件類型
- filetype on
- " 檢測文件類型插件
- filetype plugin on
- " 不設定在插入狀態無法用退格鍵和 Delete 鍵刪除回車符
- set backspace=indent,eol,start
- set whichwrap+=<,>,h,l
- " 顯示行號
- set number
- " 上下可視行數
- set scrolloff=6
- " replace tab with space
- set expandtab
- " 設定 tab 長度為 4
- set tabstop=4
- " 設置按BackSpace的時候可以一次刪除掉4個空格
- set softtabstop=4
- " 設定 << 和 >> 命令移動時的寬度為 4
- set shiftwidth=4
- set smarttab
- set history=1024
- " 不突出顯示當前行
- set nocursorline
- " 覆蓋文件時不備份
- set nobackup
- " 自動切換當前目錄為當前文件所在的目錄
- set autochdir
- " 搜索時忽略大小寫,但在有一個或以上大寫字母時仍大小寫敏感
- set ignorecase
- set smartcase
- " 搜索到文件兩端時不重新搜索
- set nowrapscan
- " 實時搜索
- set incsearch
- " 搜索時高亮顯示被找到的文本
- set hlsearch
- " 關閉錯誤聲音
- set noerrorbells
- set novisualbell
- "set t_vb=
- " 不自動換行
- "set nowrap
- "How many tenths of a second to blink
- set mat=2
- " 允許在有未保存的修改時切換緩沖區,此時的修改由 vim 負責保存
- set hidden
- " 智能自動縮進
- set smartindent
- " 設定命令行的行數為 1
- set cmdheight=1
- " 顯示狀態欄 (默認值為 1, 無法顯示狀態欄)
- set laststatus=2
- "顯示括號配對情況
- set showmatch
- " 解決自動換行格式下, 如高度在折行之後超過窗口高度結果這一行看不到的問題
- set display=lastline
- " 設定配色方案
- colorscheme evening
- " 設置在狀態行顯示的信息
- set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ [%{(&fenc==\"\"?&enc:&fenc).(&bomb?\",BOM\":\"\")}]\ %c:%l/%L%)
- " 顯示Tab符
- set list
- set listchars=tab:\|\ ,trail:.,extends:>,precedes:<
- "啟動時不顯示 捐贈提示
- set shortmess=atl
- "blank 空白
- "buffers 緩沖區
- "curdir 當前目錄
- "folds 折疊
- "help 幫助
- "options 選項
- "tabpages 選項卡
- "winsize 窗口大小
- "slash 轉換文件路徑中的\為/以使session文件兼容unix
- "unix 設置session文件中的換行模式為unix
- set sessionoptions=blank,buffers,curdir,folds,help,options,tabpages,winsize,slash,unix,resize
- " 允許backspace和光標鍵跨越行邊界
- set whichwrap+=<,>,h,l
- " backspace
- set backspace=eol,start,indent
- " 可以在buffer的任何地方使用鼠標(類似office中在工作區雙擊鼠標定位)
- set mouse=a
- set selection=exclusive
- set selectmode=mouse,key
- " 在被分割的窗口間顯示空白,便於閱讀
- set fillchars=vert:\ ,stl:\ ,stlnc:\
- " 高亮顯示匹配的括號
- set showmatch
- " 匹配括號高亮的時間(單位是十分之一秒)
- set matchtime=5
- "編碼設置
- set enc=utf-8
- set fencs=utf-8,ucs-bom,shift-jis,gb18030,gbk,gb2312,cp936
- " set mapleader
- let mapleader=","
- nmap J 5j
- nmap K 5k
- " Ctrl+a
- nmap <silent> <C-a> ggvG$
- " 選中狀態下 Ctrl+c 復制
- vnoremap <c-c> "+y
- " Ctrl+v
- nmap <silent> <C-v> "+p
- " 窗口切換
- nnoremap <c-h> <c-w>h
- nnoremap <c-l> <c-w>l
- nnoremap <c-j> <c-w>j
- nnoremap <c-k> <c-w>k
- " 插入模式下上下左右移動光標
- inoremap <c-h> <left>
- inoremap <c-l> <right>
- inoremap <c-j> <c-o>gj
- inoremap <c-k> <c-o>gk
- " Ctrl+s
- " If the current buffer has never been saved, it will have no name,
- " call the file browser to save it, otherwise just save it.
- "nnoremap <silent> <C-S> :if expand("%") == ""<CR>browse confirm w<CR>else<CR>confirm w<CR>endif<CR>
- "imap <c-s> <c-o><c-s><CR>
- " Use CTRL-S for saving, also in Insert mode
- nmap <C-S> :update<CR>
- vmap <C-S> <C-C>:update<CR>
- imap <C-S> <C-O>:update<CR>
- " C++的編譯和運行
- "map <F6> :call CompileRunGpp()<CR>
- "func! CompileRunGpp()
- "exec "w"
- "exec "!g++ % -o %<"
- "exec "! ./%<"
- "endfunc
- map <F10> :call RunGpp()<cr>
- func! RunGpp()
- exec "w"
- exec "! ./%<"
- endfunc
- "vim plugin setting
- "======================"
- set tags=tags
- set tags+=~/.vim/my-tags/tags
- set tags+=~/.vim/my-tags/stl-tags
- set tags+=~/.vim/my-tags/sys-tags
- set autochdir
- "Update ctags
- map <silent> <F8> :!ctags -R --c++-kinds=+p --fields=+iaS --extra=+q<cr>
- """"""""""""""""""""""""""""""
- " Tag list (ctags)
- """"""""""""""""""""""""""""""
- "if MySys() == "windows" "設定windows系統中ctags程序的位置
- " let Tlist_Ctags_Cmd = ‘ctags‘
- "elseif MySys() == "linux" "設定Linux系統中ctags程序的位置
- let Tlist_Ctags_Cmd = ‘/home/sphinx/.vim/ctags-5.8/ctags‘
- "endif
- let Tlist_Show_One_File = 1 "不同時顯示多個文件的tag,只顯示當前文件的
- let Tlist_Exit_OnlyWindow = 1 "如果taglist窗口是最後一個窗口,則退出vim
- let Tlist_Use_Right_Window = 0 "在右側窗口中顯示taglist窗口
- let Tlist_OnlyWindow=1
- "let Tlist_Use_Right_Window=0
- "let Tlist_Sort_Type=‘name‘
- "let Tlist_Show_Menu=1
- "let Tlist_Max_Submenu_Items=10
- "let Tlist_Max_Tag_length=16 "20
- "let Tlist_Use_SingleClick=0
- "let Tlist_Auto_Open=0
- "let Tlist_Close_On_Select=0
- "let Tlist_File_Fold_Auto_Close=1
- "let Tlist_GainFocus_On_ToggleOpen=0
- "let Tlist_Process_File_Always=1
- "let Tlist_WinHeight=10
- "let Tlist_WinWidth=18
- "let Tlist_Use_Horiz_Window=0
- let Tlist_Auto_Highlight_Tag = 1
- "let Tlist_Auto_Open = 1
- let Tlist_Auto_Update = 1
- let Tlist_Close_On_Select = 0
- let Tlist_Compact_Format = 0
- let Tlist_Display_Prototype = 0
- let Tlist_Display_Tag_Scope = 1
- let Tlist_Enable_Fold_Column = 0
- let Tlist_File_Fold_Auto_Close = 0
- let Tlist_GainFocus_On_ToggleOpen = 1
- let Tlist_Hightlight_Tag_On_BufEnter = 1
- let Tlist_Inc_Winwidth = 0
- let Tlist_Max_Submenu_Items = 1
- let Tlist_Max_Tag_Length = 30
- let Tlist_Process_File_Always = 0
- let Tlist_Show_Menu = 0
- let Tlist_Sort_Type = "order"
- let Tlist_Use_Horiz_Window = 0
- let Tlist_WinWidth = 31
- map <F12> :TlistOpen<CR>
- "OMNI
- "omnicppcoplete
- "-- omnicppcomplete setting --
- set completeopt=menu,menuone
- let OmniCpp_MayCompleteDot = 1
- " autocomplete with .
- let OmniCpp_MayCompleteArrow = 1
- " autocomplete with ->
- let OmniCpp_MayCompleteScope = 1
- " autocomplete with ::
- let OmniCpp_SelectFirstItem = 2
- " select first item (but don‘t insert)
- let OmniCpp_NamespaceSearch = 2
- " search namespaces in this and included files
- let OmniCpp_ShowPrototypeInAbbr = 1
- " show function prototype in popup window
- let OmniCpp_GlobalScopeSearch=1
- let OmniCpp_DisplayMode=1
- let OmniCpp_DefaultNamespaces=["std"]
- set nocp
- filetype plugin on
- "WinManager
- let g:winManagerWindowLayout=‘FileExplorer|TagList‘
- "let g:winManagerWindowLayout=‘FileExplorer|BufExplorer|TagList‘
- let g:persistentBehaviour=0
- let g:winManagerWidth=20
- let g:defaultExplorer=1
- nmap wm :WMToggle<cr>
- "QuickFix
- nmap <F6> :cn<cr>
- nmap <F7> :cp<cr>
- "MiniBufExplorer
- "let g:miniBufExplMapWindowNavVim = 1
- "let g:miniBufExplMapWindowNavArrows = 1
- let g:miniBufExplModSelTarget = 1
- let g:miniBufExplorerMoreThanOne = 2
- let g:miniBufExplModSelTarget = 0
- let g:miniBufExplUseSingleClick = 1
- let g:miniBufExplMapWindowNavVim = 1
- let g:miniBufExplVSplit = 15 "25
- let g:miniBufExplSplitBelow=1
- let g:bufExplorerSortBy = "name"
- autocmd BufRead,BufNew :call UMiniBufExplorer
- map <leader>u :TMiniBufExplorer<cr>
- "AutoClose
- "let g:AutoClosePairs = {‘(‘: ‘)‘, ‘{‘: ‘}‘, ‘[‘: ‘]‘, ‘"‘: ‘"‘, "‘": "‘"}
- let g:AutoClosePairs = {‘(‘: ‘)‘, ‘{‘: ‘}‘, ‘[‘: ‘]‘, ‘"‘: ‘"‘, "‘": "‘"}
- """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " Maintainer:
- " " Geek SphinX
- " " [email protected]
- " "
- " " Version:
- " " 1.0 - Thu Nov 1 17:21:44 CST 2012
- " "
- " """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " Sets how many lines of history VIM has to remember
- " set history=1024
- "
- " " Auto syntax highlight
- " set syntax=on
- "
- " " Check file format
- " filetype on
- "
- " " Enable filetype plugins
- " filetype plugin on
- " filetype indent on
- "
- " " Sets non VI compatible mode
- " set nocompatible
- "
- " " Set to auto read when a file is changed from the outside
- " set autoread
- "
- " " With a map leader it‘s possible to do extra key combinations
- " " like <leader>w saves the current file
- " let mapleader = ","
- " let g:mapleader = ","
- "
- " " Fast saving
- " nmap <leader>w :w<cr>
- " nmap <leader>q :q<cr>
- "
- " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " " => VIM user interface
- " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " " Replace J, K
- " nmap J 5j
- " nmap K 5k
- "
- " " Ctrl+A to select all content in visual mode
- " nmap <silent> <C-a> ggvG$
- "
- " " Ctrl+C to copy
- " vnoremap <C-c> "+y
- "
- " " Ctrl+V to paste
- " nmap <silent> <C-v> "+p
- "
- " " Set 7 lines to the cursor - when moving vertically using j/k
- " set so=7
- "
- " " Turn on the Wild menu
- " set wildmenu
- "
- " " Ignore compiled files
- " set wildignore=*.o,*~,*.pyc
- "
- " "Always show current position
- " set ruler
- "
- " " Height of the command bar
- " set cmdheight=2
- "
- " " A buffer becomes hidden when it is abandoned
- " set hid
- "
- " " Configure backspace so it acts as it should act
- " set whichwrap+=<,>
- " set backspace=indent,eol,start
- "
- " " Ignore case when searching
- " set ignorecase
- "
- " " When searching try to be smart about cases
- " set smartcase
- "
- " " Highlight search results
- " set hlsearch
- "
- " " Makes search act like search in modern browsers
- " set incsearch
- "
- " " Don‘t redraw while executing macros (good performance config)
- " set lazyredraw
- "
- " " For regular expressions turn magic on
- " set magic
- "
- " " Show matching brackets when text indicator is over them
- " set showmatch
- "
- " " How many tenths of a second to blink when matching brackets
- " set mat=2
- "
- " " No annoying sound on errors set noerrorbells
- " set novisualbell
- " set t_vb=
- " set tm=500
- "
- " " Show line number
- " set number
- "
- " " Highlight over 80 columns
- " highlight OverLength ctermbg=red ctermfg=white guibg=#592929
- " match OverLength /\%81v.\+/
- "
- " " Show Tab symbol
- " set list
- " set listchars=tab:\|\ ,trail:.,extends:>,precedes:<
- "
- " " Switch windows
- " nnoremap <C-h> <C-w>h
- " nnoremap <C-l> <C-w>l
- " nnoremap <C-j> <C-w>j
- " nnoremap <C-k> <C-w>k
- "
- " " Move cursor in insert mode
- " inoremap <C-h> <C-o>h
- " inoremap <C-l> <C-o>l
- " inoremap <C-j> <C-o>j
- " inoremap <C-k> <C-o>k
- "
- "
- " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " " => Colors and Fonts
- " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " " Enable syntax highlighting
- " syntax enable
- "
- " "colorscheme desert
- " colorscheme molokai
- " set background=dark
- "
- " " Set extra options when running in GUI mode
- " if has("gui_running"www.wanmeiyuele.cn )
- " set guioptions-=T
- " set guioptions+=e
- " set t_Co=256
- " set guitablabel=%M\ %t
- " endif
- "
- " " Set utf8 as standard encoding and en_US as the standard
- " language
- " set encoding=utf8
- "
- " " Use www.senta77.com/ Unix as the standard file type
- " set ffs=unix,dos,mac
- "
- " " Use Inconsolata as the gui font
- " set guifont=Inconsolata\ 15
- "
- " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " => Text, tab www.fengshen157.com and indent related
- " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " " Use spaces instead of tabs
- " set expandtab
- "
- " " Be smart when using tabs ;)
- " set www.567860.cn smarttab
- "
- " " 1 tab == 4 spaces
- " set shiftwidth=4
- " set tabstop=4
- "
- " " Linebreak on 500 characters
- " set lbr
- " set tw=500
- "
- " set ai "Auto indent
- " set si "Smart indent
- " set wrap www.huarenyl.cn/ "Wrap lines
- "
- "
- " """"""""""""""""""""""""""""""
- " " => Status line
- " """"""""""""""""""""""""""""""
- " " Always show the status line
- " set laststatus=2
- "
- " " Format the status line
- " "set statusline=\ www.hjd1956.com/ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \
- " Line:\ %l
- "
- "
- " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " " => Mouse
- " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " set mouse=a
- " set selection=www.2636666.cn exclusive
- " set selectmode=mouse,key
- "
- " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
- " " => www.taohuayuan178.com Plugins
- " """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
6.插件的下載與安裝。
在~/.vim文件下有建一個doc 文件夾和plugin的文件夾。一般指導性的幫助文件會放到doc文件夾。插件的源碼等會放到plugin中。
可能用到的插件如下:此鏈接中有各種有用的插件大家可以看教程操作。
插件下載和配置:http://blog.csdn.net/wooin/article/details/1858917
用到的vim命令:http://www.thd178.com/ .net/sys/linux/52704.htm
註意事項:let g:winManagerWindowLayout=‘FileExplorer|TagList‘
nmap wm :WMToggle<www.mhylpt.com/ cr>
vim配置入門,到豪華版vim配置