顯示廣告
隱藏 ✕
※ 本文為 cuteman0725 轉寄自 ptt.cc 更新時間: 2012-10-23 07:31:17
看板 EZsoft
作者 Bellkna (Belldandy)
標題 [教學] GVIM(VIM) PORTABLE 編譯
時間 Mon Oct 22 19:42:21 2012


前言:
本來想要編譯 64bit 的 gvim 來使用
不過遇到一些問題 後來還是用 32bit (為了某些好用的 scrpit)
加上官網的安裝檔一直沒更新 patch 所以就想自己編譯的念頭
而且編好的程式可以 portable 使用
(有些 script 要 python 支援的 就必需該電腦有裝的才能使用)
下面 2 種版本(32bit or 64bit)的編譯方法都會講到

開始前要安裝一些軟體
首先 安裝 Mercurial
官網 : http://mercurial.selenic.com/
下載頁面 : http://mercurial.selenic.com/downloads/
按照喜好選擇安裝檔下載即可 這邊 32bit or 64bit 不影響編譯
Mercurial 2.3.2 MSI installer - x64 Windows - requires admin rights
(我是裝這個)
這個是用來下載 vim 的原始碼
也可以官網下載原始碼再來 patch
不過 windows 下 patch 很麻煩 (而且不一定會過 ; linux 下 patch 是沒問題)
用這個比較方便 安裝時用預設值安裝即可
裝好 Mercurial 後 根據 vim 官網上的資料 http://www.vim.org/mercurial.php
在命令列提示字元下 輸入下面這行(記得先切換到想下載到的資料夾)
hg clone https://vim.googlecode.com/hg/ vim
之後就等它下載完

原始碼下載完畢後
接著安裝 TDM-GCC (也可以用 MINGW 只是 MINGW 沒有離線安裝包 這個比較方便)
官網 : http://tdm-gcc.tdragon.net/ http://sourceforge.net/projects/tdm-gcc/
 
TDM-GCC MinGW Compiler | Free Development software downloads at SourceForge.net
[圖]
The most recent stable releases from the GCC compiler project, for 32-bit and 64-bit Windows, cleverly disguised with a real installer & updater. ...
 
下載頁面 :
http://tdm-gcc.tdragon.net/download
http://sourceforge.net/projects/tdm-gcc/files/TDM-GCC Installer/
TDM-GCC MinGW Compiler - Browse /TDM-GCC Installer at SourceForge.net The most recent stable releases from the GCC compiler project, for 32-bit and 64-bit Windows, cleverly disguised with a real installer & updater. ...
 
選一個連結即可 指向的地方是同一個
視要編譯的版本(32or64) 下載對應的編譯器
32bit : tdm-gcc-4.7.1-2.exe
64bit : tdm64-gcc-4.7.1-3.exe
視要編譯的版本安裝一個即可
(2 個都裝也沒問題 只是使用上別用錯就好 編譯時會 error)
這個安裝也是用預設值安裝即可

TDM-GCC 裝好後
就可以開始編譯 vim 了
執行 程式集 裡面的 MinGW Command Prompt
(視編譯版本選擇對應的版本 MinGW32 or MinGW64)
然後 切換到 vim 原始碼的目錄 src
執行下面其中一行(
mingw32-make.exe -f Make_ming.mak FEATURES=HUGE (32 bit)
mingw32-make.exe -f Make_ming.mak FEATURES=HUGE ARCH=x86-64 (64 bit)
FEATURES 參數可以視需要而調整 我是直接用 HUGE 比較省事
(想研究其它參數的 可以看 Make_ming.mak 的內容研究)
接下來就等它編譯好 約5分鐘左右(Athlon II X4 630)

編譯好後(沒跳啥 error 的訊息就沒問題)
接下來就是把 編好的執行檔 copy 到別的目錄上使用
也可以直接使用 src 內的 gvim
不過 還是把需要的東西 copy 到另一個目錄上
使用比較方便 也比較不佔空間
根據 vim wiki 上的說明
http://vim.wikia.com/wiki/Version_independent_installation_of_Vim_on_Windows
Version independent installation of Vim on Windows - Vim Tips Wiki
[圖]
The installer and the zip versions of the (g)vim distributions for MS-Windows install (g)vim in... ...
 
我按照內容 整理出下面所需要的目錄結構

vim\vim73\runtime (資料夾)
vim\vim73\gvim.exe
vim\vim73\gvimext.dll
vim\vim73\vimrun.exe
vim\vim73\xxd.exe

runtime 直接從 vim 的目錄 複制
gvim.exe 和 vimrun.exe 從 vim\src 複制
xxd.exe 從 vim\src\xxd 複製
gvimext.dll 從 vim\src\GvimEx\ 複制
照這個目錄結構 放置檔案和資料夾 就是可以 portable 的 gvim

vim 常用的 vimrc 就放在 vim 目錄裡就可以被讀取到
(這邊和安裝的 gvim 有所不同 檔名為 vimrc 安裝的話會是 .vimrc)

雖說這樣子已經是可以使用的 gvim
不過 使用 diff 時 會有 error 產生
(安裝版的會用 mydiff() 此函數來解決)
不過 根據這篇提到
http://vim.wikia.com/wiki/Running_diff
Running diff - Vim Tips Wiki
[圖]
Vim is able to "diff" files (show the differences between similar files) using an external diff... ...
 
建議的解決方法 還是下載 GnuWin 裡面的 diffutils 來使用
官網 :
http://gnuwin32.sourceforge.net/
GnuWin32
GnuWin32 provides Win32 (MS Windows 95 / 98 / ME / NT / 2000 / XP / 2003 / Vista / 2008) ports of tools with a GNU or similar open source license. ...
 
http://sourceforge.net/projects/gnuwin32/
GnuWin | Free Development software downloads at SourceForge.net
[圖]
GnuWin provides Win32-versions of GNU tools, or tools with a similar open source licence. The ports are native ports, relying only on libraries … ...
 
下載網址 : (選最新版的 bin 下載即可)
http://sourceforge.net/projects/gnuwin32/files/diffutils/
GnuWin - Browse /diffutils at SourceForge.net
GnuWin provides Win32-versions of GNU tools, or tools with a similar open source licence. The ports are native ports, relying only on libraries … ...
 
因為 diff.exe 需要下面這2個 dll 才能工作 所以下面這2個也得下載
http://sourceforge.net/projects/gnuwin32/files/libiconv/
GnuWin - Browse /libiconv at SourceForge.net
GnuWin provides Win32-versions of GNU tools, or tools with a similar open source licence. The ports are native ports, relying only on libraries … ...
 
http://sourceforge.net/projects/gnuwin32/files/libintl/
GnuWin - Browse /libintl at SourceForge.net
GnuWin provides Win32-versions of GNU tools, or tools with a similar open source licence. The ports are native ports, relying only on libraries … ...
 

這是我下載使用的版本
diffutils-2.8.7-1-bin.zip
libiconv-1.9.2-1-bin.zip
libintl-0.14.4-bin.zip

從裡面解壓出 以下這3個檔案
diff.exe
libiconv2.dll
libintl3.dll
然後和 gvim 放置在同一目錄即可
這樣 diff 就能正常使用

接下來 稍微提一下 script 安裝使用上的問題
自行編譯出來的 gvim 使用的目錄結構是以 gvim 執行檔所在目錄為主
以安裝這個為例子 pathogen.vim
http://www.vim.org/scripts/script.php?script_id=2332

pathogen.vim 所要放置的目錄為
vim\vim73\runtime\autoload
不過 放這邊的話 我們要更新 gvim 時
不能直接覆蓋那 4個檔案+1個資料夾
所以改放這邊
vim\vimfiles\autoload (自行建立)
而 pathogen 預設的讀取目錄也會在這
vim\vimfiles\bundle

文章到這邊 應該可以建立出一個能使用的 gvim 才對
我應該沒有漏掉什麼才對XD
如果有錯誤的地方 麻煩指正 謝謝
(其實主要是寫一下當筆記 怕自己忘了怎麼弄的)

最後提一下 為什麼我還是用 32bit 的 gvim
因為這一個 script
http://sjl.bitbucket.org/gundo.vim/
介紹影片 :
http://vimcasts.org/episodes/undo-branching-and-gundo-vim/

當初看了這個 覺得好棒!
因為這個 script 需要 python 才能工作
所以編譯時就加入了 python 的支援
可是 編好的 gvim 只要執行 python 相關程式就當機了
結果 不斷的嚐試+GOOGLE後
發現 64bit 的 python 和 MinGW(TDM-GCC) 有點問題(可能用其它編譯器會沒問題)
最後 我安裝 32bit 的 python 就沒問題
Gundo 只支援 python 2.7 想使用 3.3 的話 好像得改程式碼
想同時用 2.7 和 3.3 的話得開 dynamic
只是我這樣編出來的 gvim 測試 python 還是會當
所以 為了省事 我只用了 python 支援 編譯時加入這行
PYTHON=C:\Python27 PYTHON_VER=27 DYNAMIC_PYTHON=no

python3的話用這行 2個不能同時開
PYTHON3=C:\Python33 PYTHON3_VER=33 DYNAMIC_PYTHON3=no

記得要去 python 下載安裝檔並安裝 才能加入 python 的支援
官網 : http://www.python.org/
Python Programming Language – Official Website
Home page for Python, an interpreted, interactive, object-oriented, extensible
programming language. It provides an extraordinary combination of clarity and
versatility, and is free and comprehensively ported. ...
 

參考資料補充:
http://vim.wikia.com/wiki/Category:Building_Vim
http://vim.wikia.com/wiki/Build_Python-enabled_Vim_on_Windows_with_MinGW
Build Python-enabled Vim on Windows with MinGW - Vim Tips Wiki
[圖]
Getting Python scripting in Vim on Windows can be a bit tricky, see . Python must be installed.... ...
 

--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 111.252.213.22

--
※ 看板: P_qman 文章推薦值: 0 目前人氣: 0 累積人氣: 626 
分享網址: 複製 已複製
r)回覆 e)編輯 d)刪除 M)收藏 ^x)轉錄 同主題: =)首篇 [)上篇 ])下篇