Code cleanup for test.py.
Solves waiting problem in an elegant way.

1. The keys after launching vim will wait until the vim is full loaded.
2. The keys after leaving vim will wait until the vim process is dead.
3. A bunch of cleanups.