This is a plugin which enforces alt-ijkl
navigation shortcuts on currently open keymap, tool windows and popups. The idea is that these shortcuts are more ergonomic for navigation/editing than using keyboard arrows so you can stop using arrows in IDE editor.
These shortcuts are inspired by Vim, gaming keyboard layouts and common sense.
Editor navigation:
alt-i
- line upalt-j
- move to previous wordalt-k
- line downalt-l
- move to next wordalt-n
- move leftalt-m
- move rightalt-u
- move to line startalt-o
- move to line endalt-f
- page downalt-w
- page upalt-shift-ijklmnuo
- navigate with selection
Editor text modification:
alt-e / alt-shift-e
- expand/shrink word selectionalt-;
- delete next characteralt-d
- delete next wordalt-y
- remove linealt-ctrl-shift-ik
- move statement up/downalt-ctrl-shift-jl
- move element left/rightalt-cmd-shift-ik
(OSX) - move statement up/downalt-cmd-shift-jl
(OSX) - move element left/rightalt-/
- cyclic expand word (aka hippie completion)alt-'
- code completionalt-l
- choose lookup item and replacecmd-l
orctrl-l
- complete statement
Search and navigation between files:
alt-a
- highlight usages in filealt-s
- show usages popupalt-shift-s
- find usagesalt-h
- jump to sourcectrl-cmd-b
orctrl-alt-b
- implementations popupalt-b
- backalt-shift-b
- forwardcmd-shift-[
- previous tabcmd-shift-]
- next tabalt-q
- close tabshift ctrl t
- reopen closed tab
Because existing key layouts are inefficient and painful to use.
Below you can find reasons for choosing particular keys.
When touch typing you would normally position your index fingers on letters f
and j
. This is fine for writing a lot of text sequentially. The problem is that writing/editing code is never linear and requires a lot of navigation even for simplest tasks. Navigation with standard key layouts makes you move right hand from j
letter to arrows and back to j
. This takes a lot of effort.
Ideally, we would just move arrows into the are with letters and use them as before. This is what ijkl
mapped to up/left/down/right
is trying to achieve (note that both ijkl
and arrows are used with right hand).
There are several options how to make ijkl
work for navigation.
One option could be something like vim command/insert modes, i.e. "command mode" in which ijkl
keys work as arrows and "insert mode" in which all keys work as in traditional editors. It might be a good idea to test this on practice over a long period of time. Although not many text editors have replicated vim modes so may be this is a sign.
Another option is to use modifier keys to change behaviour of ijkl
letters (or you might think about it as enabling "command mode" only when modifier key is pressed). In general, this option is much easier to implement in various editors/IDEs. And among modifier keys, alt
was the least used in existing IDE keymaps so the left alt
was chosen.
Three is a problem with arrow navigation that left/right arrows jump only one character at a time. You can use ctrl-left/right
(or alt-left/right
on OSX) to jump between words. This is more useful and, arguably, should be default navigation for arrows. That's why in alt-jl
moves caret to previous/next word. Single character navigation is still useful sometimes, so it's mapped to alt-nm
. There is no particular reason for these letters except that they are located not too far from ijkl
.
Moving to the start/end of line is another important part of navigation, so ideally it should mapped to keys not far from ijkl
. For this reason u
and o
seem like a great choice.
Moving to the start of line is u
because it is close to j
and essentially also means moving caret left. And o
is mapped to the end of line because it's about moving right, similar to l
(there is an implicit assumption here that you're writing code left to right in English).
The choice of fw
letters mapped to page down/up was copied from less and admittedly is somewhat arbitrary.
TBD
There are couple issues when using alt-ijkl shortcuts with built-in OSX keyboard layouts:
- dead keys cannot be used as IDE shortcuts (e.g.
alt-i
in US layout) - if
alt-ik
are mapped to some character, thenNavigate to Class
action handlesalt-ik
shortcuts as both navigation up/down and entering a character. - keys with certain output, when held down, trigger IDE action only once (e.g.
alt-i
with 'ˆ' output in US layout).
The first two issues can be solved by adding keyboard input source which doesn't have dead keys and doesn't output characters for alt-ijkl
shortcuts. See section below.
To solve the third issue you can disable sticky keys feature by executing in shell defaults write -g ApplePressAndHoldEnabled -bool false
.
On IDE startup the plugin will suggest to add keyboard input sources. In practice, this means that plugin will create ~/Library/Keyboard Layouts/ijkl-keys.bundle
directory with a bunch of files.
After input sources were installed, open OSX System Preferences -> Keyboard -> Input Sources
and click on +
to add input sources.
Choose U.S. - IJKL
or British - IJKL
input source from English category and click Add
button. (If you don't see these inputs, you might need to log out / log in or restart.)
Now you can switch to new input source in IDE and use alt-ijkl
shortcuts.
If you're happy with custom layout and want to hide built-in layout from input source list, follow these steps:
- change the current input source to your custom keyboard layout
open ~/Library/Preferences/com.apple.HIToolbox.plist
(requires XCode)- remove the input source or input sources you want to disable from the
AppleEnabledInputSources
dictionary; if there is anAppleDefaultAsciiInputSource
key, remove it - restart