2013年2月23日 星期六

使用 pathogen 管理 VIM 的插件 (plugin)

幫 VIM 添加 SrcExpl 這個插件時,一下子將檔案複製到 ~/.vim/doc 目錄,又一下子將檔案複製到 ~/.vim/plugin 目錄的,現在使用的插件數量少倒還沒什麼,我想到將來若 VIM 裡安排了一大堆插件後,若要搞明白那個檔案是那個插件、又那個檔案是那個版本的,光是想像就頭疼了。繼續在網上爬了爬文,找到 pathogen 這個插件,它可以用來幫我們簡單地管理 VIM 的插件,只要將插件在 ~/.vim/bundle 目錄下建立目錄扔進去就搞定,要刪除也不過將那個插件的目錄刪除就行了。

既然有這麼方便的插件,當然要安裝來使用囉!仔細再讀讀說明,只要在 ~/.vim 下建立兩個目錄,一個是放置 pathogen.vim 的 ~/.vim/autoload 目錄,而另一個用來放置插件的 ~/.vim/bundle 目錄。然後將 pathogen.vim 下載複製到 ~/.vim/autoload 目錄內。

接著修改 ~/.vimrc 這個檔案,在「最前面」加上一行 execute pathogen#infect() 就搞定了。最後依據說明及反覆驗證的結果,我加了幾下這兩行:

execute pathogen#infect()
filetype plugin indent on 

另外,在爬文找到的「使用github管理VIM」這篇文章更乾脆直接利用 github 來管理 VIM 的設定檔 .vimrc 和所有的插件,不過我目前在 VIM 使用的插件只有 SrcExpl 這一組,就暫時不搞 github 了。

延伸閱讀:

使用 SrcExpl 強化 VIM 的 Source Explorer 能力

雖然平時比較習慣使用 Eclipse,但一直以來免不了要在 Terminal 下修改一些程式碼,所以偶爾也用用 VIM 這個編輯器。這陣子爬了爬文,也試著將 VIM 加了些外掛功能,也讓 VIM 用起來更方便些。首先要搞的就是讓 VIM 更貼近 EclipseSource Insight 些。

爬文後,找到一個評價頗高的外掛,就是這個 SrcExpl。

首先,下載了 SrcExpl 最新版本 (5.1) 的 SrcExpl-5.1.zip,將解壓縮後得到的 doc 及 plugin 兩個目錄複製到 ~/.vim 目錄內。

接著,根據 SrcExpl 的說明,若想讓 VIM 像 Source Insight 一樣工作,還需要一個外掛 Trinity (trinity.vim),於是再下載 Trinity 2.0 的 Trinity-2.0.zip,並將解壓縮得到的 NERD_tree.vim 及 trinity.vim 兩個檔案複製到 ~/.vim/plugin 目錄內。

接著,分別依照 SrcExpl 及 Trinity 的說明將以下兩段設定寫到 ~/.vimrc 檔裡。

SrcExpl :

" // The switch of the Source Explorer 
nmap <F8> :SrcExplToggle<CR> 

" // Set the height of Source Explorer window 
let g:SrcExpl_winHeight = 8 

" // Set 100 ms for refreshing the Source Explorer 
let g:SrcExpl_refreshTime = 100 

" // Set "Enter" key to jump into the exact definition context 
let g:SrcExpl_jumpKey = "<ENTER>" 

" // Set "Space" key for back from the definition context 
let g:SrcExpl_gobackKey = "<SPACE>" 

" // In order to Avoid conflicts, the Source Explorer should know what plugins 
" // are using buffers. And you need add their bufname into the list below 
" // according to the command ":buffers!" 
let g:SrcExpl_pluginList = [ 
        \ "__Tag_List__", 
        \ "_NERD_tree_", 
        \ "Source_Explorer" 
    \ ] 

" // Enable/Disable the local definition searching, and note that this is not 
" // guaranteed to work, the Source Explorer doesn't check the syntax for now. 
" // It only searches for a match with the keyword according to command 'gd' 
let g:SrcExpl_searchLocalDef = 1 

" // Do not let the Source Explorer update the tags file when opening 
let g:SrcExpl_isUpdateTags = 0 

" // Use 'Exuberant Ctags' with '--sort=foldcase -R .' or '-L cscope.files' to 
" //  create/update a tags file 
let g:SrcExpl_updateTagsCmd = "ctags --sort=foldcase -R ." 

" // Set "<F12>" key for updating the tags file artificially 
let g:SrcExpl_updateTagsKey = "<F12>"  

Trinity :

" Open and close all the three plugins on the same time 
nmap <F8>  :TrinityToggleAll<CR> 

" Open and close the Source Explorer separately 
nmap <F9>  :TrinityToggleSourceExplorer<CR> 

" Open and close the Taglist separately 
nmap <F10> :TrinityToggleTagList<CR> 

" Open and close the NERD Tree separately 
nmap <F11> :TrinityToggleNERDTree<CR>  

接著,再根據 Trinity 的說明下載了 Taglist 的 taglist_45.zip,並將解壓縮得到的 plugin/taglist.vim 及 doc/taglist.txt 兩個檔案分別複製到 ~/.vim/plugin 及 ~/.vim/doc 目錄內。

接著再修改 ~/.vimrc,讓 VIM 支援滑鼠的動作。爬文的結果多半將它寫成 set mouse=a,但由於平時我習慣使用 PuTTY 連上 Linux 主機,這樣一來會變得不好用,所以我將它改成以下這樣:

set mouse=n

如此一來,在 VIM 裡按 F8 鍵時,就會開啟如下圖的分割視窗,

若是再按下 F10 鍵,則會執行 ctags 的指令來建立標籤索引檔,讓 VIM 搭配 ctags 來查找程式碼。

ctags --sort=foldcase -R . 

其中對於 F10 鍵的這個功能就讓我有點疑惑了,改天再來仔細看看這幾個外掛的細節吧!

最後另外一點,在 Trinity 2.0 裡包含了一個 NERD_tree.vim,但打開看了看,它應該是 2008 年 7 月 20 日發表的 2.13.0 版,不過在 NERD tree 的網頁上目前可以看到最新版本是 4.2.0 版。我在 NERD tree 的網頁下載了 2.13.0 版來看 Trinity 2.0 的 NERD_tree.vim 比較了一下,這兩個檔案的內容有些許的不同,我想應該是 Trinity 2.0 的維護者 Wenlong Che 作了修改吧!因此,我暫時沒有將 NERD tree 更換成 4.2.0 版。

延伸閱讀:

2013年1月31日 星期四

為 X86 版本的 Android 4.2 添加中文輸入法

X86 版本的 Android 4.2.1 (Jelly Bean) 裡預設只打包了「谷歌拼音輸入法」,但筆者最熟悉的是「倉頡輸入法」,所以翻看了一下,決定將 LIME IME 放進去。

首先,瀏覽 http://code.google.com/p/limeime/ 並下載 LIMEHD_391_334.apk 這個檔案,這是 LIME IME 最新版本的 APK 檔。

然後,將 LIMEHD_391_334.apk 這個檔案放到 ANDROID-X86 原始程式碼的 device/generic/x86/app/ 目錄裡。

依據 device/generic/x86/app/README 的說明,放在這裡的 APK 檔將在編譯時自動被添加進去。

#
# Put your apks here. The Android-x86 build system will add them automatically.
#

最後,重新編譯出 android_x86.iso,執行後就可以發現多了「LIME-HD」這個輸入法了。

下圖是示範使用 LIME-HD 輸入中文的畫面。

2013年1月26日 星期六

在 Oracle VM VirtualBox 玩 Android 4.2 的幾點筆記

這回用 Oracle VM VirtualBox 玩 Android 4.2,大致整理了一下在 VirtualBox 裡對虛擬機器的設定。

首先,在 "試玩 X86 版本的 Android 4.2.1 (Jelly Bean)" 這篇文章裡,我提到了要「停用滑鼠整合」。也可以換成方式,在「系統」裡將「啟動絕對指標裝置」取消勾選,這個取消模擬 USB HID 的支援。如此,在「USB」裡也可以將「啟用 USB 控制器」取消勾選了。

在「顯示」裡,要記得勾選「啟用 3D 加速」。

在「音效」裡,要將音效控制器改成「SoundBlaster 16」。

在「網路」裡,將介面卡類型選擇「PCnet-FAST III (Am79C973)」。

其中,音效控制器和網路介面卡的設定應該可以不管,基本上我是依之前試玩 Android 4.0 時的習慣設定。目前 android_x86 目的在建立 universal image,有興趣的朋友也可以試試其它的控制器設定。

延伸閱讀:

將 X86 版本的 Android 4.2 安裝到硬碟上

在 "試玩 X86 版本的 Android 4.2.1 (Jelly Bean)" 這篇文章裡,是直接從光碟啟動 Android 4.2。

這篇文章裡,我打算記錄將 Android 4.2 安裝到硬碟的過程。

在啟動後,選擇「Installation」:

接著,選擇「Create/Modify partitions」:

此時,會進入 cfdisk 的畫面,我將硬碟分割成兩個磁區,並將其中一個指定為 swap。這只是一個習慣,只要是安裝基於 Linux Kernel 的系統時,我習慣會保留約 1GB 的空間指定為 swap,即使它不見得有作用。

接著,將 Android-X86 安裝到 sda1 這個磁區,並將該磁區格式化成 ext3:

接著,選擇安裝 GRUB:

將 /system 這個路徑指定為 read-write。印象中,之前接觸過一些 ARM 開發板上的 Android 移植, /system 這個路徑是被掛載成唯讀的,不過若將它指定成可讀寫時,在測試及 debug 時也相對方便些。

安裝完成後,可以將虛擬機器關閉,然後在設定裡將 ISO 檔從光碟機中移除,接著就可以直接由硬碟啟動 Android-X86 了。

試玩 X86 版本的 Android 4.2.1 (Jelly Bean)

幾天前在 Android-x86 的 Google Group 上看到 "jb-x86 source is ready" 這篇文章。

Hi,
I've pushed all jb-x86 branches to our main git server.
As usual, you can get it by

repo init -u http://git.android-x86.org/manifest -b jb-x86
repo sync

You will note there is only one target, android_x86.
This is the first step of the plan to create a universal image.
Though it's still far from complete.
I'll describe more details later.

SourceForge mirror is not synced yet.
Will try to do it when I have time.

-- 
Chih-Wei
Android-x86 project
http://www.android-x86.org 

依文章的說明下載了 Android 4.2 (Jelly Bean) 的 X86 版本:

$ repo init -u http://git.android-x86.org/manifest -b jb-x86
$ repo sync

然後,再依以下指令編譯得到 android_x86.iso 這個檔案。

$ . build/envsetup.sh
$ lunch android_x86-eng
$ time make -j2 iso_img

其中,在執行 lunch android_x86-eng 指令時,也可以選擇使用 android_x86-user 或 android_x86-userdebug。

以下是執行 make 指令後的訊息:

PLATFORM_VERSION_CODENAME=REL
PLATFORM_VERSION=4.2.1
TARGET_PRODUCT=android_x86
TARGET_BUILD_VARIANT=eng
TARGET_BUILD_TYPE=release
TARGET_BUILD_APPS=
TARGET_ARCH=x86
TARGET_ARCH_VARIANT=x86
HOST_ARCH=x86
HOST_OS=linux
HOST_OS_EXTRA=Linux-2.6.32-5-amd64-x86_64-with-debian-6.0.6
HOST_BUILD_TYPE=release
BUILD_ID=JOP40D
OUT_DIR=out

Android 從 4.0 以後,編譯都挺花時間的,我的 Thinkpad X61 使用 Intel(R) Core(TM)2 Duo CPU T7300 @ 2.00GHz 及 4GB 記憶體,第一次編譯大概要半個工作天左右。

這次我改用 Oracle VM VirtualBox 來玩 X86 版本的 Android 4.2。

首先在 VirtualBox 建立一個「Other Linux」的虛擬機器:

在「顯示」這欄裡將「啟用 3D 加速」勾選起來:

在「存放裝置」這欄,將 android_x86.iso 掛載到光碟機上:

在「音效」裡,將音效控制器改成「SoundBlaster 16」:

在「網路」裡,先使用 NAT 模式,至於介面卡類型則選擇了「PCnet-FAST III (Am79C973)」:

接著就可以啟動虛擬機器了:

最後,在 VirtualBox 裡要記得「停用滑鼠整合」:

參考文章: