1*scroll.txt* For Vim version 8.1. Last change: 2018 Apr 26 2 3 4 VIM REFERENCE MANUAL by Bram Moolenaar 5 6 7Scrolling *scrolling* 8 9These commands move the contents of the window. If the cursor position is 10moved off of the window, the cursor is moved onto the window (with 11'scrolloff' screen lines around it). A page is the number of lines in the 12window minus two. The mnemonics for these commands may be a bit confusing. 13Remember that the commands refer to moving the window (the part of the buffer 14that you see) upwards or downwards in the buffer. When the window moves 15upwards in the buffer, the text in the window moves downwards on your screen. 16 17See section |03.7| of the user manual for an introduction. 18 191. Scrolling downwards |scroll-down| 202. Scrolling upwards |scroll-up| 213. Scrolling relative to cursor |scroll-cursor| 224. Scrolling horizontally |scroll-horizontal| 235. Scrolling synchronously |scroll-binding| 246. Scrolling with a mouse wheel |scroll-mouse-wheel| 25 26============================================================================== 271. Scrolling downwards *scroll-down* 28 29The following commands move the edit window (the part of the buffer that you 30see) downwards (this means that more lines downwards in the text buffer can be 31seen): 32 33 *CTRL-E* 34CTRL-E Scroll window [count] lines downwards in the buffer. 35 The text moves upwards on the screen. 36 Mnemonic: Extra lines. 37 38 *CTRL-D* 39CTRL-D Scroll window Downwards in the buffer. The number of 40 lines comes from the 'scroll' option (default: half a 41 screen). If [count] given, first set 'scroll' option 42 to [count]. The cursor is moved the same number of 43 lines down in the file (if possible; when lines wrap 44 and when hitting the end of the file there may be a 45 difference). When the cursor is on the last line of 46 the buffer nothing happens and a beep is produced. 47 See also 'startofline' option. 48 {difference from vi: Vim scrolls 'scroll' screen 49 lines, instead of file lines; makes a difference when 50 lines wrap} 51 52<S-Down> or *<S-Down>* *<kPageDown>* 53<PageDown> or *<PageDown>* *CTRL-F* 54CTRL-F Scroll window [count] pages Forwards (downwards) in 55 the buffer. See also 'startofline' option. 56 When there is only one window the 'window' option 57 might be used. 58 59 *z+* 60z+ Without [count]: Redraw with the line just below the 61 window at the top of the window. Put the cursor in 62 that line, at the first non-blank in the line. 63 With [count]: just like "z<CR>". 64 65============================================================================== 662. Scrolling upwards *scroll-up* 67 68The following commands move the edit window (the part of the buffer that you 69see) upwards (this means that more lines upwards in the text buffer can be 70seen): 71 72 *CTRL-Y* 73CTRL-Y Scroll window [count] lines upwards in the buffer. 74 The text moves downwards on the screen. 75 Note: When using the MS-Windows key bindings CTRL-Y is 76 remapped to redo. 77 78 *CTRL-U* 79CTRL-U Scroll window Upwards in the buffer. The number of 80 lines comes from the 'scroll' option (default: half a 81 screen). If [count] given, first set the 'scroll' 82 option to [count]. The cursor is moved the same 83 number of lines up in the file (if possible; when 84 lines wrap and when hitting the end of the file there 85 may be a difference). When the cursor is on the first 86 line of the buffer nothing happens and a beep is 87 produced. See also 'startofline' option. 88 {difference from vi: Vim scrolls 'scroll' screen 89 lines, instead of file lines; makes a difference when 90 lines wrap} 91 92<S-Up> or *<S-Up>* *<kPageUp>* 93<PageUp> or *<PageUp>* *CTRL-B* 94CTRL-B Scroll window [count] pages Backwards (upwards) in the 95 buffer. See also 'startofline' option. 96 When there is only one window the 'window' option 97 might be used. 98 99 *z^* 100z^ Without [count]: Redraw with the line just above the 101 window at the bottom of the window. Put the cursor in 102 that line, at the first non-blank in the line. 103 With [count]: First scroll the text to put the [count] 104 line at the bottom of the window, then redraw with the 105 line which is now at the top of the window at the 106 bottom of the window. Put the cursor in that line, at 107 the first non-blank in the line. 108 109============================================================================== 1103. Scrolling relative to cursor *scroll-cursor* 111 112The following commands reposition the edit window (the part of the buffer that 113you see) while keeping the cursor on the same line. Note that the 'scrolloff' 114option may cause context lines to show above and below the cursor. 115 116 *z<CR>* 117z<CR> Redraw, line [count] at top of window (default 118 cursor line). Put cursor at first non-blank in the 119 line. 120 121 *zt* 122zt Like "z<CR>", but leave the cursor in the same 123 column. {not in Vi} 124 125 *zN<CR>* 126z{height}<CR> Redraw, make window {height} lines tall. This is 127 useful to make the number of lines small when screen 128 updating is very slow. Cannot make the height more 129 than the physical screen height. 130 131 *z.* 132z. Redraw, line [count] at center of window (default 133 cursor line). Put cursor at first non-blank in the 134 line. 135 136 *zz* 137zz Like "z.", but leave the cursor in the same column. 138 Careful: If caps-lock is on, this command becomes 139 "ZZ": write buffer and exit! {not in Vi} 140 141 *z-* 142z- Redraw, line [count] at bottom of window (default 143 cursor line). Put cursor at first non-blank in the 144 line. 145 146 *zb* 147zb Like "z-", but leave the cursor in the same column. 148 {not in Vi} 149 150============================================================================== 1514. Scrolling horizontally *scroll-horizontal* 152 153For the following four commands the cursor follows the screen. If the 154character that the cursor is on is moved off the screen, the cursor is moved 155to the closest character that is on the screen. The value of 'sidescroll' is 156not used. 157 158z<Right> or *zl* *z<Right>* 159zl Move the view on the text [count] characters to the 160 right, thus scroll the text [count] characters to the 161 left. This only works when 'wrap' is off. {not in 162 Vi} 163 164z<Left> or *zh* *z<Left>* 165zh Move the view on the text [count] characters to the 166 left, thus scroll the text [count] characters to the 167 right. This only works when 'wrap' is off. {not in 168 Vi} 169 170 *zL* 171zL Move the view on the text half a screenwidth to the 172 right, thus scroll the text half a screenwidth to the 173 left. This only works when 'wrap' is off. {not in 174 Vi} 175 176 *zH* 177zH Move the view on the text half a screenwidth to the 178 left, thus scroll the text half a screenwidth to the 179 right. This only works when 'wrap' is off. {not in 180 Vi} 181 182For the following two commands the cursor is not moved in the text, only the 183text scrolls on the screen. 184 185 *zs* 186zs Scroll the text horizontally to position the cursor 187 at the start (left side) of the screen. This only 188 works when 'wrap' is off. {not in Vi} 189 190 *ze* 191ze Scroll the text horizontally to position the cursor 192 at the end (right side) of the screen. This only 193 works when 'wrap' is off. {not in Vi} 194 195============================================================================== 1965. Scrolling synchronously *scroll-binding* 197 198Occasionally, it is desirable to bind two or more windows together such that 199when one window is scrolled, the other windows are also scrolled. In Vim, 200windows can be given this behavior by setting the (window-specific) 201'scrollbind' option. When a window that has 'scrollbind' set is scrolled, all 202other 'scrollbind' windows are scrolled the same amount, if possible. The 203behavior of 'scrollbind' can be modified by the 'scrollopt' option. 204 205When using the scrollbars, the binding only happens when scrolling the window 206with focus (where the cursor is). You can use this to avoid scroll-binding 207for a moment without resetting options. 208 209When a window also has the 'diff' option set, the scroll-binding uses the 210differences between the two buffers to synchronize the position precisely. 211Otherwise the following method is used. 212 213 *scrollbind-relative* 214Each 'scrollbind' window keeps track of its "relative offset," which can be 215thought of as the difference between the current window's vertical scroll 216position and the other window's vertical scroll position. When one of the 217'scrollbind' windows is asked to vertically scroll past the beginning or end 218limit of its text, the window no longer scrolls, but remembers how far past 219the limit it wishes to be. The window keeps this information so that it can 220maintain the same relative offset, regardless of its being asked to scroll 221past its buffer's limits. 222 223However, if a 'scrollbind' window that has a relative offset that is past its 224buffer's limits is given the cursor focus, the other 'scrollbind' windows must 225jump to a location where the current window's relative offset is valid. This 226behavior can be changed by clearing the "jump" flag from the 'scrollopt' 227option. 228 229 *syncbind* *:syncbind* *:sync* 230:syncbind Force all 'scrollbind' windows to have the same 231 relative offset. I.e., when any of the 'scrollbind' 232 windows is scrolled to the top of its buffer, all of 233 the 'scrollbind' windows will also be at the top of 234 their buffers. 235 236 *scrollbind-quickadj* 237The 'scrollbind' flag is meaningful when using keyboard commands to vertically 238scroll a window, and also meaningful when using the vertical scrollbar of the 239window which has the cursor focus. However, when using the vertical scrollbar 240of a window which doesn't have the cursor focus, 'scrollbind' is ignored. 241This allows quick adjustment of the relative offset of 'scrollbind' windows. 242 243============================================================================== 2446. Scrolling with a mouse wheel *scroll-mouse-wheel* 245 246When your mouse has a scroll wheel, it should work with Vim in the GUI. How 247it works depends on your system. It might also work in an xterm 248|xterm-mouse-wheel|. By default only vertical scroll wheels are supported, 249but some GUIs also support horizontal scroll wheels. 250 251For the Win32 GUI the scroll action is hard coded. It works just like 252dragging the scrollbar of the current window. How many lines are scrolled 253depends on your mouse driver. If the scroll action causes input focus 254problems, see |intellimouse-wheel-problems|. 255 256For the X11 GUIs (Motif, Athena and GTK) scrolling the wheel generates key 257presses <ScrollWheelUp>, <ScrollWheelDown>, <ScrollWheelLeft> and 258<ScrollWheelRight>. For example, if you push the scroll wheel upwards a 259<ScrollWheelUp> key press is generated causing the window to scroll upwards 260(while the text is actually moving downwards). The default action for these 261keys are: 262 <ScrollWheelUp> scroll three lines up *<ScrollWheelUp>* 263 <S-ScrollWheelUp> scroll one page up *<S-ScrollWheelUp>* 264 <C-ScrollWheelUp> scroll one page up *<C-ScrollWheelUp>* 265 <ScrollWheelDown> scroll three lines down *<ScrollWheelDown>* 266 <S-ScrollWheelDown> scroll one page down *<S-ScrollWheelDown>* 267 <C-ScrollWheelDown> scroll one page down *<C-ScrollWheelDown>* 268 <ScrollWheelLeft> scroll six columns left *<ScrollWheelLeft>* 269 <S-ScrollWheelLeft> scroll one page left *<S-ScrollWheelLeft>* 270 <C-ScrollWheelLeft> scroll one page left *<C-ScrollWheelLeft>* 271 <ScrollWheelRight> scroll six columns right *<ScrollWheelRight>* 272 <S-ScrollWheelRight> scroll one page right *<S-ScrollWheelRight>* 273 <C-ScrollWheelRight> scroll one page right *<C-ScrollWheelRight>* 274This should work in all modes, except when editing the command line. 275 276Note that horizontal scrolling only works if 'nowrap' is set. Also, unless 277the "h" flag in 'guioptions' is set, the cursor moves to the longest visible 278line if the cursor line is about to be scrolled off the screen (similarly to 279how the horizontal scrollbar works). 280 281You can modify the default behavior by mapping the keys. For example, to make 282the scroll wheel move one line or half a page in Normal mode: > 283 :map <ScrollWheelUp> <C-Y> 284 :map <S-ScrollWheelUp> <C-U> 285 :map <ScrollWheelDown> <C-E> 286 :map <S-ScrollWheelDown> <C-D> 287You can also use Alt and Ctrl modifiers. 288 289This only works when Vim gets the scroll wheel events, of course. You can 290check if this works with the "xev" program. 291 292When using XFree86, the /etc/XF86Config file should have the correct entry for 293your mouse. For FreeBSD, this entry works for a Logitech scrollmouse: > 294 Protocol "MouseMan" 295 Device "/dev/psm0" 296 ZAxisMapping 4 5 297See the XFree86 documentation for information. 298 299 *<MouseDown>* *<MouseUp>* 300The keys <MouseDown> and <MouseUp> have been deprecated. Use <ScrollWheelUp> 301instead of <MouseDown> and use <ScrollWheelDown> instead of <MouseUp>. 302 303 *xterm-mouse-wheel* 304To use the mouse wheel in a new xterm you only have to make the scroll wheel 305work in your Xserver, as mentioned above. 306 307To use the mouse wheel in an older xterm you must do this: 3081. Make it work in your Xserver, as mentioned above. 3092. Add translations for the xterm, so that the xterm will pass a scroll event 310 to Vim as an escape sequence. 3113. Add mappings in Vim, to interpret the escape sequences as <ScrollWheelDown> 312 or <ScrollWheelUp> keys. 313 314You can do the translations by adding this to your ~.Xdefaults file (or other 315file where your X resources are kept): > 316 317 XTerm*VT100.Translations: #override \n\ 318 s<Btn4Down>: string("0x9b") string("[64~") \n\ 319 s<Btn5Down>: string("0x9b") string("[65~") \n\ 320 <Btn4Down>: string("0x9b") string("[62~") \n\ 321 <Btn5Down>: string("0x9b") string("[63~") \n\ 322 <Btn4Up>: \n\ 323 <Btn5Up>: 324 325Add these mappings to your vimrc file: > 326 :map <M-Esc>[62~ <ScrollWheelUp> 327 :map! <M-Esc>[62~ <ScrollWheelUp> 328 :map <M-Esc>[63~ <ScrollWheelDown> 329 :map! <M-Esc>[63~ <ScrollWheelDown> 330 :map <M-Esc>[64~ <S-ScrollWheelUp> 331 :map! <M-Esc>[64~ <S-ScrollWheelUp> 332 :map <M-Esc>[65~ <S-ScrollWheelDown> 333 :map! <M-Esc>[65~ <S-ScrollWheelDown> 334< 335 vim:tw=78:ts=8:noet:ft=help:norl: 336