What exactly is the source of your happiness again?

Something from the New York Times…

I’d finally managed to exile the voices in my head that told me my
personal happiness was only as good as my outward success, rooted in
things that were often outside my control.


Problem Using Vim on the Motorola Droid

I use the excellent ConnectBot SSH client on my Motorola Droid to SSH into Linux/Unix boxen. Subsequently, I make the mistake of using Vim. Once I enter insert mode in Vim, I realize that the Droid keyboard (and probably every other smartphone keyboard) doesn’t have any key representing the Escape key (that is used in Vim to exit insert mode). There isn’t even a key, AFAIK, representing Control. After being stumped by this multiple times, I now do the following every time before I start editing with Vim when connected in via my Droid:

:imap qq <Esc>

Note that you have to do this *before* you enter insert mode (remember you want a key-sequence to be able to exit insert mode). Once set, I can enter ‘q’ two times in succession to simulate the Escape key action.


Creating and Using Keyboard Macros (Record Macro, Play Macro) to Record and Playback Keystrokes in Vim

  • In normal mode, press the key sequence q followed by a. This starts the recording mode (and you should see the word “recording” on the mode-line at the bottom).
  • Then enter or exit the insert-mode as many times as you wish, editing text using the keyboard. All the time, vim will keep recording all your keystrokes.
  • Finally exit insert-mode (get into normal mode) and then press q. This will stop recording your keystrokes.
  • Playback the recorded macro in normal mode, anytime, using the key-sequence @ followed by a. This will playback all the edits you made earlier. Once you’ve referred to a the first time, you can subsequently use @ followed by @ (a double @) to repeat the operation.

Instead of the key a following q when starting recording mode, you can really use any one of the keys 0 to 9 or a to z. The second key is basically a reference to a ‘register’ that sort of names your macro.  You can record multiple different macros and play them back by recording to each one of these ‘registers’. The key you use on playback after the @ refers to the appropriate macro recorded.

Recording and playback of keystrokes in Emacs is explained here.


Creating and Using Keyboard Macros (Record Macro, Play Macro) to Record and Playback Keystrokes in Emacs

  • Use C-x ( to start the macro (start recording keystrokes)
  • …Perform whatever keyboard actions…
  • Use C-x ) to stop the macro (stop recording keystrokes)
  • Playback the recorded macro anytime using C-x e

You can also assign different hot-keys for convenience:

(global-set-key [f1] 'start-kbd-macro)
(global-set-key [f2] 'end-kbd-macro)
(global-set-key [f3] 'call-last-kbd-macro)

Check out the KeyboardMacros Emacs Wiki page for more in-depth info on Emacs Keyboard Macros.