在RedHat5.3上編譯和配置Vim

博主的新Blog地址:http://www.brantchen.com

歡迎訪問:)
---------------------------------------------------------


今天忽然發現我的虛擬機紅帽子5.3上居然沒有Vim,暈~~

唉,要用的時候一點都不方便,沒辦法,重新下個源代碼來編譯一個吧~~

下載的地址很容易找到啦,最新的是7.3: ftp://ftp.vim.org/pub/vim/unix/vim-7.3.tar.bz2

解壓後,簡單看了下./configure -help,然後我的./configure選項如下:

  1. ./configure --prefix=/usr/local --enable-multibyte --with-features=big --disable-selinux

這裏需要說的是,如果你沒有使用 --disable-selinux, 它就會報:

os_unix.c:45:30: error: selinux/selinux.h: No such file   or directory
os_unix.c: In function ‘mch_copy_sec’:
os_unix.c:2615: error: ‘security_context_t’ undeclared (first use in this   function)
os_unix.c:2615: error: (Each undeclared identifier is reported only once
os_unix.c:2615: error: for each function it appears in.)
os_unix.c:2615: error: expected ‘;’ before ‘from_context’
os_unix.c:2616: error: expected ‘;’ before ‘to_context’
os_unix.c:2618: error: ‘from_context’ undeclared (first use in this function)
os_unix.c:2631: error: ‘to_context’ undeclared (first use in this function)
make[1]: *** [objects/os_unix.o] Error 1


好的,我是加了--disable-selinux啦,但是還是報錯了,如下:

checking --with-tlib argument... empty: automatic   terminal library selection

checking for tgetent in -lncurses... no

checking for tgetent in -ltermlib... no

checking for tgetent in -ltermcap... no

checking for tgetent in -lcurses... no

no terminal library found

checking for tgetent()... configure: error: NOT FOUND!

You need to   install a terminal library; for example ncurses.

Or specify   the name of the library with --with-tlib.


谷歌了好久,發現是沒有安裝ncurses那個庫,然後又從小紅帽的安裝盤裏面找到庫文件,執行安裝:

Install ncurses-devel-5.5-24.20060715.x86_64.rpm

重新configure即可。

接下來就按部就班了,執行:

  1. make && make install

哈哈,現在你的Vim7.3就在 /usr/local/了 O(∩_∩)O~


有一點要小心,編譯後的Vim所使用的插件文件是在 /usr/local/share/vim/vim73/plugin目錄,別弄錯了!

現在可以來配置你的.vimrc文件,定製化你的Vim。(我覺得每次定製化自己要用東西都是很享受的,就像裝修一樣,哈哈,扯遠了;))

你可以自己重新寫一個.vimrc,也可以將 /usr/local/share/vim/vim73/裏面的示例vimrc文件作爲模板,看你自己啦。

我是有一個自己用了好久的vimrc文件,直接放到 ~/目錄就好了。

當然,也可以給大家曬曬我的 vimrc文件,可能大家還更關心這個,哈哈:


set nocompatible
source $VIMRUNTIME/vimrc_example.vim
source $VIMRUNTIME/mswin.vim
behave mswin

set nocompatible            " 關閉 vi 兼容模式
syntax on                   " 自動語法高亮
filetype on
filetype plugin on  
colorscheme molokai         " 設定配色方案
set number                  " 顯示行號
set cursorline              " 突出顯示當前行
set ruler                   " 打開狀態欄標尺
set shiftwidth=4            " 設定 << 和 >> 命令移動時的寬度爲 4
set softtabstop=4           " 使得按退格鍵時可以一次刪掉 4 個空格
set tabstop=4               " 設定 tab 長度爲 4
set nobackup                " 覆蓋文件時不備份
set autochdir               " 自動切換當前目錄爲當前文件所在的目錄
filetype plugin indent on   " 開啓插件
set backupcopy=yes          " 設置備份時的行爲爲覆蓋
set ignorecase smartcase    " 搜索時忽略大小寫,但在有一個或以上大寫字母時仍保持對大小寫敏感
set nowrapscan              " 禁止在搜索到文件兩端時重新搜索
set incsearch               " 輸入搜索內容時就顯示搜索結果
set hlsearch                " 搜索時高亮顯示被找到的文本
set noerrorbells            " 關閉錯誤信息響鈴
set novisualbell            " 關閉使用可視響鈴代替呼叫
set t_vb=                   " 置空錯誤鈴聲的終端代碼
" set showmatch               " 插入括號時,短暫地跳轉到匹配的對應括號
" set matchtime=2             " 短暫跳轉到匹配括號的時間
set magic                   " 設置魔術
set hidden                  " 允許在有未保存的修改時切換緩衝區,此時的修改由 vim 負責保存
set guioptions-=T           " 隱藏工具欄
set guioptions-=m           " 隱藏菜單欄
set smartindent             " 開啓新行時使用智能自動縮進
set backspace=indent,eol,start
                           " 不設定在插入狀態無法用退格鍵和 Delete 鍵刪除回車符
set cmdheight=1             " 設定命令行的行數爲 1
set laststatus=2            " 顯示狀態欄 (默認值爲 1, 無法顯示狀態欄)
set statusline=\ %<%F[%1*%M%*%n%R%H]%=\ %y\ %0(%{&fileformat}\ %{&encoding}\ %c:%l/%L%)\
                           " 設置在狀態行顯示的信息
set foldenable              " 開始摺疊
set foldmethod=syntax       " 設置語法摺疊
set foldcolumn=0            " 設置摺疊區域的寬度
setlocal foldlevel=1        " 設置摺疊層數爲
" set foldclose=all           " 設置爲自動關閉摺疊                            
" nnoremap <space> @=((foldclosed(line('.')) < 0) ? 'zc' : 'zo')<CR>
                           " 用空格鍵來開關摺疊


" return OS type, eg: windows, or linux, mac, et.st..
function! MySys()
   if has("win16") || has("win32") || has("win64") || has("win95")
       return "windows"
   elseif has("unix")
       return "linux"
   endif
endfunction

" 用戶目錄變量$VIMFILES
if MySys() == "windows"
   let $VIMFILES = $VIM.'/vimfiles'
   let $VIMCONF  = '_vimrc'
elseif MySys() == "linux"
   let $VIMFILES = $HOME.'/.vim'
   let $VIMCONF  = '.vimrc'
endif

" 設定doc文檔目錄
let helptags=$VIMFILES.'/doc'

" 設置字體 以及中文支持
if has("win32")
   set guifont="Courier New:h12:cANSI"
endif

" 配置多語言環境
if has("multi_byte")
   " UTF-8 編碼
   set encoding=utf-8
   set termencoding=utf-8
   set formatoptions+=mM
   set fencs=utf-8,gbk

   if v:lang =~? '^\(zh\)\|\(ja\)\|\(ko\)'
       set ambiwidth=double
   endif

   if has("win32")
       source $VIMRUNTIME/delmenu.vim
       source $VIMRUNTIME/menu.vim
       language messages zh_CN.utf-8
   endif
else
   echoerr "Sorry, this version of (g)vim was not compiled with +multi_byte"
endif

" 讓 Tohtml 產生有 CSS 語法的 html
" syntax/2html.vim,可以用:runtime! syntax/2html.vim
let html_use_css=1

" Python 文件的一般設置,比如不要 tab 等
autocmd FileType python set tabstop=4 shiftwidth=4 expandtab
autocmd FileType python map <F12> :!python %<CR>

" 選中狀態下 Ctrl+c 複製
vmap <C-c> "+y

" 打開javascript摺疊
let b:javascript_fold=1
" 打開javascript對dom、html和css的支持
let javascript_enable_domhtmlcss=1
" 設置字典 ~/.vim/dict/文件的路徑
autocmd filetype javascript set dictionary=$VIMFILES/dict/javascript.dict
autocmd filetype css set dictionary=$VIMFILES/dict/css.dict
autocmd filetype php set dictionary=$VIMFILES/dict/php.dict

"-----------------------------------------------------------------
" plugin - bufexplorer.vim Buffers切換
" \be 全屏方式查看全部打開的文件列表
" \bv 左右方式查看   \bs 上下方式查看
"-----------------------------------------------------------------

"-----------------------------------------------------------------
" plugin - taglist.vim  查看函數列表,需要ctags程序
" F4 打開隱藏taglist窗口
"-----------------------------------------------------------------
if MySys() == "windows"                " 設定windows系統中ctags程序的位置
   let Tlist_Ctags_Cmd = '"'.$VIMRUNTIME.'/ctags.exe"'
elseif MySys() == "linux"              " 設定windows系統中ctags程序的位置
   let Tlist_Ctags_Cmd = '/usr/bin/ctags'
endif
nnoremap <silent><F4> :TlistToggle<CR>
let Tlist_Show_One_File = 1            " 不同時顯示多個文件的tag,只顯示當前文件的
let Tlist_Exit_OnlyWindow = 1          " 如果taglist窗口是最後一個窗口,則退出vim
let Tlist_Use_Right_Window = 1         " 在右側窗口中顯示taglist窗口
let Tlist_File_Fold_Auto_Close=1       " 自動摺疊當前非編輯文件的方法列表
let Tlist_Auto_Open = 0
let Tlist_Auto_Update = 1
let Tlist_Hightlight_Tag_On_BufEnter = 1
let Tlist_Enable_Fold_Column = 0
let Tlist_Process_File_Always = 1
let Tlist_Display_Prototype = 0
let Tlist_Compact_Format = 1

"-----------------------------------------------------------------
" plugin - mark.vim 給各種tags標記不同的顏色,便於觀看調式的插件。
" \m  mark or unmark the word under (or before) the cursor
" \r  manually input a regular expression. 用於搜索.
" \n  clear this mark (i.e. the mark under the cursor), or clear all highlighted marks .
" \*  當前MarkWord的下一個     \#  當前MarkWord的上一個
" \/  所有MarkWords的下一個    \?  所有MarkWords的上一個
"-----------------------------------------------------------------


"-----------------------------------------------------------------
" plugin - NERD_tree.vim 以樹狀方式瀏覽系統中的文件和目錄
" :ERDtree 打開NERD_tree         :NERDtreeClose    關閉NERD_tree
" o 打開關閉文件或者目錄         t 在標籤頁中打開
" T 在後臺標籤頁中打開           ! 執行此文件
" p 到上層目錄                   P 到根目錄
" K 到第一個節點                 J 到最後一個節點
" u 打開上層目錄                 m 顯示文件系統菜單(添加、刪除、移動操作)
" r 遞歸刷新當前目錄             R 遞歸刷新當前根目錄
"-----------------------------------------------------------------
" F3 NERDTree 切換
map <F3> :NERDTreeToggle<CR>
imap <F3> <ESC>:NERDTreeToggle<CR>

"-----------------------------------------------------------------
" plugin - NERD_commenter.vim   註釋代碼用的,
" [count],cc 光標以下count行逐行添加註釋(7,cc)
" [count],cu 光標以下count行逐行取消註釋(7,cu)
" [count],cm 光標以下count行嘗試添加塊註釋(7,cm)
" ,cA 在行尾插入 /* */,並且進入插入模式。 這個命令方便寫註釋。
" 注:count參數可選,無則默認爲選中行或當前行
"-----------------------------------------------------------------
let NERDSpaceDelims=1       " 讓註釋符與語句之間留一個空格
let NERDCompactSexyComs=1   " 多行註釋時樣子更好看

"Set mapleader
let mapleader = ","

"Fast reloading of the .vimrc
map <silent> <leader>ss :source $VIM/$VIMCONF<cr>
"Fast editing of .vimrc
map <silent> <leader>ee :e $VIM/$VIMCONF<cr>
"When .vimrc is edited, reload it
autocmd! bufwritepost $VIMCONF source $VIM/$VIMCONF

"-----------------------------------------------------------------
" plugin - DoxygenToolkit.vim  由註釋生成文檔,並且能夠快速生成函數標準註釋
"-----------------------------------------------------------------
let g:DoxygenToolkit_authorName="Asins - asinsimple AT gmail DOT com"
let g:DoxygenToolkit_briefTag_funcName="yes"
"map <leader>da :DoxAuthor<CR>
map <leader>df :Dox<CR>
map <leader>db :DoxBlock<CR>
map <leader>dc a /*  */<LEFT><LEFT><LEFT>

"-----------------------------------------------------------------
" plugin – checksyntax.vim    JavaScript常見語法錯誤檢查
" 默認快捷方式爲 F5
"-----------------------------------------------------------------
let g:checksyntax_auto = 0 " 不自動檢查

"-----------------------------------------------------------------
" plugin - snipMate.vim    自動補全插件 (No need configuration)
" (I discard NeoComepeCache)
"-----------------------------------------------------------------

"-----------------------------------------------------------------
" plugin - autocomplpop.vim  (No need configuration)
"-----------------------------------------------------------------

" save the file
" map <leader>w :w<cr>
map ,w :w<cr>
" quit
map ,q :q<cr>
" save and quit
map ,z ZZ
set fileformats=unix,dos,mac
nmap <leader>fd :se fileformat=dos<CR>
nmap <leader>fu :se fileformat=unix<CR>
" Buffers操作快捷方式!
nnoremap <C-RETURN> :bnext<CR>
nnoremap <C-S-RETURN> :bprevious<CR>

" Tab操作快捷方式!
nnoremap <C-TAB> :tabnext<CR>
nnoremap <C-S-TAB> :tabprev<CR>

"關於tab的快捷鍵
" map tn :tabnext<cr>
" map tp :tabprevious<cr>
" map td :tabnew .<cr>
" map te :tabedit
" map tc :tabclose<cr>

"窗口分割時,進行切換的按鍵熱鍵需要連接兩次,比如從下方窗口移動
"光標到上方窗口,需要<c-w><c-w>k,非常麻煩,現在重映射爲<c-k>,切換的
"時候會變得非常方便.
nnoremap <C-h> <C-w>h
nnoremap <C-j> <C-w>j
nnoremap <C-k> <C-w>k
nnoremap <C-l> <C-w>l

"一些不錯的映射轉換語法(如果在一個文件中混合了不同語言時有用)
nnoremap <leader>1 :set filetype=xhtml<CR>
nnoremap <leader>2 :set filetype=css<CR>
nnoremap <leader>3 :set filetype=javascript<CR>
nnoremap <leader>4 :set filetype=php<CR>

" use Ctrl+[l|n|p|cc] to list|next|previous|jump to count the result
" map <C-x>l <ESC>:cl<CR>
" map <C-x>n <ESC>:cn<CR>
" map <C-x>p <ESC>:cp<CR>
" map <C-x>c <ESC>:cc<CR>

大家不要誤會上面的配置全部是我原創的哈,只是我綜合了好幾個網絡上我覺得寫得好的vimrc後我整合了下下,哈哈,發揮開源共享精神嘛O(∩_∩)O~

配置裏面用到很多插件,這個太多了,但是都比較簡單,看他們的help就曉得怎麼用了,網上也很容易找到,我就不再一一講解。

需要提一下的是,用到了ctags插件,這個一般機器上都沒有ctags,你都需要找到ctags源碼編譯一個: http://sourceforge.net/projects/ctags/files/ctags/5.8/ctags-5.8-1.src.rpm/download

編譯這個很簡單,如下:

./configure && make && make install

編譯好的ctags複製到 /usr/bin/下面,然後你的vimrc就可以用ctags的功能了哈。



基本上就是這樣,enjoy it

O(∩_∩)O~

---------------------------------------------------------
博主的新Blog地址:http://www.brantchen.com

歡迎訪問:)



發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章