Thursday, September 13, 2007

OK, I will do second backup NOW!

Last night I came across a sad story about a guy who loose almost all of his data, including some voice files of his passed mother.

Well, I do have backup. For work, I got one extra hard disk in Mac Pro, which got synchronized with the main HD whenever I am having lunch in weekdays. At home, I have tons of old harddisks storing my huge music library. In my Linux server, I scheduled important files backup to another drive every single night. But is it a bulletproof solution? I know it's not.

What if my office got fire? Then both the HD in Mac Pro will be gone. What if my home got fire or theft? Then all my personal data and work are gone. OK, may be these are a little bit extreme. How about if the power supply of my computer got surged? The result is the same. One backup = no backup.

So I just subscribed Mozy. It recently got a Mac backup solution. For about USD5 per month, I have unlimited storage for backup. Though it may take month to perform a complete backup of all my stuff (well, the approximate upload rate stays at about 60KB/s), for long term, it should be a bulletproof solution. Just no need to get worried about backup anymore.

I am glad that I have read the story, and even more glad that I have made the decision immediately.

Thursday, September 06, 2007

iPod touch - not good enough


Steve Jobs just announced the iPod touch today. I don't like it, because...

1. 16G ?
For a 80G iPod user, I am already filled my 5.5G iPod with over 60G of Apple Lossless audio files. How could I accept an brand new iPod with 16G space? OK, the new iPod Classic has 160G. But we need a better PMP. Only the new iPod touch can deliver this. So should we buy both iPod touch and the iPod classic together? Hey Steve Jobs, I want an at least 80G iPod touch!

2. WiFi?
May be in States this is practical. But in HK, only having WiFi is not enough! Give me bluetooth for both network access and A2DP!

3. iTunes WiFi store?
Where is it? (in HK)

4. Starbuck?
All I can see the plans for implementing "Starbuck" music feature is in the States. Where is it?



As iPod get more functionalities builtin, I am more tempted to perform a comparison with my Dopod U1000.

a) Both can play music
iPod has better UI and audio output quality. But U1000 can play much more variety of audio types. (ogg, flac, wma...)

b) Both can play video
But U1000 can play more video types (DivX, Xvid, wmv...)

c) Both have WIFI

d) Both have browsers
May be the user experience in Safari is more pleasing. But Opera Mobile is not that bad!

e) Both can play YouTube

f) Both is touch screen, and wide screen
Just that iPod is multi-touch, and U1000 is argh...single touch. ;)

g) a2dp?
U1000 only.

h) gps?
U1000 only.

i) HSDPA?
U1000 only.

j) Camera?
U1000 only.

k) Install new applications?
Urgh...as iPhone will soon be able to easily to have this. I think iPod touch will have the same chance. But installing new application for Windows mobile is just a piece of cake, plus there are so many applications out there...

l) Storage size?
iPod touch has 16G. U1000 has 8G (microdrive) + 4G SD = 12G.

m) price?
Oh....iPod completely wins in this category.

So as I have an U1000, I don't need iPod touch. :)

Blogged with Flock

Monday, September 03, 2007

Why I leave Palm and Uses Windows mobile

Actually, for this topic, I don't need to say much, because the Engadget team has say it all. But below is my Palm's experience.

I started as a early Palm user from Palm IIIc-> TRGpro -> m505 -> Clie NR70V -> Clie NZ90 -> Treo 650 + TX. In fact, I would claim myself as a mobile gadget freak, as I spent most of my $$ to mobile gadgets. I like Palm at those days, because Palm OS has many advantages over other platforms (Symbian, Pocket PC 200x/Windows CE). Applications are plenty, and I can achieve many things on the go. When I bought my Treo 650, I hope the next Treo will have Wi-Fi, HSDPA, native a2dp, bluetooth 2.0, better camera resolution, bigger screen, supports more multimedia codecs. I die for a bigger screen (consider I have been a user of NZ90/NR70V), but unfortunately Palm TX is not a phone. I wait and wait and wait, and eventually I loose my patience and buy the TX, hoping it's a good companion to my Treo. Believe it or not, the TX can't use Treo as a phone modem! The phone list driver in TX, no matter how I try and look for any updates from Palm site, has no entry for Treo 650 at all. I sent an email asking for this to Palm support. Well they are so helpful, that, after months of emails back and forth, the major answer I have is that their Palm engineer is (still) working on the issue. OK, Palm doesn't announce any better Treo device, and they don't provide updates to their existing Treo 650 to solve my problem. I am totally disappointed.

Sometimes later, I keep getting news from Palm that pushed me further away from Palm:

1. Palmsource is acquired by Access.
2. OS 6 is dead
3. ALP won't be released shortly. (Consider as of now, Sept 2007, we still don't see any device with ALP released yet)
4. The Treo 750V is released!

For some period, I am actively looking for a replacement for my Treo, still thinking that, hey, let's wait for Palm longer to see if there is any better device it could come out. I don't want to switch to Windows mobile, because of the past bad experience. There is not much option available at those time. So I switched to use Nokia E70. Now my Palm TX can go online. That's good. But the limited memory of this device really drives me crazy. Eventually, I settled with Dopod 838pro (Or HTC Hermes/CHT9000 or whatever it is called).

Switching to Windows mobile, initially, is really a painful experience. Compared with Palm, it's slow, required reset much often, and worst of all, it really needs an XP machine to work with (my major OS is Mac OS X) But after fighting with the device for about a month, I finally start to enjoy it. But do note, that kind of experience should be about the same for whatever a new platform we are using. It took me about the same to get familiar with Palm when I first play with Palm IIIc.



Now I am using HTC U1000, wm6. This is the best mobile device I ever have up to now. Windows mobile 6 provides a much stable and responsive user experience. I especially like the Opera Mobile that comes with it. It has multiple tabs, good javascript and html/css standards support, not to mention good unicode support. BTW, bad browsing experience is my another major complaint on Palm's platform. Blazer can support UTF-8, but it's painfully slow and buggy (or stupid). Other Palm browsers doesn't have good unicode support.

Recently TCPMP flash video plugin, which enable watching all YouTube videos, really makes my U1000 the ultimate entertainment device. Imagine you can watch practically anything you want in a 5" widescreen device on the go. With recent purchase of a Sony BT stereo device (Sony BRM1), and some registry hack, a2dp becomes a much enjoyable experience with WM device. In fact, I think it sound already better than most Sony Ericsson/Nokia a2dp mobiles.

The HSDPA plus the easy shoutcast support in WM media players allows me to listen to my custom made icecast server on the go, in 128kbps bitrate. Together with they Sony BT dongle, I can just put my U1000 inside my bag, and listen to my home streaming server freely, including volume up/volume down, skipping song.

So until ALP platform devices can provide me a better experience, I will stay with windows mobile then.

Wednesday, August 22, 2007

My most used Mac applications

Below are my most used Application List in Mac:

1. jEdit

Actually I have tried many editors, including Textmate, TextWrangler, BBedit, Smultron. But I settled with jEdit for its powerful plugins, including sftp support (which is a must for me), customizable and extensive syntax highlighting support and customizable keyboard shortcuts.

Another big reason is its multi-platform support. It's a very painful experience to use another editor whenever you need to change OS environment. As jEdit is in Java, it can be run in Windows, Mac and Linux.

2. iTerm

A great alternative to Terminal. As compared with Terminal, it has multiple tabs, and fast shortcut to bookmarks. Previously versions of iTerm has problem of screen refresh slow down when a session is opened for a long time. Recent versions has fixed this and quickly become my favorite app. (Well, note that starting from Leopard, Terminal will also have tabs. Wow!)

3. muCommander

A great sftp/ftp application. Another cross-platform application. Beside sftp and ftp, it also support SMB and http. One of its killer feature is, you can perform file transfer across different servers directly, no special requirements on the remote servers! (as opposed to some ftp programs in Windows in order to achieve this). Though you can only have 2 columns opened for 2 servers in one window, you can create more windows of this app and connect to more servers. Files can be drag and drop across diff. windows (and hence different servers!). Another feature I like is its keyboard oriented navigation, which allows me not to touch the mouse at all.

4. VLC

A great media player which support huge list of video formats. It can be a great alternative as a music player also. One thing I don't like iTunes is that it force you to add the music files to its library before they can be played. But not every music file (mp3 etc) you would eager to add to the library. For this case, I willl drag the files to VLC.

5. CotVNC (Chicken of VNC)

Best VNC client in Mac. It even supports Bonjour to discover VNC servers in LAN. Together with ssh tunnelling (using ssh command), I can perform VNC connection to many remote PC/Mac behind firewalls. Oh, for Mac VNC server, you can try Vine Server (Vine)

6. Parallels

I don't think I need to tell you what it is. Actually I think it is a killer application for Mac, which drives many people to use Mac hardwares. Being a programmer, Parallels allow me to run a Ubuntu server inside Mac, not to mention to use IE7 for testing web page layouts.

7. Skype

For video conferencing, I think the quality (especially voice) is even better than iChat.

8. Thunderbird

Add-ons support and more fine-tuned settings is why I keep using Thunderbird instead of Apple Mail. Besides, it's also a good RSS Reader and newsgroup reader too.

9. NeoOffice

You can also try OpenOffice. But NeoOffice offers a much better Mac user experience.

10. QuckSilver

Hands down the killer app. for Mac. Apple Spotlight even not comes close. You won't believe you can do so many things with your keyboard.

11. Journler

If you look for well categorized notes application, this is it. But it can do much more than that. It has Smart Folder, tags, super fast keyword search, blog support, iLife support, embbeded browser..... If you know how to sync its data files to multiple Macs, then your essential information/notes/ideas is always with you.

12. Camino, Firefox, Netscape, Opera, Flock

You may not believe me. But I do use All of them. Each serves its own purpose, and has its own strength for different purposes. Camino is a fast, mac oriented UI and mozilla rending engine browser. Firefox provides huge of addons, and hands down the best browser. Netscape (only v9 or later!) provides a fine-tuned firefox experience, it feels a little bit faster (at least for start-up) and add some good tools by default. Opera is the fastest browser, plus you can use it for BT too. Flock provides great integration with Flickr (and other photo services) , blogs, bookmarks services. It's also mozilla based too.

You should try every of them to see which one suits your needs most.




Tuesday, August 21, 2007

My brand new iMac 20" arrived




DG Group told me Apple unfortunately has delayed once again my iMac 24". As I really don't know when will the "true" shipment will be, I finally decided to switch back to 20" iMac. So here I go, I am using it right now. :)

I saw from Apple forum that many users don't like the glassy display, and the display has a typical problem of being too bright on the bottom while too dim on the top. Well, in my eyes, it's acceptable to me. Just not so sure how to correctly calibrate the display yet.

This iMac just took about 1.5 hour to transfer about 80G files from my Macbook. So far so good.

Monday, August 20, 2007

Haha photo blog again

This is tc station

Mac + Parallel + Ubuntu + wm6 net access

My major web development platform is Kubuntu, which I installed inside Parallels. Since I want to freely test the web application in any of my machines, I choose bridged networking (both macbook and Kubuntu are set to using static IP addresses). On the other hand, my Macbook can access the net through shared networking of my U1000, which provides the HSDPA connectivity to it. I have two problems to solve for the above setup:

1. When I am on the go, since my ethernet is unplugged, my Macbook cannot ssh to my Kubuntu.

2. And of course, my Kubuntu can't access the net, even my Macbook is connected with my U1000.

Recently, I have found a solution. But before this, I need to say something about my home networking configuration first. I have Linux server at home, acting as NAT gateway for all the machines inside my house. The Linux server has 2 ethernet cards, one connected with modem from ISP, the other connected to internal LAN. I don't have DHCP server setup, as I want to have more control on IP on each machine. Say my network is 192.168.0.0, my Linux server is having IP 192.168.0.1. So every machine in my LAN is setting 192.168.0.1 as gateway and DNS server. This includes the setting for my Macbook and the Kubuntu VM.

You may wonder why I need to setup my home networking this way instead of all set to DHCP. The major reason is this setup is exactly the same as in my working area. So my Macbook (or whatever mobile devices that I brought between my working area and home) doesn't need to change anything for joining the network of two places. Another reason is I usually like to remote access any other machine from another machine at home (mostly due to my physical laziness). So I don't want my home computers to change IP time to time.

Anyway, Below is my solution on the go:

1. During on the go, change the Kubuntu networking inside Parallels from "bridge networking" to "host guest".

2. In Macbook -> Preference -> Network, Create a new location profile, say "OnTheGo". In this profile, edit the "Parallels Host-Guest" device to have the IP address of the gateway address being used by Kubuntu. (In my case, it is 192.168.0.1)

3. In Macbook -> Preference -> Sharing -> Internet, set

Share your connection from "Bluetooth PAN" to ethernet Adaptor (en?) of "Parallels host-guest"adapter.

After the above is set, you should already be able to perform any networking operations from Macbook to the Kubuntu. After you have connected the Macbook with wm6 through BT PAN, the Kubuntu will be able to access the net also.

When I am back to home, I just need to change the Location setting back to default (or whatever used at home), and Parallels setting back to "bridge networking". This way, the "Parallels host-guest" adapter's IP address won't get conflict with my Linux server.

Testing mail posting!

Can you see this?

I am waiting for my iMac 24" :)


Well, many guys don't like the new glassy screen, but I like it, just as I like my prev. VAIO glassy LCD.

My iMac spec.:
  • 2.4GHz Intel Core 2 Duo
  • 2GB memory
  • 500GB hard drive1
  • 8x double-layer SuperDrive
  • ATI Radeon HD 2600 PRO with 256MB memory
I never have a LCD as large as 24". Will this make my programming faster? :P

Thursday, October 20, 2005

Unicode conversion in Perl

Starting from Perl 5.6, Perl uses utf-8 for storing character strings internally (Just like Java, which also uses Unicode for storing character strings). To convert a string in native encoding to another encoding, we can think of the same way as what we usually do in Java (if you happens to have some experience in Java character set conversion, you will know what I am saying). e.g. If we want to convert a Big5 string to UTF-16 :


use Encode qw/encode decode/;

$big5str = get_big5_string();
$now_in_utf8 = decode("big5", $big5str);
$now_in_utf16 = encode("UTF-16", $now_in_utf8);



For extra information, if you to want to return an Excel spreadsheet containing Chinese characters from CGI, you can do this:


#!/usr/bin/perl
use Spreadsheet::WriteExcel;
use Encode qw/encode decode/;

my $big5str = get_big5_string();
my $now_in_utf8 = decode("big5", $big5str);
my $now_in_utf16 = encode("UTF-16", $now_in_utf8);

$filename ="excel_file.xls";
print "Content-type: application/vnd.ms-excel\n";
print "Content-Disposition: attachment; filename=$filename\n";
print "\n";

my $workbook = Spreadsheet::WriteExcel->new("-");
my $worksheet = $workbook->addworksheet();

$worksheet->write(1,1,"Non-unicode characters");
$worksheet->write_unicode(1, 2, $now_in_utf16);
$workbook->close();


For M$ Excel before version 2000, you will see square box before each cell, this is due to the BOM character generated during the encode process. Excel 2003 and OpenOffice can recognise this character correctly. To remedy the square bracket, you can just remove it:


my $now_in_utf8 = decode("big5", $big5str);
my $now_in_utf16 = encode("UTF-16", $now_in_utf8);
$now_in_utf16 =~ s/^\x{fe}\x{ff}//;

AMASS

As mentioned in Ajaxian, AMASS(Ajax MAssive Storage System) allows Ajax application to store potentially large amount of persistent data in local machine. By using a SharedObject in a hidden Flash, AMASS can store local data without user intervention for data size smaller than 100k. For larger amount of data, the system will prompt for user approval. I think this is one step closer for Ajax application to perform similar things as locally installed application.

In current stage, the main issue is it only works in Windows. It has not been tested in Linux platform, and it doesn't work in Mac :<.

Wednesday, October 19, 2005

Subversion initial setup

Subversion is a project aims to build a version control system that is a compelling replacement for CVS in the open source community. Besides usual way of doing version control, this is also a good candidate for backup of anything you can imagine. There is a free online book available, if you want to further study it.

Below are some setup notes I have jotted down during my setup. May be this will be helpful to you also.

Setup in Gentoo Linux, as apache2 module

1. If you happens to have apache 2 already installed, setting up Subversion is easy:

# emerge subversion

But in case you are using apache 1.x, you can still go ahead and let portage to install apache 2 for you. There is nothing much harm (other than use more memory) to run both apache 1.x and 2.x together. All you need is just changing the port number apache 2.x is listening to.

2. Create directory for source repository: (you can use whatever directory)

#mkdir /var/repository

3. Create user account for svn:


#mkdir /var/svn/conf
#htpasswd2 -c /var/svn/conf/svnusers newusername


The second command create a new user "newusername" and store the a/c password info in /var/svn/conf/svnusers. The -c option is for file creation, if you are adding more users, you can simply go without this option.

4. To allow apache2 to load the corresponding svn modules, modify /etc/conf.d/apache2 to add "-D DAV -D SVN", e.g.:

APACHE2_OPTS="-D SSL -D PHP4 -D FASTCGI -D DEFAULT_VHOST -D DAV -D SVN"

5. Configure the modules config file /etc/apache2/modules.d/47_mod_dav_svn.conf (you may have number other than 47, depending on the portage maintainer). Assuming we use the password file and repository directory created previously, the file may look like this:


<IfDefine SVN>
<IfModule !mod_dav_svn.c>
LoadModule dav_svn_module modules/mod_dav_svn.so
</IfModule>
<Location /repos>
DAV svn
SVNPath /file2/repos
AuthType Basic
AuthName "WINS Subversion Repository"
AuthUserFile /var/svn/conf/svnusers
Require valid-user
</Location>
<IfDefine SVN_AUTHZ>
<IfModule !mod_authz_svn.c>
LoadModule authz_svn_module modules/mod_authz_svn.so
</IfModule>
</IfDefine>
</IfDefine>


6. Create your initial repository:

#svnadmin create /var/repository

Setup in Redhat, standalone server

For illustration purpose, this time, we run subversion for standalone version, and invoked through xinetd.

1. First step is also easy:

#rpm -Uvh subversion-XXXX.rpm

Just replace XXXX with the version currently available in your system.

2. Create a user for svn in your system. For security, you should set it's login shell to nologin.

3. Add 2 lines to /etc/services: (if they don't exist yet)


subversion 3690/tcp # Subversion
subversion 3690/udp # Subversion


4. Create a file /etc/xinetd.d/svn


# subversion server
service svn
{
disable = no
socket_type = stream
protocol = tcp
wait = no
user = svnuser
server = /usr/bin/svnserve
server_args = -i
}


5. Create your initial repository:


#mkdir /var/repository
#svnadmin create /var/repository


6. During initializing the repository directory, svn creates various directories and files. In particular, there is a config file svnserve.conf inside conf directory created. There are extensive comments inside the config file, with all example setting commented out because they are already set by default by svn. Anyway, you can customize them to your needs, e.g.:


[general]
anon-access = none
auth-access = write
password-db = passwd
realm = My Subversion Realm


The above disables anonymous access, and allow write access for authenticated user. Most importantly, it defines the password file for authentication as 'passwd'. Now in the same conf directory, create this file with following content:

[users]
wins=password1
user2=password2

Using subversion
The most important command to know first is help:

$svn help

To get help on a specific topic :

$svn help update

Import initial directory for a project:

For apache module:


$svn mkdir 'http://localhost/repos/NewProject' -m 'Creating new Project'
$svn import ./MyProject 'http://localhost/repos/NewProject/trunk' -m 'Import for 1st time'


Note that '/repos' is defined in Location directive in apache config.

For standalone version, use svn:// instead.


$svn mkdir 'svn://localhost/var/repository/NewProject' -m 'Creating new Project'
$svn import ./MyProject 'svn://localhost/var/repository/NewProject/trunk' -m 'Import for 1st time


Note that the '/var/repository' are actually a full path of the directory where you create for repository.

Before performing any commit, you need to perfrom an update first :

$cd ./Myproject
$svn update


To check your checked out source status :

svn status

The svn will also mark all non-version file inside your checkout directory as '?' status.

To ignore some files from subversion status cmd (or add/import), either set it globally in ~/.subversion/config :

[miscellany]
### Set global-ignores to a set of whitespace-delimited globs
### which Subversion will ignore in its 'status' output.
global-ignores = *.o *.lo *.la #*# .*.rej *.rej .*~ *~ .#* .DS_Store *.class


or set it in svn cmd:

$cd WEB-INF
$svn propset svn:ignore "*" work/

(first arg is the wildcard pattern, second is the path)

to view back any prop set to a path:

$cd WEB-INF
$svn proplist work


To commit your changes:

$svn commit -m 'Some changes...'

Video iPod


For the past week, everyone is talking about new iPod. Newspaper said many people will die for this thing because of its low price and video capability. But to me, I think it's just an intermediate product from Apple. Given there are already few PMP supporting 640x480 screen, having good support for DivX and Xvid, I can only see the video support in iPod just as a bonus instead of a great feature for main use.

The battery leads to great disappointment too. The official spec. states the 30G version lasts for 2 hours while the 60G lasts for 3 hours in video playback. Not to mention it probably assumes a fully charged and healthy battery condition.

If video support in iPod needs to be as attractive as music support, I think at least the following features need to be found in future iPod generation:

  • Great battery life for video playback (> 10 hrs)
  • Direct support for DivX and Xvid codecs alike. rmvb support would be great too (just dreaming.)
  • Bigger screen
Bigger screen could be difficult to design, in order to retain the original iPod style and click wheel. But after I saw iRiver U10, Apple should be able to come up with a better idea on their own.

Some rumors say Apple is actively developing a Wi-Fi enabled iPod, with builtin mobile Safari for browsing and even buying tunes in ITS. No matter this rumor is true or not, but network enabled iPod is really a great feature that I personally die for long time ago. Imagine you can listen to Internet radio in public places where WiFi is available. At home, you can stream your bigger music collection from iTunes to your iPod similar to Airport Express. And best of all, we will probably have WiFi headphones to free ourselves from cable. I remember Jobs once thought Bluetooth can't deliver good quality music wirelessly to hp. But I strongly believe WiFi can make this come true. Besides, a builtin mobile Safari means a brand new portable device experience just like PSP does. Besides usual web browsing, I know PSP can now even do remote control through VNC, may be iPod can do similar thing to control your Mac remotely? OK, I know it's already too far away.

How about a Dashboard widget style of APIs for iPod? Imagine all cool things you can do with widgets now can easily ported to iPod. Hmm...

Back to real. Right now, the new Zen Vision would definitely be a better choice for PMP than iPod. Let's see which direction Apple will go in their next step in iPod.

Tuesday, October 18, 2005

Why I switch to Mac OS X

I have been a PC user for more than 15 years, and have been both Windows and Linux users since their very early version. (DOS 5.x to Windows 3.x to XP, Slackware to Redhat to Gentoo). I have also been a user of OS/2 for about 1 to 2 years.

Recently I have switched to Mac OS X for the following reasons:

  1. Easy to use, cool looking, well thought and stable GUI readily available. Supporting Chinese and those default good looking Chinese fonts just can't be available in common Linux distro by default.
  2. BSD Unix behind the scene. So I can still do whatever I can do previously with Linux (Apache, Jboss, mysql, gcc, perl,php)
  3. I am not a gamer, so most of the applications I usually use in XP do have similar equivalent in OS X.
  4. Plug & Play usage for my iPod and firewire/usb external drives. (I can even connect my plain old Creative Jukebox thr. USB, just need to install an extra app)
  5. No more virus/spamware problem.
  6. Can run some great killer applications like Photoshop/Dreamweaver etc.

For the first 2 weeks with my Mac, I am struggling with searching for similar applications I used to have in Windoz. Now my search is nearly over:

Browser -> Safari/Firefox
BT -> Azureus
FTP -> Fugu/Transmit
Text editor -> jEdit
Media Player -> VLC (and realplayer for rmvb)
chm ebooks reader -> xchm
Photo viewer -> FFview/GraphicConverter
SSH client -> Terminal!

Well, I know every platform is not for everyone. For me, I need a rock solid OS which can both do GUI and server applications. Linux should be the default answer, but the GUI from both KDE or GNOME just isn't as cool as Aqua. And you just can't plug and play with most hardware with Linux. Don't flame me on this. That's personal choice. :)

Catalyst Framework

Catalyst is a MVC(Model-View-Controller) Framework in Perl, based on the idea of Maypole and RoR. If you know Perl but want to have a taste of all the juice from RoR, but don't want to learn Ruby, Catalyst should be a good answer.

In particular, it provides URL action mappings, and CRUD application too (i.e. instant web database frontend, once you have your MODEL defined).

Thursday, June 09, 2005

Elinks

If you like lynx, you will love Elinks. It has direct mouse support, frames and tables, menus (even pop up menu), within your text terminal. Oh, did I mention it also supports tabbed browsing? (better than IE6, ha ha...)

Besides Midnight Commandar, this is another cool text (or cli) mode application with good mouse support. Anyone know any others?

Monday, June 06, 2005

Backspace + Screen + Vim + PuTTy in FreeBSD

If you use putty to ssh to FreeBSD, you will notice the backspace key won't work in vim in insert mode. The easiest solution is set the backspace to Ctrl-? in your putty setting.

Now when you starting working with gnu screen, you will met another problem. The Ctrl-? backspace now shows as ~ in your shell prompt. If you set the putty back the Ctrl-H, it will works again.

So what should we do if we want to use vim inside screen, through PuTTy in a FreeBSD environment? The solution is, use Ctrl-H in your PuTTy, and add the following code to your .vimrc file:

:if &term == "termname"
: set t_kb=^V
: fixdel
:endif

The above code is copied from vimdoc.

Sunday, June 05, 2005

GNU Screen

GNU Screen enables you to work in multiple sessions in single a telnet/ssh sesion. After you have installed it :

- run screen. Now you are presented still in your shell prompt as usual. Ctrl-a c will create another new session.
- Ctrl-a " will list all your session. Use arrow key to select one, enter to goes to that session.
- Ctrl-a A will prompt you a name for the current session.
- Ctrl-a w will shows you some info of all sessions.
- Ctrl-a Ctrl-a toggles between current and previous session.
- Ctrl-a d will detach the curren screen sessions, and goes back to your original shell prompt. In fact if you are in a remote terminal, just close your terminal emulation app will achive the same effect. After detached, screen -ls will list all the detached sessions. screen -r will restore the first one. screen -d -r will try to detach the session, then attach it. (Good for detaching the session from another remote terminal, and steal it to current one). Think about it, it's really handful!
- For help, Ctrl-a ?
- Hint: If you usually set your bash setting in .bash_profile, you can make a symbolic link of .bashrc back to this file. This way, when screen invokes bash, it will read back your profile setting.
- Hint: If you see ~ appearing when pressing backspace key, it means your terminal emulator is setting wrong. For PuTTy, change it to Ctrl-H.

Don't use vim just as vi

Most Linux nowadays comes with vim instead of vi. But many people just keep using vim as vi. (I am one of them, how about you?) Actually when I first met vim, I am excited, and try to learn all those new techniques. But later on, as using GUI editor much more often, I forgot everything. :x

Below are some difference that I think vim really stands out:

0. Visually copy/cut/paste!
- just type v to start visual mode. Then navigate to whereever you want. This will creates a marked block. Just type 'y' for yanking (copy), or 'd' for cut. Move your cursor to elsewhere, then 'p' to paste your text!
- 'V', will start marking lines
- Ctrl-v will start block mode marking!
- During cursor movement, 'o' will move to the other corner of your current cursor
- For block Visual mode, 'O' moves to the other corner, in the same line
- 'gv' highlight back the previous marked area.
- In addition to yank(y) and delete (d), you can also perform change 'c', 'I' for insert, 'A' for append. For block mode, this means you are repeating what you change for the marked areas. Pretty cool.


1. Resizable windows
- To split current session to two horizontal windows, :split
- To jump your cursor location from one to another, Ctrl-w w (or Ctrl-w Ctrl-w)
- To close one of the window created by split, just Ctrl-w c
- The usual jkhl navigation key works as expected, just add Ctrl-w before it. e.g. Ctrl-w j will move your cursor to the window below your current one.
- To create a new window of a new file, :new
- Ctrl-w + (don't just press the '=' for +, you need to add a shift key!) increase your current window by one row. Type a number before Ctrl-w will repeat this action. So 5 Ctrl-w + increases 5 rows. Similarly, Ctrl-w - will decrease by one.
- <N> Ctrl-w _ will set your current window to <N> rows. Ommitting will maximize your current window as large as possible, but still keep other windows there.

2. File browsing
- : edit <filename> (e <filename> will also do) will try open another file. You will be warned if you havent' save your current file. Also note that you can perform filename completion by pressing <Tab> key.
- Even better, for vim 6.x, edit . will brings you the directory listing. The usual vi navigation (jkhl) keys works as expected. You can perform / search. Just press enter for a directory name will navigate to this directory. Pressing enter for a file will start edit this file. 'D' (capital D) will delete the file, don't worry, it will ask you to confirm.
- You can keep editing another files during your session by using :edit , but just you need to save before moving to another. If you don't want to save yet, try :hide edit filename . (type hid instead of hide will also do.)
- Vim keeps a buffer list of all the editing sessions, and assign a number to each buffer. To view all the buffers, :ls When you knows the buffer number, you can switch to this file by :buf <N> (or even just :b <N>). Still , add hid before if you don't want to save for the moment. In the buffer list, '#' means your current session, '+' means modified session.
- Another way to switch between buffer number is <N>Ctrl-^ (press Ctrl-6), where <N> refers to the buffer number.
- To quickly leave all sessions without saving, :qa!

3. text completion
- Ah, this is really cool. Keep pressing Ctrl-N will goes through all possible strings appears in your current session.

4. Tag list
- The Taglist plugin shows all the functions/scope in another window, just like Function Lists in PsPad/Ultraedit. It will also show the buffer list at the top for easier navigation. Cooo...l!

5. Undo/Redo
- You know 'u' will do undo. For vim, you can perform multiple undo <N>u
- The other way round, Ctrl-R perform redo.

5. Insert mode change
- under insert mode, you can move around using cursor, and keep inserting text. No need to type <Esc> i

6. Marks and Jumps
- To create a mark: m[a-zA-Z] lowercase marks will lost when the current file is removed from buffer list. Upper case marks won't.
- To return to marked: either use ' or ` , follows by the marked character. e.g. 'c
- To view the mark list, :marks
- Whenever you perfrom any jumping actions (like ', /, G etc.), a new jump list is created. To view jump list, :jumps
- Use Ctrl-o for to goes up the jump list, use Ctrl-i to goes down the jump list

7. Search/Replace
- To perform global replace, with confirmation :%s/pattern/replacement/gc
where % means perform on all lines, g is multiple time in each line, c means confirm.
- just pressing * will search the word under cursor. g* search for partial match. # search in backward direction, while g# search for partial word in backward direction.

8. Command Line Editing
- To edit another file, :e , then press <TAB>, this will
show the first file in current directory. This is vim word completion. Keep pressing TAB gives you more files in the internal list in forward direction. To get back the reverse direction, Ctrl-P. Press Ctrl-D will show the whole list for overiew.
- For set option, in addition to the option keyword completion, if you TAB after =, vim will even auto complete with the current option value.
- Under command line, you can Ctrl-P to show your command history. After you press at least one time of Ctrl-P, you can use Ctrl-N to go forward the history again.
- q: will open a command line window. The usual jkhl keys works, and you can edit any line. After you have modify any available command line (or just go to the line w/o editing), press enter. Bingo, this command is executed, and the command line window is auto closed.

Misc. Hints
- To scroll your page one line at a time, use Ctrl-Y and Ctrl-E
- change your vim init setting in your ~/.vimrc
- If you use screen with vim, you can change your .bash_profile (or .bashrc) to set TERM=xterm-color. This will allow mouse=a setting to work. FYI, default screen TERM is set to 'screen'.