├── README.markdown ├── doc └── noscrollbar.txt └── plugin └── noscrollbar.vim /README.markdown: -------------------------------------------------------------------------------- 1 | # Noscrollbar 2 | 3 | ![Noscrollbar demo](https://gcavallanti.github.io/vim-noscrollbar/noscrollbar.gif) 4 | 5 | Noscrollbar is a scrollbar-like widget for the vim statusline that 6 | provides a visual feedback of what part of a buffer is currently shown on 7 | screen. 8 | 9 | The "no" in noscrollbar refers to the fact that the gripper cannot be 10 | really gripped and dragged, i.e., the scrollbar cannot be used to scroll the 11 | window with the mouse. 12 | 13 | ## Installation 14 | 15 | I recommend installing [pathogen.vim](https://github.com/tpope/vim-pathogen), and 16 | then simply copy and paste: 17 | 18 | cd ~/.vim/bundle 19 | git clone https://github.com/gcavallanti/vim-noscrollbar.git 20 | 21 | Once help tags have been generated, you can view the manual with 22 | `:help noscrollbar`. 23 | 24 | ### How to use 25 | 26 | Simply add `%{noscrollbar#statusline()}` to the `statusline` option and you are 27 | done. Example: 28 | 29 | set statusline=%<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %{noscrollbar#statusline()} 30 | 31 | The default behavior returns a string of length 20 where the dash character '-' 32 | is used to render the track of the scrollbar and the hash character '#' is used 33 | to render the gripper. The scrollbar look can be customized by passing the 34 | length, the track character and the gripper character. For example the default 35 | look is set by calling `%{noscrollbar#statusline(20,'-','#')}`. 36 | 37 | ### High resolution mode 38 | 39 | NoscrollBar comes with an high resolution mode. Check `:help noscrollbar` 40 | for details. 41 | 42 | ## Self-Promotion 43 | 44 | Like noscrollbar? Follow and/or star the 45 | [repository](https://github.com/gcavallanti/vim-noscrollbar). You might also want to follow 46 | me on [GitHub](https://github.com/gcavallanti). 47 | 48 | ## License 49 | 50 | Copyright (c) Giovanni Cavallanti. Distributed under the same terms as Vim itself. 51 | See `:help license`. 52 | -------------------------------------------------------------------------------- /doc/noscrollbar.txt: -------------------------------------------------------------------------------- 1 | *noscrollbar.txt* For Vim version 7.3 Last change: 2014 Dec 10 2 | 3 | 4 | CONTENTS *noscrollbar* 5 | Introduction |noscrollbar-introduction| 6 | Config |noscrollbar-config| 7 | Statusline |noscrollbar-statusline| 8 | FAQ |noscrollbar-faq| 9 | Changelog |noscrollbar-changelog| 10 | About |noscrollbar-about| 11 | ============================================================================== 12 | INTRODUCTION *noscrollbar-introduction* 13 | 14 | Noscrollbar is a scrollbar-like widget for the vim statusline that 15 | provides a visual feedback of what part of a buffer is currently shown on 16 | screen. The "no" in noscrollbar refers to the fact that the gripper cannot be 17 | really gripped and dragged, i.e., the scrollbar cannot be used to scroll the 18 | window with the mouse. 19 | 20 | ============================================================================== 21 | CONFIG *noscrollbar-config* 22 | 23 | The easiest way to use noscrollbar is simply to add the 24 | %{|noscrollbar#statusline()|} item to the 'statusline' option. 25 | Setting 'statusline' to > 26 | 27 | %<%f\ %h%m%r%=%-14.(%l,%c%V%)\ %{noscrollbar#statusline()} 28 | < 29 | gives a 'statusline' that matches the default one when 'ruler' is set, except 30 | that the relative position is replaced by a scrollbar. 31 | 32 | The default behavior returns a string of length 20 where the dash character "-" 33 | is used to render the track of the scrollbar and the hash character "#" is used 34 | to render the gripper. The scrollbar look can be customized by passing the 35 | length, the track character and the gripper character. For example the following 36 | %{} item: 37 | > 38 | 39 | %{noscrollbar#statusline(9,'_','=')} 40 | < 41 | results in a scrollbar that looks like this: > 42 | 43 | __==_____ 44 | < 45 | Noscrollbar comes with an high-resolution mode. Turning it on is just a matter 46 | of passing two lists of characters used to render the gripper left and right 47 | edges. If your vim correctly displays unicode characters then adding > 48 | 49 | %{noscrollbar#statusline(20,'■','◫',['◧'],['◨'])} 50 | < 51 | to the 'statusline' option gives a simple high-resolution scrollbar. The 52 | high-resolution mode depends on unicode characters to render partial states 53 | where the edges of the statusbar should be somewhere in the middle of 54 | a character (a sort of subpixel-rendering). For this to work properly 55 | a cooperation between vim (|+multi_byte|) and your font of choice is required. 56 | If the above settings do not work for you, try to experiment with these 57 | alternative choices > 58 | 59 | %{noscrollbar#statusline(20,'-','█',['▐'],['▌'])} 60 | 61 | %{noscrollbar#statusline(20,'-','▓',['▐'],['▌'])} 62 | < 63 | ============================================================================== 64 | STATUSLINE *noscrollbar-functions* 65 | 66 | The |noscrollbar#statusline()| should be called inside a %{} 'statusline' 67 | expression item. 68 | 69 | *noscrollbar#statusline()* 70 | noscrollbar#statusline({length}, {track_symbol}, {grippersymbol} [, 71 | {gripperleftsymbols}, {gripperrightsymbols} [, {part}]]) 72 | Return a string of length {length} representing the scrollbar. 73 | {track_symbol} is the character used to render the track element 74 | of the scrollbar. {gripper_char} is the character used to 75 | render the gripper element of the scrollbar. 76 | {gripperleftsymbols} and {gripperrightsymbols} are lists of 77 | characters, of the same length, used to render the states that 78 | range from "close to track symbol" to "close to gripper symbol". 79 | Setting {part} to 'l', 'm', 'r' returns the left track element, 80 | the middle (gripper) element or the right (track) element, 81 | respectively. 82 | 83 | ============================================================================== 84 | FAQ *noscrollbar-faq* 85 | 86 | Q: Is it possible to scroll a window by dragging the gripper ? 87 | A: No, it isn't. As far as I know mouse clicks on the statusline are not 88 | passed to vimscripts. 89 | 90 | Q: Is it possible to use Noscrollbar with vim-airline ? 91 | A: Yes! add this to your .vimrc > 92 | 93 | function! Noscrollbar(...) 94 | let w:airline_section_z = '%{noscrollbar#statusline()}' 95 | endfunction 96 | call airline#add_statusline_func('Noscrollbar') 97 | < 98 | (Thanks to reddit user threeifbywhiskey) 99 | 100 | ============================================================================== 101 | CHANGELOG *noscrollbar-changelog* 102 | 103 | 0.1 104 | * Initial version 105 | 106 | ============================================================================== 107 | ABOUT *noscrollbar-about* 108 | 109 | Grab the latest version or report a bug on GitHub: 110 | 111 | http://github.com/gcavallanti/vim-noscrollbar 112 | 113 | ============================================================================== 114 | vim:tw=78:ts=8:ft=help:norl 115 | -------------------------------------------------------------------------------- /plugin/noscrollbar.vim: -------------------------------------------------------------------------------- 1 | if &cp || exists('g:noscrollbar_loaded') 2 | finish 3 | endif 4 | 5 | let g:noscrollbar_loaded = 1 6 | 7 | function! noscrollbar#statusline(...) 8 | let top_line = line("w0") 9 | let bottom_line = line("w$") 10 | let current_line = line('.') 11 | let lines_count = line('$') 12 | 13 | " Default values 14 | let length = 20 15 | let tracksymbol = '-' 16 | let grippersymbol = '#' 17 | let gripperleftsymbols = [] 18 | let gripperrightsymbols = [] 19 | let part = 'a' 20 | 21 | if a:0 >= 3 22 | let length = a:1 23 | let tracksymbol = a:2 24 | let grippersymbol = a:3 25 | endif 26 | 27 | if a:0 >= 5 && type(a:4) == 3 && type(a:5) == 3 28 | \ && len(a:4) == len(a:5) 29 | let gripperleftsymbols = a:4 30 | let gripperrightsymbols = a:5 31 | endif 32 | 33 | if a:0 >= 6 34 | let part = a:6 35 | endif 36 | 37 | let scaling = len(gripperleftsymbols) + 1 38 | 39 | " Compute gripper position and size as if we have scaling times a:1 40 | " characters available. Will shrink everything back just before returning 41 | let scrollbar_length = str2nr(length) * scaling 42 | 43 | " Gripper positions are 0 based (0..scrollbar_length-1) 44 | let gripper_position = float2nr((top_line - 1.0) / lines_count 45 | \ * scrollbar_length) 46 | let gripper_length = float2nr(ceil((bottom_line - top_line + 1.0) 47 | \ / lines_count * scrollbar_length)) 48 | 49 | " Users expect to see the scrollbar in the leftmost position only if we 50 | " are at the very top of the buffer 51 | if (top_line > 1) && (gripper_position == 0) 52 | " Since the top line is not visible shift the gripper by one position 53 | let gripper_position = 1 54 | if (gripper_position + gripper_length > scrollbar_length) 55 | " Shrink the gripper if we end up after the end of the scrollbar 56 | let gripper_length = gripper_length - 1 57 | endif 58 | endif 59 | 60 | if (bottom_line < lines_count) 61 | \ && (gripper_position + gripper_length == scrollbar_length) 62 | " As before, if the last line is not on the screen but the scrollbar 63 | " seems to indicate so then either move the scrollbar position leftwise 64 | " by one position or decrease its length 65 | if gripper_position > 0 66 | let gripper_position = gripper_position - 1 67 | else 68 | let gripper_length = gripper_length - 1 69 | endif 70 | endif 71 | 72 | " Shrink everything back to the range [0, a:1) 73 | let gripper_position = 1.0 * gripper_position / scaling 74 | let gripper_length = 1.0 * gripper_length / scaling 75 | let scrollbar_length = 1.0 * scrollbar_length / scaling 76 | 77 | " The left of the gripper is broken in 3 parts. The left and right are 78 | " fractionals in the range [0, len(a:4)). 79 | let gripper_length_left = ceil(gripper_position) - gripper_position 80 | " Hackish rounding errors workaround. If `gripper_length 81 | " - gripper_lenght_left` is 0.9999.. we force it to 1 before rounding it 82 | let gripper_length_middle = floor(round((gripper_length 83 | \ - gripper_length_left)*100.0)/100.0) 84 | let gripper_length_right = gripper_length - gripper_length_left 85 | \ - gripper_length_middle 86 | 87 | " Time to assemble the actual scrollbar 88 | let scrollbar = '' 89 | if part != 'm' && part != 'r' 90 | let scrollbar .= repeat(tracksymbol, float2nr(floor(gripper_position))) 91 | 92 | let grippersymbol_index = float2nr(round(gripper_length_left * scaling)) 93 | if grippersymbol_index != 0 94 | let scrollbar .= gripperleftsymbols[grippersymbol_index - 1] 95 | endif 96 | endif 97 | 98 | if part != 'l' && part != 'r' 99 | let scrollbar .= repeat(grippersymbol, float2nr(gripper_length_middle)) 100 | endif 101 | 102 | if part != 'l' && part != 'm' 103 | let grippersymbol_index = float2nr(round(gripper_length_right * scaling)) 104 | if grippersymbol_index != 0 105 | let scrollbar .= gripperrightsymbols[grippersymbol_index - 1] 106 | endif 107 | let scrollbar .= repeat(tracksymbol, float2nr(scrollbar_length 108 | \ - ceil(gripper_position + gripper_length))) 109 | endif 110 | 111 | return scrollbar 112 | endfunction 113 | --------------------------------------------------------------------------------