I have:

nnoremap <ScrollWheelUp> k
nnoremap <S-ScrollWheelUp> k
nnoremap <C-ScrollWheelUp> k
nnoremap <ScrollWheelDown> j
nnoremap <S-ScrollWheelDown> j
nnoremap <C-ScrollWheelDown> j
inoremap <ScrollWheelUp> <c-x><c-y>
inoremap <S-ScrollWheelUp> <c-x><c-y>
inoremap <C-ScrollWheelUp> <c-x><c-y>
inoremap <ScrollWheelDown> <c-x><c-e>
inoremap <S-ScrollWheelDown> <c-x><c-e>
inoremap <C-ScrollWheelDown> <c-x><c-e>

this works on iTerm but doesn't overwrite the default scroll behavior (applying my maps but still applies the default behaviors which is scrolling 3 lines up/down). I tried on macvim and that successfully replaced the default behavior.

  • 1
    You can't override setting of a terminal. Vim probably gets 3 scroll events, according to what's setup in iTerm. You can confirm that by doing echo "scroll up" instead of k press in your mapping, and then verify how many entries there is with :messages command (if they won't all show up in the message area) – grodzik Aug 8 at 11:27
  • 1
    @grodzik you mean echom – D. Ben Knoble Aug 8 at 11:43
  • Yes all the scroll events are working, but the screen is still scrolling, i don't understand how iterm is making vim to scroll, shoudn't it be just sending key codes to vim and vim is handling the scrolling? I tried macvim with the same config and the scroll mappings overrides the default behavior correctly. – wengwengweng Aug 8 at 12:56
  • 1
    iTerm is a GUI application, same as macvim. They directly interpret mouse scroll event from the system. Vim is a console application and events like mouse scroll come from the terminal that it is running in. That's why it's working in MacVim and not Vim, MacVim is the one who interprets the event, Vim is not. I might be wrong here, but I think you need to set iTerm correctly or try this in another termianl emulator. – grodzik Aug 8 at 14:05
  • Yes of course macvim / iterm is interpreting the event, but shouldn't vim be the only one executing the actions triggered by the event? The explanation I can think of now is those keymaps are not fully responsible for the mouse scroll event. I also tried it on vimr and it doesn't even execute my custom mapped functionality – wengwengweng Aug 8 at 16:20

Found a workaround:

if has('gui_macvim')

    nnoremap <ScrollWheelUp> 2k
    nnoremap <S-ScrollWheelUp> 2k
    nnoremap <C-ScrollWheelUp> 2k
    nnoremap <ScrollWheelDown> 2j
    nnoremap <S-ScrollWheelDown> 2j
    nnoremap <C-ScrollWheelDown> 2j
    inoremap <ScrollWheelUp> <c-x><c-y>
    inoremap <S-ScrollWheelUp> <c-x><c-y>
    inoremap <C-ScrollWheelUp> <c-x><c-y>
    inoremap <ScrollWheelDown> <c-x><c-e>
    inoremap <S-ScrollWheelDown> <c-x><c-e>
    inoremap <C-ScrollWheelDown> <c-x><c-e>

" how to check if vim is running on iTerm?
else

    noremap <up> k
    noremap <down> j
    inoremap <up> <c-x><c-y>
    inoremap <down> <c-x><c-e>

endif

and 2 iTerm settings:

Profiles > Terminal > Report mouse wheel events to false

Advanced > Scroll wheel sends arrow keys when in alternate screen mode to true

Makes iTerm works expectedly

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.