I figured out a way to do that with Hammerspoon
and clever usage of mapping.
The first part is configuring Shift + ScrollUp and
Shift + ScrollDown to scroll horizontally. In
order to do that, you have put the following code snippet in your .vimrc
:
nnoremap <S-ScrollWheelUp> <ScrollWheelLeft>
nnoremap <S-2-ScrollWheelUp> <2-ScrollWheelLeft>
nnoremap <S-3-ScrollWheelUp> <3-ScrollWheelLeft>
nnoremap <S-4-ScrollWheelUp> <4-ScrollWheelLeft>
nnoremap <S-ScrollWheelDown> <ScrollWheelRight>
nnoremap <S-2-ScrollWheelDown> <2-ScrollWheelRight>
nnoremap <S-3-ScrollWheelDown> <3-ScrollWheelRight>
nnoremap <S-4-ScrollWheelDown> <4-ScrollWheelRight>
Note that we have to use <S-2-ScrollWheelUp>
and the like
because they are sent as keys to the terminal as well. I found no
documentation about this (I figured this out by using
Ctrl + V while scrolling in insert mode).
After that, we have to remap horizontal scrolls to Shift + vertical scrolls. To do so, we place the following snippet in Hammerspoon's init.lua
scrollBind = hs.eventtap.new({hs.eventtap.event.types.scrollWheel}, function(e)
if is_active('iTerm2') then
local horizontalOffset = e:getProperty(hs.eventtap.event.properties.scrollWheelEventDeltaAxis2)
if horizontalOffset ~= 0 then
hs.eventtap.scrollWheel({ 0, horizontalOffset }, {"shift"}, 'pixel')
return true
end
end
return false
end):start()
function is_active(program_name)
local active_window_name = hs.window.focusedWindow():application():name()
return active_window_name == program_name
end
We create the scrollBind
variable just so the keystroke watcher isn't erased by the Lua's garbage collector.
wWeE$)}
etc.), and if you're using arrow keys you're definitely using Vim wrong. – Doorknob Feb 4 '15 at 18:53