Jeromy Anglim's Notes

Assorted notes on statistics, R, psychological research, LaTeX, computing, etc. See also my primary blog for more substantive posts: jeromyanglim.blogspot.com
  • rss
  • archive

Tags:
  • R
  • LaTeX
  • Linux / Ubuntu
  • OSX
  • Jags
  • Tumblr

Previous Notes:
Main Blog:
  • Vim-style cursor navigation in any program using KeyRemap4MacBook

    Enabling vim features using KeyRemap4MacBook

    KeyRemap4MacBook provides a wide range of keyboard customisations. In particular I was interested in enabling Vim style keybindings across more programs so that I could minimise the need to move the hand from the touch typing position. This post describes several KeyRemap4MacBook customisations that I explored.

    I concluded that several customisations that appeared at first to be good were not good. The main problem is that customisations often interfere too much with existing keyboard functionality. Ultimately, the only customisations that I have retained are Simultaneous Vi Mode and modifications to key repeat settings. Thus, I describe these first, before discussing customisations that I tried but did not persist with (i.e., Ubiquitous Vim Bindings and Complete Vi Mode).

    If there is one take home point it is this: simultaneous vi mode quickly becomes awesome for touch typists.

    Simultaneous Vi Mode

    This mode involves pressing s and d keys together and then using h, j, k, and l for vim style cursor navigation. I also added “Change F to FN”. This means that HJKL correspond to Home, PageDown, PageUp, and End. This gives a lot more navigational power. It’s also possible to simultaneously hold down s, d, and modifier keys like cmd, alt, and shift to do other forms of navigation and selection.

    This is much less full featured than Complete Vi Mode, but it does not cause mode confusion or conflict. It is activated and then deactivated naturally when the task switches. It wont interfere with any existing functionality.

    I lowered the simultaneous key presses threshold to 30 milliseconds. This seemed to enable me to still be able to type asdf fairly quickly, yet it was not so quick that I was accidentally typing sd when trying to press both keys simultaneously. That said, by enabling this shortcut, I have realised just how frequently I pound out asdf.

    I also suppressed messages in Growl from the program as it was annoying being informed every time I simultaneously held down s and d.

    After using this customisation for a few weeks it has become intuitive and really powerful. I use it most commonly when performing search and select type tasks. For example, when searching the help menu for a command using Cmd+Shift+/, you need to then cursor down to the selection and press enter. As a touch typer the sd then j combination to navigate down quickly becomes automatic and less attention demanding than moving the hands from the home row position.

    Other useful examples:

    • Navigating Finder with the keyboard using the touch typing position
    • Selecting items in Spotlight
    • Selecting items in Alfred. Even though Alfred has some nice support for selecting items, I often find the sd and j approach quicker.
    • Browsing a PDF
    • Selecting a particular URL from a list in the Chrome address bar
    • Selecting an auto-completion option in Excel
    • Selecting code complete in various IDEs such as RStudio

    However there are times when I don’t use it:

    • For most tasks in Chrome, there is Vimium
    • For the terminal there are Vi customisations to .inputrc (see here
    • For text editing there is Vim.

    In summary, I’m really happy with this customisation.

    Key repeat settings

    I also found it useful to adjust the following key repeat settings

    • Key repeat wait: 30ms
    • Key repeat initial wait: 350ms

    I have not adopted the remaining settings, but I figured the discussion might be worth recording for others interested in such customisations.

    Ubiquitous Vim Bindings

    This setting allows editing of text in a wide range of programs on the Mac using many Vim key bindings. The documentation provides details of what keys are supported.

    For example, you can edit text in Chrome browser text boxes (e.g., gmail, stackoverflow, tumblr), Word, Excel.

    Fortunately the program is smart enough to not operate in terminal applications, Firefox , emacs, vi and vim. For the terminal I have existing customisation settings here.

    I first configured the program with the following settings

    • Enabled Insert Mode Commands
    • Esc toggles Normal Mode
    • Esc does not exit normal model

    This corresponds to how I actually use Vim in Vim. However, this means that actually pressing escape requires holding down the escape key. This is quite disruptive as escape key presses are often not registered especially if you are in the habit of activating.

    Insert mode commands can also cause conflicts. In particular, Control +U conflicts with Excel cell edit.

    This is a real trade-off. On the one hand, Vim key bindings are awesome for when they are needed, but overriding the escape key is unacceptable.

    I also turned off “Enable Tab key” as it appeared to interfere with navigating menus with the keyboard.

    I experimented with configuring two versions of KeyRemap. A default configuration that does not support Vim text editing, and a configuration that I call “Vim” that does support Vim editing. However, it seemed at first that toggling versions would require the mouse which seemed to defeat the purpose of the efficiency savings. However, I have since found out that it is possible to toggle settings using the command-line. I asked on the github issue tracker for the project about switching between settings using a keyboard shortcut. Details on switching preferences are provided here.

    Thus, the possibility of switching modes using a keyboard shortcut might make this customisation worthy of further consideration, but for now, I have disabled this option.

    Complete Vi Mode

    This provides Vi style navigation in a wide range of applications. This includes a wide range of keys This means that many more things can be done without moving the hand from the home row position.

    Examples,

    • Scroll up and down webpages
    • Move between cells in Excel
    • Navigate forms and dialog boxes with the keyboard
    • Navigate the menus
    • Navigate deskbars such as Spotlight

    Configuration: I initially tried using “simultaneous key presses” (i.e., pressing both left and right cmd). However, my first impression was that you often forget to switch between modes. There is no visual indicator of what mode you are in. Thus, it is fairly disruptive. This is compounded by the fact that there is often no clear indicator on a task for when you might be finished with Vi command mode, and when you might want to shift to regular use of the keyboard.

    • November 8, 2012 (6:33 pm)
  • comments powered by Disqus