├── .gitignore ├── README.markdown └── plugin └── SimpleSmoothScroll.vim /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | Session.vim 3 | -------------------------------------------------------------------------------- /README.markdown: -------------------------------------------------------------------------------- 1 | ### Description 2 | 3 | SimpleSmoothScroll is a simple Vim global plugin for giving a smoothed effect 4 | to Ctrl-D and Ctrl-U. 5 | 6 | ### Rationale 7 | 8 | I originally created this script for myself when I was looking through large 9 | code files in a legacy code base and I was having trouble keeping track of 10 | where I was in all the spaghetti. The smooth scroll action gave me a better 11 | sense of my own navigation. 12 | 13 | I originally published this code [on StackOverflow](http://stackoverflow.com/a/12201974/834176). 14 | The current version has been fixed up some in an attempt to be a little more 15 | readable and conform to the guidelines put forth in `:help write-script`. 16 | 17 | I've also used this as a chance to begin learning to use Github. At the time I 18 | wrote this, I did not realize that there were [many existing smooth scroll 19 | plugins](http://www.vim.org/scripts/script_search_results.php?keywords=smooth+scroll&script_type=&order_by=rating&direction=descending&search=search). 20 | To be honest, I haven't looked into any of them. They might be better than 21 | this. 22 | 23 | ### Features 24 | 25 | + Scroll on the basis of the Vim `scroll` option. 26 | + If you set the mouse option for some modes, you can scroll with the mouse 27 | wheel in those modes. 28 | + Manually customizable scrolling speed (adjust the `sleep` command's time 29 | argument; I use ten milliseconds). *Note*: just like slowing down the frame 30 | rate on a video, if you slow down the smooth scroll too much it will be jerky 31 | scroll. 32 | already in insert mode) 33 | + Simple and lightweight 34 | 35 | ### Warning 36 | 37 | I've found that you shouldn't push Ctrl-D or 38 | Ctrl-U until the previous scroll has finished, or the 39 | behavior is somewhat unpredictable. I have mostly experienced this problem when 40 | dealing with very large files over a painfully slow network connection. 41 | 42 | ### Installation 43 | 44 | I recommend installing [pathogen.vim](https://github.com/tpope/vim-pathogen), 45 | and then executing: 46 | 47 | cd ~/.vim/bundle 48 | git clone https://github.com/Kazark/vim-SimpleSmoothScroll.git 49 | 50 | or the equivalent. Alternatively, you can copy `plugin/SimpleSmoothScroll.vim` 51 | to `~/.vim/plugin`. (Note: you may have to use `~\vimfiles` instead of 52 | `~/.vim` if you are on Windows...) 53 | 54 | ### Insert mode 55 | 56 | By default and have different purposes in insert mode. However if 57 | you would like to have scroll working as normal mode, add the lines below to 58 | your vimrc file. 59 | 60 | ``` 61 | inoremap i 62 | inoremap i 63 | ``` 64 | -------------------------------------------------------------------------------- /plugin/SimpleSmoothScroll.vim: -------------------------------------------------------------------------------- 1 | " Purpose: Vim global plugin for giving a smoothed effect to C^D and C^U 2 | " Author: Kazark 3 | " License: No warranty or guarantee of any kind that it will work as intended 4 | " and will not have harmful or annoying behavior or side effects. That said, 5 | " use, copy, distribute, modify however you like if you find it that useful, 6 | " which you probably won't. 7 | 8 | if exists('g:loaded_SimpleSmoothScroll_plugin') 9 | finish 10 | endif 11 | let g:loaded_SimpleSmoothScroll_plugin=1 12 | 13 | if !exists('g:SimpleSmoothScrollDelay') 14 | let g:SimpleSmoothScrollDelay=10 15 | endif 16 | 17 | let s:save_cpo = &cpo 18 | set cpo&vim 19 | 20 | function s:ScrollUp() 21 | call s:ScrollWithAction("") 22 | endfunction 23 | 24 | function s:ScrollDown() 25 | call s:ScrollWithAction("") 26 | endfunction 27 | 28 | function s:ScrollWithAction(scrollaction) 29 | execute "norm " . a:scrollaction 30 | redraw 31 | let counter=1 32 | while counter<&scroll 33 | let counter+=1 34 | execute "sleep ".g:SimpleSmoothScrollDelay."m" 35 | redraw 36 | execute "norm " . a:scrollaction 37 | endwhile 38 | endfunction 39 | 40 | nnoremap :call ScrollUp() 41 | nnoremap :call ScrollDown() 42 | map 43 | map 44 | 45 | let &cpo = s:save_cpo 46 | --------------------------------------------------------------------------------