psliwka / vim-smoothie

Smooth scrolling for Vim done right🥤
MIT License
988 stars 27 forks source link

Feature request: `gg` fast-scrolls to the top #1

Closed benwoodward closed 3 years ago

benwoodward commented 4 years ago

Not a super-necessary feature, but sublime text does this and it gives you a sense of how long the file is when you see it scroll past.

psliwka commented 4 years ago

This is a reasonable feature request indeed. It does, however, pose several implementation challenges:

  1. Currently, the plugin mechanics rely on scrolling, i.e. moving the window over the buffer. The cursor follows the window as a side effect, being subject to various modifiers such as scrolloff and startofpage. Commands such as gg work the other way around - they move the cursor itself, which is being followed by the window. To handle them reliably, the plugin will need to learn this difference, probably by switching between different scrolling styles depending on what command triggered movement.
  2. Cursor movement commands are frequently used to operate on ranges, f.ex. gggqG. The plugin will need to detect such cases, and either skip the animation, or delay executing further commands until the animation ends. Otherwise, subsequent commands would be applied to incorrect ranges.
  3. Any command replaced by vim-smoothie should be 100% compatible with the original one. In case of gg, that means supporting [count] and 'startofline' at least.

Similar issues apply to implementing other cursor movement commands, such as f.ex. [[ and {.

subnut commented 3 years ago

@benwoodward @hendry3k

Try #21 with the following configuration -

silent! map <unique> gg         <Plug>(Smoothie_gg)
silent! map <unique> G          <Plug>(Smoothie_G)

and please report bugs, if any

benwoodward commented 3 years ago

@subnut Works well! Great work.

psliwka commented 3 years ago

gg and G support has landed on master 🎉 To enable it, you can either set up custom mappings in your vimrc (as @subnut described above), or you can let g:smoothie_experimental_mappings=v:true and have them defined automatically along with the rest of default mappings.