Wednesday, October 28, 2009

Daily VIM commands

These are commands I found to be using frequently when on command line:

Window Operations:
  • :split - horizontal split
  • :vs - vertical split
  • :vsplit - vertical split
  • Ctrl + W, Ctrl + W - will tab between windows
  • Ctrl + W, _ - will maximize current window
  • Ctrl + W, = - will resize all windows equally
  • 4 CTRL-W + - will increase height of window by 4 lines
File Explorer:
  • :e - will tab through the files available in current directory
  • :cd <..> - will change to directory, just like system command
  • :Ex - open file explorer in current window
  • :Sex - split current window and open explorer in one of windows
  • Hit a file to open that file in current window
  • Ctrl + 6 to go back to explorer from opened file
  • :s/OLD/NEW - find and replace a first occurrence on current line
  • :s/OLD/NEW/g - find and replace all occurrences on current line
  • :%s/OLD/NEW/g - find and replace all occurrences in entire file
Diffing files
  • From within VI: :vertical diffsplit file
  • From command shell: vimdiff file1, file2
Buffer Operations
  • :ls - will list currently open buffers
  • :bn - will open a buffer n, where n is a number as reported by ls
  • :b - tab through open buffers, select one to open with Enter
  • :tabe - opens a new tab (tab in edit mode)
  • gt - advance to the next
  • gT - advance to the previous
  • {count}gt - go to the {count} tab
  • :tabe - path/to/file - to open a file
  • :tabn - go to next tab
External Commands
  • :pwd - print working directory
  • :cd - as usual - move to directory
  • :cd D - will iterate through directories starting with D

Visual Selection Mode
  • v - to put in the visual selection mode
  • y - yank/copy
  • x - cut selection
  • p - paste at cursoe location

Ctrl + N or Ctrl + P - this will show choices when typing partial working

Expand tabs with spaces(put these onto the .vimrc file):
:set tabstop=4
:set expandtab

Mouse Support (in the .vimrc file)
:set mouse=a

This is mostly a cheet sheet for myself, ..but enjoy

Sunday, October 18, 2009

Ubuntu 9.04 on MacBook Pro 5.4

A few days ago I purchased a new shiny MacBook Pro, and decided to install Ubuntu on it. Why? because Linux is my habitat, and also because some software packages I use are readily available on Linux, but not on Mac OS. In any case, this blog is not about Mac OS vs Linux (more on this maybe one day; I can write a book on how Mac OS sucks :)), but rather some steps I had to overcome to complete the installation.

Out of the box, Jaunty works on MBP, with some exceptions. The trackpad is too slow be useful, the Fn key in in the reverse.
After installation using the Boot Camp, I followed the instructions on the Ubuntu forums:, additionally used information here:
to adjust keyboard settings. All was fine, except the Trackpad refused to be configured. This has proven to be the biggest hurdle I spent the most time on... until I discovered this posting:
Configure ALPS (Synaptics) touchpad in Ubuntu 9.0.4 (Jaunty Jackalope)
Apparently, the fdi file must be mapped to the correct HAL device (kinda makes sense :)).
Using this command:

$lshal > hal.txt

, I was able to see that the name of my device was: "Apple Inc. Apple Internal Keyboard / Trackpad".
Armed with this knowledge, I edited my FDI file to my liking, and HAL was able to load it, and apply my settings to the right device.
The trick is to find the parameter: "info.product" in the lshal output and use it in the fdi file.
Here is my complete fdi file after adjusting speed and sensitivity:


Friday, January 2, 2009

Bending Outlook towards GMail

I use e-mail extensively, and usually for the most part working for clients whose infrastructures are based on MS Exchange. I have tried really hard to wean myself from Outlook, but unfortunately the alternatives bring about a host of other problems (tried Thunderbird and Evolution).

The two things I really like about GMail are:
* Nothing is deleted
* All is searchable

One really annoying problem is that the server administrator usually sets up cleaning of the "Deleted Items" folder and you loose all those "deleted" messages for future searches. I've been using GMail for personal use since 2004, and really like the idea that nothing needs to be deleted. Configuring Outlook 2003 to save all messages has proven to be a challenge. Here is how I did this.

First, I created a new folder under "Inbox" called "MyDeletedItems". I then wrote a VBA macro to move all messages from "Deleted Items" as well as all selected messages from any current view to "MyDeletedItems" folder.
Here is a code for the marco:

Sub MoveToMyDeletedFolder()

Dim x As Integer
Set myDeletedItemsFolder = Application.GetNamespace("MAPI").GetDefaultFolder(6).Folders("MyDeletedItems")

'This will move all selected messages from current view to "MyDeletedItems" folder.
Set sectedItems = Outlook.Application.ActiveExplorer.Selection
For x = 1 To sectedItems.Count
'MsgBox sectedItems.Item(x).SenderName & ":" & sectedItems.Item(x).Subject
sectedItems.Item(x).Move myDeletedItemsFolder
Next x

' this will move all items from standard DeletedItems folder to MyDeletedFolder
Set deletedItemsFolder = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderDeletedItems)
Set delItems = deletedItemsFolder.Items
For x = 1 To delItems.Count
'MsgBox delItems.Item(x).SenderName & ":" & delItems.Item(x).Subject
delItems.Item(x).Move myDeletedItemsFolder
Next x

End Sub

The next step was to create a button and wire it to the macro, which was fairly easy. The really awkward way of adding a shortcut to buttons in Outlook shocked me. This is done by changing a text associated with a button. You need to pre-pend the name with a '&' character, which will make pressing Alt+'next character' possible. For instance, if the label on the button is "&Delete Message", then this button is associated with a Alt+D keyboard shortcut. Editing the button text is equally unfriendly. Thanks to all the people whose links I cannot reproduce here (i googled extensively to get all this information), I learned that in order to edit a button text, you have to do: Tools-> Customize, then, when the Customize dialog is up, right - click on the button to edit it's text.

As you can see from screenshot, my configuration is 'Alt+X'.

Since there is much written about Outlook security on the web, I will not repeat it here, but getting to run the macros is not straight forward. Instead of changing the security levels, I chose to create s self - signed certificate and us it for the macros.
Here are the steps to dot this:
  • Generate a self-signed certificate. This can be done with a variety of tools, but the simplest way to do this is to use MS - provided SelfCert.exe. On my machine, it is located here: c:/Program Files/Microsoft Office/Office11
  • In VBA Editor, do: Tools-> Digital Signature -> Choose .. and choose a certificate you just generated.
After this step, I was able to run the macro by just selecting a message in my inbox and pressing 'Alt+X'.
I think that when I started poking around all these steps, Outlook prompted me if I want to enable macros for X number of days, I selected some value and completely forgot it. Sure enough, after a dye days :) this stopped working and Outlook presented me with a message saying that I need to "Enable macros" from the application (Outlook). This was very annoying, and I had to dig further.
After some poking around, I figured that the certificate I created is a type of a "personal certificate", which can be seen in Internet Explorer Tools-> internet Options-> Content -> Certificates -> Personal. I exported this certificate and imported it back in as "Trusted Root Certificate", which solved this problem. I can run my macros again (till further obstacle from MS :)).

Once you import the certificate as "trusted Root Certificate", start Outlook again and try to run the macro, you will be presented with this dialog:

At this point, mark "Always trust macros from this publisher" and press "Enable Macros" button.

The last thing to make Outlook to behave close to GMail is to have a good search. While I generally believe that the Google Desktop is a search engine superior search to Windows search, I have a few gripes about it. First, when an e-mail message is found, there is no way to see what folder a message belongs to. Additionally, there is a pretty annoying bug in Google Desktop and Outlook integration, which sometimes prevents a link "Open in Outlook" to work. This makes it impossible to reply to and forward messages found through a search engine. Windows search, on the other hand has a tight integration with Outlook (surprise !), and is working well albeit slower than Google.

I have an e-mail environment for corporate e-mail that is somewhat close to GMail - nothing is deleted, and all is searchable.

I hope this help someone.