Closing the terminal window when the shell exits

An annoying foible to Terminal in OSX is that by default when a terminal exits (Control+D) the Terminal window does not close, you just get [Process Completed]. Turns out this can be fixed really easily, just go to Terminal -> Preferences... -> Settings -> Shell and select ‘Close the window’ for the ‘When the shell exits:’ option.

Closing Terminal window on shell exit

Screenshots in OSX

Its really simple but I have been spoiled by having a little Print Screen key on my keyboard throughout years of Windows and Linux. On a Mac keyboard F13 still works but in OSX you need to press Cmd+Shift+3 to take a screen shot of the whole screen and save it on the desktop and Cmd+Shift+4 to select a box to capture and get saved on the desktop.

If you were really keen you could remap Cmd+Shift+3 to F13 but I’ve found after doing it once or twice it’s pretty darn easy to remember.

Keyboard navigation in OSX

I’m a long time Fedora user and some keyboard shortcuts are second nature to me. Pressing the Home key should take the cursor to the beginning of the line (end should go to the end) and Ctrl+PgUp should move to the previous tab in terminal (Ctrl+PgDn should move to the next tab).

Now it might be a good idea to leave the original key bindings for moving to the beginning/end of a line (Cmd+Left/Cmd+Right) and changing tabs (Ctrl+{/Ctrl+}) in place, especially if you use a laptop.

Changing the behaviour of the Home and end keys

Open and select Terminal -> Preferences... -> Settings -> Keyboard, make sure to select the theme you like and make it default as these settings are Terminal theme dependent. Click the + button at the bottom and enter:

Key: home
Modifier: None
Action: send string to shell
Textbox: (press ctrl+a)

Key: end
Modifier: None
Action: send string to shell
Textbox: (press ctrl+e)

Then in the text box press the home key and click ‘OK’. For the end key do the exact same thing except swap home for end. It should look like this:
Terminal settings, change home/end behaviour

To change the behaviour of the home and end end keys in other applications, like vim for example, we can create a default key binding. Firstly check if the file /Library/KeyBindings/DefaultKeyBinding.dict exists, if it doesn’t create it with the following contents:

    /* Remap Home / End to be correct :-) */
    "\UF729"  = "moveToBeginningOfLine:";                   /* Home         */
    "\UF72B"  = "moveToEndOfLine:";                         /* End          */
    "$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
    "$\UF72B" = "moveToEndOfLineAndModifySelection:";       /* Shift + End  */

I have found this to work in most applications but specifically NOT in Xcode. To get home and end to work in Xcode you need to follow a process very similar to the one for Terminal. Open Xcode and click Xcode -> Preferences... -> Key Bindings -> Text and change;

Move to end of line                           -> End
Move to beginning of line                     -> Home
Move to end of line extending selection       -> Shift+End
Move to beginning of line extending selection -> Shift+Home

This will cause conflicts with pre-existing key bindings, click on conflicts and remove/change the offending bindings. Below is the list of modified bindings I made to complete this change.

[EDIT: In screenshot change Move to left end of line extending selection to Move to end of line extending selection.]

Xcode key bindings to modify home and end key behaviour

For Firefox you could try using this Addon although I think it may not work with modern Firefox versions. The actual key bindings used in Firefox and the reasons behind them are listed here.

If this hasn’t fixed the key binding for your preferred text editor try looking in the key binding/key map section of the editor’s preferences. It seems in OSX that nearly every program specifies these key bindings internally.

Changing the behaviour of the Ctrl+PgUp and Ctrl+PgDn keys

Open a Terminal window and type:

defaults write NSUserKeyEquivalents -dict-add "Select Previous Tab"    "^\UF72C"
defaults write NSUserKeyEquivalents -dict-add "Select Next Tab"        "^\UF72D"

Then quit Terminal, start it again, open more than one tab and try it out!

Vim / Gvim / MacVim : vimrc / gvimrc

I know it’s kind of a weird title but hey, this is about creating the perfect vimrc file be it for Vim, Gvim or MacVim.

Most of the following options come from here, here, here, here and here.


How many previous commands vim remembers.

set history=500

Turn on the filetype plugin so vim automatically detects the filetype of the file opened for purposes of syntax highlighting and indentation rules.

filetype plugin on 
filetype indent on

Turn autoread on so when another program changes the file the changes are automatically loaded.

set autoread

Always show the cursor position.

set ruler

Make the command bar higher so we always see the ruler.

set cmdheight=2

Make backspace behaviour like you think it should.

set backspace=eol,start,indent 
set whichwrap+=,h,l

Show matching the bracket when cursor is over a bracket

set showmatch

How many tenths of a second to blink when matching brackets

set mat=2

Remove annoying sound on errors

set noerrorbells 
set novisualbell 
set t_vb= 
set tm=500

Show line numbers.

set number


When ‘ignorecase’ and ‘smartcase’ are both on, if a pattern contains an uppercase letter, it is case sensitive, otherwise, it is not. For example, /The would find only “The”, while /the would find “the” or “The” etc.

set ignorecase 
set smartcase

Highlight the search result(s).

set hlsearch

Start searching as soon as you start typing.

set incsearch

Colours and Fonts

Enable syntax highlighting.

syntax enable

Set the colour scheme.

colorscheme desert 
set background=dark

Options for when the GUI is enabled.

if has("gui_running") 
  set guioptions-=T 
  set guioptions+=e 
  set t_Co=256 
  set guitablabel=%M\ %t 

Use utf8 as the standard encoding.

set encoding=utf8

Indent and line formatting

Use spaces instead of tabs.

set expandtab

Use 4 spaces as a tab.

set shiftwidth=4 
set tabstop=4

Auto indent on

set ai

Smart indent on

set si

line wrapping in editor.

set wrap

Status line

Always show the status line

set laststatus=2

Specify the formatting of the status line

set statusline=\ %{HasPaste()}%F%m%r%h\ %w\ \ CWD:\ %r%{getcwd()}%h\ \ \ Line:\ %l 
function! HasPaste() 
  if &paste 
    return 'PASTE MODE ' 
  return '' 

Edited mappings

Move a line of text using ALT+[jk] or Comamnd+[jk] on a mac.

nmap <M-j> mz:m+<cr>`z
nmap <M-k> mz:m-2<cr>`z
vmap <M-j> :m'>+<cr>`<my`>mzgv`yo`z
vmap <M-k> :m'<-2<cr>`>my`<mzgv`yo`z

if has("mac") || has("macunix")
  nmap <D-j> <M-j>
  nmap <D-k> <M-k>
  vmap <D-j> <M-j>
  vmap <D-k> <M-k>

Remove any trailing whitespace on save.

func! DeleteTrailingWS() 
  exe "normal mz" 
  exe "normal `z" 
autocmd BufWrite *.py :call DeleteTrailingWS() 
autocmd BufWrite *.coffee :call DeleteTrailingWS()

Opening a folder or application from the terminal in OSX

I’ve become pretty dependent on the gnome-open command in Gnome. After I began using OSX more frequently I was in need of an equivalent, it’s:

% open .

Yep, it’s really that simple. While we’re on the topic you can also launch applications with the open command.

% open -a /Applications/

You can also pass arguments to the application to be opened:

% open -a /Applications/

This is pretty sweet and can be extended extracted to a bash script that lives somewhere on your path for example /usr/bin.


open -a /Applications/$ $2

Add execute permissions to the file ( chmod +x /usr/bin/run) and it can be called with:

% run VLC agoodsong.ogg

Mobile Broadband v. Fixed Connection

I have been playing with a Telstra Elite mobile broadband today and have had the opportunity to compare its bandwidth and latency with my regular connection here at work.

The Telstra Elite is rated as a 21Mbps device claiming real-world speeds between 0.55 and 8Mbps downstream and 0.3-3Mbps upstream. As a disclaimer my lab is in a position of poor mobile reception, I’m stuck right between towers with a lot of concrete and steel between me and the towers. I have issues with all carriers except Telstra, because they use a lower frequency band than other carriers in Australia it seems to penetrate buildings better.

My connection at work is ethernet to a local router then into the work network from then on I am not really sure.



To test latency I am simply using ping. I am querying a server known to be less than 20Kms away (

First the regular network connection:

$ ping -c 10
PING ( 56(84) bytes of data.
64 bytes from ( icmp_req=1 ttl=54 time=2.34 ms
64 bytes from ( icmp_req=2 ttl=54 time=2.26 ms
64 bytes from ( icmp_req=3 ttl=54 time=3.77 ms
64 bytes from ( icmp_req=4 ttl=54 time=2.12 ms
64 bytes from ( icmp_req=5 ttl=54 time=2.07 ms
64 bytes from ( icmp_req=6 ttl=54 time=2.12 ms
64 bytes from ( icmp_req=7 ttl=54 time=2.11 ms
64 bytes from ( icmp_req=8 ttl=54 time=3.04 ms
64 bytes from ( icmp_req=9 ttl=54 time=2.27 ms
64 bytes from ( icmp_req=10 ttl=54 time=2.14 ms ping statistics —
10 packets transmitted, 10 received, 0% packet loss, time 11044ms
rtt min/avg/max/mdev = 2.076/2.430/3.777/0.524 ms

Secondly using the mobile broadband card:

$ ping -c 10
PING ( 56(84) bytes of data.
64 bytes from ( icmp_req=1 ttl=49 time=160 ms
64 bytes from ( icmp_req=2 ttl=49 time=129 ms
64 bytes from ( icmp_req=3 ttl=49 time=67.9 ms
64 bytes from ( icmp_req=4 ttl=49 time=77.0 ms
64 bytes from ( icmp_req=5 ttl=49 time=65.8 ms
64 bytes from ( icmp_req=6 ttl=49 time=64.0 ms
64 bytes from ( icmp_req=7 ttl=49 time=63.0 ms
64 bytes from ( icmp_req=8 ttl=49 time=201 ms
64 bytes from ( icmp_req=9 ttl=49 time=80.3 ms
64 bytes from ( icmp_req=10 ttl=49 time=118 ms ping statistics —
10 packets transmitted, 10 received, 0% packet loss, time 9011ms
rtt min/avg/max/mdev = 63.013/102.814/201.672/45.662 ms

As you can see there is a significant difference in the latency of the two connections. I still find the mobile broadband card usable for most things including interactive shells (SSH) but certainly not for gaming. The annoying part of the mobile broadband connection is the variability of the ping but this is to be expected for wireless technology.


Regular connection:


Mobile broadband:


I think these pics speak for themselves. There is a huge difference between the two connections especially upstream. I am in a unusual situation where I get faster upstream rates than downstream, it’s awesome!



Overall I was mightily impressed with the Telstra Elite but I’m glad I don’t have to rely on it for regular usage. Later I may do the same test using my home internet and my tethered phone.