星期三, 4月 18, 2007

FreeBSD 更新 port tree 問題("missing key: categories: Cannot read the portsdb")

  前幾天為了到 Server 上做某些修正作業,想到 portupgrade 可能有點舊,乾脆升級 portupgrade 後再順便做一次 portupgrade -Fuv vim-lite 卻發現一直無法成功 upgrade,訊息如下:

myserver# portupgrade -Fuv vim-lite
---> Session started at: Wed, 18 Mar 2007 16:08:55 +0800
[missing key: categories] [Updating the portsdb in /usr/ports ... - 16648 port entries found .........1000.........2000.........3000.........4000.........5000.........6000.........
7000.........8000.........9000.........10000.........11000.........12000.........13000
.........14000.........15000.........16000........... done]
missing key: categories: Cannot read the portsdb!
database file error

  第一個想到的問題是 /var/db/pkg/pkgdb.db 是不是掛了,但砍了再重建還是一樣;第二個想到的是 /usr/ports/INDEX*.db,結果還是沒有解決問題。最後沒辦法了,把 UPDATING 翻來看看,眼睛停在這裡許久:

20070102:
AFFECTS: users of sysutils/portupgrade
AUTHOR: sem@FreeBSD.org

If you have a problem with upgrading the tools from version 2.2.1 and less,
remove the package with pkg_delete portupgrade\* command and reinstall it
from scratch. Remove /usr/ports/INDEX*.db and run portsdb -u.

  這時才恍然大悟,很久沒看 UPDATING 果然會出狀況,於是依序進行下例 Shell script,我的 package database 才活了過來,簡直是痛哭流涕。

# pkg_delete portupgrade\*
# rm /usr/ports/INDEX*.db
# cd /usr/ports/ports-mgmt/portupgrade
# make install clean
# portsdb -u

星期五, 4月 13, 2007

Vim 巨集應用 Part.1 for C++

  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <ctime>

  寫程式時常常會遇到以上這樣重覆著 #inclu.... #inclu... 的輸入動作,這是非常無聊的一件事。我們來看看如何利用 Vim 強悍的巨集錄製功能來改善這類的輸入動作。
  首先,把一定得自己動手打字的部份先完成,利用 i 進入 insert-mode,bla bla ....,完成後 <esc>回到 normal-mode:
  1. iostream
  2. vector
  3. algorithm
  4. ctime
  使用 :1 <enter> 移到第一列,按下 qa 啟動巨集錄製功能(會將錄製內容存放在 a 暫存),分別輸入 I#include <<esc>A><esc>j ,然後輸入 q 結束錄製。完成後您的程式碼應該長這樣:
  1. #include <iostream>
  2. vector
  3. algorithm
  4. ctime
  接下來要怎麼把剛剛的動作應用在下面的三列上呢?我們現在的游標應該是停在第二列,請按下 3@a ,您的程式碼應該會被修改為這樣:
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <ctime>
  感受到 Vim 的 power 嗎?這只不過是冰山一角而已,它還有很多的功能等著我們將它變成日常的習慣,就如 Bram Moolenaar 所說的:make it a habit

星期三, 4月 11, 2007

習慣有 Vim

  某一天的上午,照往常的在公司開啟電腦工作,打開工作必用的 Lotus Notes client,例行性的開始處理公務 Mail,也在桌面上下載了幾個 .txt 檔,也很直覺的『點兩下』以M$的記事本打開編輯。
  就在這個時後發生一件令人驚訝的事,記事本不聽話了,按了方向鍵後,不但沒有移到應該到位的位置,反而出現 "jjjjjAbrown",這時的大鳥才驚覺『已習慣用 Vim 』這件事實。老實說,Vim 真的改變了大鳥在文字編輯器上的操作習慣,用 Vim 寫程式或文字檔已是一種生活樂趣。
  在 Vim 的官方網站有這樣的一份 演講稿,所推行的就是『習慣用 Vim』,就如同演講內容,只要能突破編輯上最耗時間的關鍵,就會把 Typing 的效率提升到一定的水準,而不是把時間浪費在重覆性且乏味的編修工事上。