Real World Examples


Here are some examples you can copy/paste directly into your own keymandorc.rb file. You can also check out a full keymando.rb file updated frequently.

https://github.com/kevincolyar/dotfiles/blob/master/keymandorc.rb

global
OSX

These mappings apply system-wide except for my terminal and MacVim.

I hate reaching for the Escape key. Instead I use the same mapping that I use in vim.

    nmap '<Ctrl-[>', '<Escape>'

vi-like movement

    except /Term/, /MacVim/ do
      map '<Ctrl-j>', '<Down>'
      map '<Ctrl-k>', '<Up>'
      map '<Ctrl-h>', '<Left>'
      map '<Ctrl-l>', '<Right>'

      map '<Ctrl-f>', '<PageUp>'
      map '<Ctrl-b>', '<PageDown>'
    end

If you also want to be able to select text using these mappings add:

      map '<Ctrl-Shift-j>', '<Shift-Down>'
      map '<Ctrl-Shift-k>', '<Shift-Up>'
      map '<Ctrl-Shift-h>', '<Shift-Left>'
      map '<Ctrl-Shift-l>', '<Shift-Right>'

I don't want Keymando to do anything when I'm in these applications, so we'll disable them.

    disable 'Remote Desktop Connection'
    disable /VirtualBox/

Remember, this is ruby, so we can do stuff like this.

    ['Finder', 'iTunes', 'Preview'].each |app| { disable app }

F2 is too much of a contorsion on my MacBook Pro so I map it to <Ctrl-m> to access the Mac menu.

    map '<Ctrl-m>', '<Ctrl-F2>'

This is my mapping to toggle Keymando.

    toggle '<Ctrl-E>'

Here’s a nice way to quickly lock your screen with a bonus confirmation and text-to-speach for fun.

    map '<Cmd-Ctrl-l>' do
      if confirm('Lock screen?')
        say 'Goodbye for now!'
        lock_screen
      end
    end

chrome
Chrome

Here are three different types of tab switching for Chrome. You can adapt them to your favorite browser.

tmux-like tab switching

    only /Chrome/ do
      map '<Ctrl-w>h', '<Cmd-{>'
      map '<Ctrl-w>l', '<Cmd-}>'
    end

vim-like tab switching

    only /Chrome/ do
      map '<Ctrl-w>h', '<Cmd-{>'
      map '<Ctrl-w>l', '<Cmd-}>'
    end

Another vim-like tab switching. Notice these are the same as the vi-movment ones I defined above (<Ctrl-h> and <Ctrl-l>). Since these mappings are defined after the ones above, they will take priority but only if the current application is Chrome.

    only /Chrome/ do
      map '<Ctrl-w>', '<Cmd-{>'
      map '<Ctrl-w>', '<Cmd-}>'
    end

iterm
iTerm

When I work in my terminal I only want to close the app using the exit command. Sometimes I accidently try to refresh or open a new tab in my browser on one monitor when focus is actually in iTerm in another monitor. To fix this I simply disable those events.

    only /iTerm/ do
      map '<Cmd-w>', nil
      map '<Cmd-q>', nil
      map '<Cmd-r>', nil
      map '<Cmd-t>', nil
    end

Mnemonics

These are some more advanced examples that use muemonics.

    map '<Cmd-y>' do
      input(

This is a handy web development mnemonic that makes Google Chrome the active applcation, refreshes the page, then returns me back to vim in my terminal.

         'rc' => lambda {
           activate('Google Chrome')
           sleep(1)
           send('<Cmd-r>')
           sleep(1)
           activate('iTerm')
         },

Here are a couple iTunes mnemonics using Keymando with Quicksilver.

        'qt' => lambda{
            track = prompt('Enter track')
            send('<Cmd- >')
            send('Browse Tracks')
            sleep(1)
            send('<Right>')
            sleep(1)
            send(track+'<Enter>')
        },
        'ba' => lambda {
            send('<Cmd- >')
            send('Browse Artists')
            sleep(1)
            send('<Right>')
        },
        'bt' => lambda {
            send('<Cmd- >')
            send('Browse Tracks')
            sleep(1)
            send('<Right>')
        },
      )

    end