Proof of concept for Remapping keys in Xcode's Vim mode using Hammerspoon.
Xcode has a built-in Vim mode. I wanted to do some changes to it:
U
in normal mode should redoy
andp
should use the system clipboard by default, while still allowing specifying a register manuallyY
should yank from the cursor to the end of the line, similar toD
andC
j
andk
act likegj
andgk
, unless you do something like10j
, then they operate normally:w<CR>
saves:%s
opens search and replacegv
to reselect the last visual mode selection
I have some bindings in my .vimrc
which are muscle memory. I also have opinions about how the system clipboard should operate in Vim.
Evil, evil bodging. The current Vim mode Xcode shows in the debug bar is not exposed to accessibility APIs, but every different mode does have its own color, so what this does is:
- Determine if the current focused element is the source code editor
- Determine where the debug bar is in the window
- Take a screenshot of the window and compare the color of a pixel in the Vim mode status (I'M SORRY)
- Perform tricks
Who knows. Right now this isn't really a proper Hammerspoon spoon and there is no user configuration, but it does most of the essential things I put in my .vimrc
.
- Install Hammerspoon and grant it accessibility and screen recording permissions
- Put the spoon in
~/.hammerspoon/Spoons
- Enable it by adding the following to your Hammerspoon configuration (
~/.hammerspoon/init.lua
):
hs.loadSpoon("XcodeVimTricks")
spoon.XcodeVimTricks:start()