blob: d43ecb28ac5b0434759d9ee4c5dcf1a5033baad9 [file] [log] [blame]
Bram Moolenaareb490412022-06-28 13:44:46 +01001*scroll.txt* For Vim version 9.0. Last change: 2022 May 07
Bram Moolenaar071d4272004-06-13 20:20:40 +00002
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.
Bram Moolenaar15142e22018-04-30 22:19:58 +020035 The text moves upwards on the screen.
Bram Moolenaar071d4272004-06-13 20:20:40 +000036 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.
Bram Moolenaar071d4272004-06-13 20:20:40 +000048
49<S-Down> or *<S-Down>* *<kPageDown>*
50<PageDown> or *<PageDown>* *CTRL-F*
51CTRL-F Scroll window [count] pages Forwards (downwards) in
52 the buffer. See also 'startofline' option.
Bram Moolenaar4399ef42005-02-12 14:29:27 +000053 When there is only one window the 'window' option
54 might be used.
Bram Moolenaar071d4272004-06-13 20:20:40 +000055
56 *z+*
57z+ Without [count]: Redraw with the line just below the
58 window at the top of the window. Put the cursor in
59 that line, at the first non-blank in the line.
60 With [count]: just like "z<CR>".
61
62==============================================================================
632. Scrolling upwards *scroll-up*
64
65The following commands move the edit window (the part of the buffer that you
66see) upwards (this means that more lines upwards in the text buffer can be
67seen):
68
69 *CTRL-Y*
70CTRL-Y Scroll window [count] lines upwards in the buffer.
Bram Moolenaar15142e22018-04-30 22:19:58 +020071 The text moves downwards on the screen.
Bram Moolenaar071d4272004-06-13 20:20:40 +000072 Note: When using the MS-Windows key bindings CTRL-Y is
73 remapped to redo.
74
75 *CTRL-U*
76CTRL-U Scroll window Upwards in the buffer. The number of
77 lines comes from the 'scroll' option (default: half a
78 screen). If [count] given, first set the 'scroll'
79 option to [count]. The cursor is moved the same
80 number of lines up in the file (if possible; when
81 lines wrap and when hitting the end of the file there
82 may be a difference). When the cursor is on the first
83 line of the buffer nothing happens and a beep is
84 produced. See also 'startofline' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +000085
86<S-Up> or *<S-Up>* *<kPageUp>*
87<PageUp> or *<PageUp>* *CTRL-B*
88CTRL-B Scroll window [count] pages Backwards (upwards) in the
89 buffer. See also 'startofline' option.
Bram Moolenaar4399ef42005-02-12 14:29:27 +000090 When there is only one window the 'window' option
91 might be used.
Bram Moolenaar071d4272004-06-13 20:20:40 +000092
93 *z^*
94z^ Without [count]: Redraw with the line just above the
95 window at the bottom of the window. Put the cursor in
96 that line, at the first non-blank in the line.
97 With [count]: First scroll the text to put the [count]
98 line at the bottom of the window, then redraw with the
99 line which is now at the top of the window at the
100 bottom of the window. Put the cursor in that line, at
101 the first non-blank in the line.
102
103==============================================================================
1043. Scrolling relative to cursor *scroll-cursor*
105
106The following commands reposition the edit window (the part of the buffer that
Bram Moolenaarc0514bf2016-11-17 14:50:09 +0100107you see) while keeping the cursor on the same line. Note that the 'scrolloff'
108option may cause context lines to show above and below the cursor.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109
110 *z<CR>*
111z<CR> Redraw, line [count] at top of window (default
112 cursor line). Put cursor at first non-blank in the
113 line.
114
115 *zt*
116zt Like "z<CR>", but leave the cursor in the same
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200117 column.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118
119 *zN<CR>*
120z{height}<CR> Redraw, make window {height} lines tall. This is
121 useful to make the number of lines small when screen
122 updating is very slow. Cannot make the height more
123 than the physical screen height.
124
125 *z.*
126z. Redraw, line [count] at center of window (default
127 cursor line). Put cursor at first non-blank in the
128 line.
129
130 *zz*
131zz Like "z.", but leave the cursor in the same column.
Bram Moolenaar06b5d512010-05-22 15:37:44 +0200132 Careful: If caps-lock is on, this command becomes
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200133 "ZZ": write buffer and exit!
Bram Moolenaar071d4272004-06-13 20:20:40 +0000134
135 *z-*
136z- Redraw, line [count] at bottom of window (default
137 cursor line). Put cursor at first non-blank in the
138 line.
139
140 *zb*
141zb Like "z-", but leave the cursor in the same column.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000142
143==============================================================================
1444. Scrolling horizontally *scroll-horizontal*
145
146For the following four commands the cursor follows the screen. If the
147character that the cursor is on is moved off the screen, the cursor is moved
148to the closest character that is on the screen. The value of 'sidescroll' is
149not used.
150
151z<Right> or *zl* *z<Right>*
Bram Moolenaar146522e2005-12-16 21:55:46 +0000152zl Move the view on the text [count] characters to the
153 right, thus scroll the text [count] characters to the
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200154 left. This only works when 'wrap' is off.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000155
156z<Left> or *zh* *z<Left>*
Bram Moolenaar146522e2005-12-16 21:55:46 +0000157zh Move the view on the text [count] characters to the
158 left, thus scroll the text [count] characters to the
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200159 right. This only works when 'wrap' is off.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000160
161 *zL*
Bram Moolenaar146522e2005-12-16 21:55:46 +0000162zL Move the view on the text half a screenwidth to the
163 right, thus scroll the text half a screenwidth to the
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200164 left. This only works when 'wrap' is off.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000165
166 *zH*
Bram Moolenaar146522e2005-12-16 21:55:46 +0000167zH Move the view on the text half a screenwidth to the
168 left, thus scroll the text half a screenwidth to the
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200169 right. This only works when 'wrap' is off.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000170
171For the following two commands the cursor is not moved in the text, only the
172text scrolls on the screen.
173
174 *zs*
Bram Moolenaar146522e2005-12-16 21:55:46 +0000175zs Scroll the text horizontally to position the cursor
Bram Moolenaar071d4272004-06-13 20:20:40 +0000176 at the start (left side) of the screen. This only
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200177 works when 'wrap' is off.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000178
179 *ze*
Bram Moolenaar146522e2005-12-16 21:55:46 +0000180ze Scroll the text horizontally to position the cursor
Bram Moolenaar071d4272004-06-13 20:20:40 +0000181 at the end (right side) of the screen. This only
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200182 works when 'wrap' is off.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000183
184==============================================================================
1855. Scrolling synchronously *scroll-binding*
186
187Occasionally, it is desirable to bind two or more windows together such that
Bram Moolenaar06b5d512010-05-22 15:37:44 +0200188when one window is scrolled, the other windows are also scrolled. In Vim,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000189windows can be given this behavior by setting the (window-specific)
190'scrollbind' option. When a window that has 'scrollbind' set is scrolled, all
191other 'scrollbind' windows are scrolled the same amount, if possible. The
192behavior of 'scrollbind' can be modified by the 'scrollopt' option.
193
194When using the scrollbars, the binding only happens when scrolling the window
195with focus (where the cursor is). You can use this to avoid scroll-binding
196for a moment without resetting options.
197
198When a window also has the 'diff' option set, the scroll-binding uses the
199differences between the two buffers to synchronize the position precisely.
200Otherwise the following method is used.
201
202 *scrollbind-relative*
203Each 'scrollbind' window keeps track of its "relative offset," which can be
204thought of as the difference between the current window's vertical scroll
205position and the other window's vertical scroll position. When one of the
206'scrollbind' windows is asked to vertically scroll past the beginning or end
207limit of its text, the window no longer scrolls, but remembers how far past
208the limit it wishes to be. The window keeps this information so that it can
209maintain the same relative offset, regardless of its being asked to scroll
210past its buffer's limits.
211
212However, if a 'scrollbind' window that has a relative offset that is past its
213buffer's limits is given the cursor focus, the other 'scrollbind' windows must
214jump to a location where the current window's relative offset is valid. This
Bram Moolenaar214641f2017-03-05 17:04:09 +0100215behavior can be changed by clearing the "jump" flag from the 'scrollopt'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000216option.
217
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000218 *syncbind* *:syncbind* *:sync*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000219:syncbind Force all 'scrollbind' windows to have the same
220 relative offset. I.e., when any of the 'scrollbind'
221 windows is scrolled to the top of its buffer, all of
222 the 'scrollbind' windows will also be at the top of
223 their buffers.
224
225 *scrollbind-quickadj*
226The 'scrollbind' flag is meaningful when using keyboard commands to vertically
227scroll a window, and also meaningful when using the vertical scrollbar of the
228window which has the cursor focus. However, when using the vertical scrollbar
229of a window which doesn't have the cursor focus, 'scrollbind' is ignored.
230This allows quick adjustment of the relative offset of 'scrollbind' windows.
231
232==============================================================================
2336. Scrolling with a mouse wheel *scroll-mouse-wheel*
234
235When your mouse has a scroll wheel, it should work with Vim in the GUI. How
236it works depends on your system. It might also work in an xterm
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +0200237|xterm-mouse-wheel|. By default only vertical scroll wheels are supported,
238but some GUIs also support horizontal scroll wheels.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000239
LemonBoyc27747e2022-05-07 12:25:40 +0100240On MS-Windows, if the scroll action causes input focus -problems, see
241|intellimouse-wheel-problems|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000242
LemonBoyc27747e2022-05-07 12:25:40 +0100243For Win32 and the X11 GUIs (Motif and GTK) scrolling the wheel generates key
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +0200244presses <ScrollWheelUp>, <ScrollWheelDown>, <ScrollWheelLeft> and
245<ScrollWheelRight>. For example, if you push the scroll wheel upwards a
246<ScrollWheelUp> key press is generated causing the window to scroll upwards
247(while the text is actually moving downwards). The default action for these
248keys are:
LemonBoyc27747e2022-05-07 12:25:40 +0100249 <ScrollWheelUp> scroll N lines up *<ScrollWheelUp>*
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +0200250 <S-ScrollWheelUp> scroll one page up *<S-ScrollWheelUp>*
251 <C-ScrollWheelUp> scroll one page up *<C-ScrollWheelUp>*
LemonBoyc27747e2022-05-07 12:25:40 +0100252 <ScrollWheelDown> scroll N lines down *<ScrollWheelDown>*
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +0200253 <S-ScrollWheelDown> scroll one page down *<S-ScrollWheelDown>*
254 <C-ScrollWheelDown> scroll one page down *<C-ScrollWheelDown>*
LemonBoyc27747e2022-05-07 12:25:40 +0100255 <ScrollWheelLeft> scroll N columns left *<ScrollWheelLeft>*
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +0200256 <S-ScrollWheelLeft> scroll one page left *<S-ScrollWheelLeft>*
257 <C-ScrollWheelLeft> scroll one page left *<C-ScrollWheelLeft>*
LemonBoyc27747e2022-05-07 12:25:40 +0100258 <ScrollWheelRight> scroll N columns right *<ScrollWheelRight>*
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +0200259 <S-ScrollWheelRight> scroll one page right *<S-ScrollWheelRight>*
260 <C-ScrollWheelRight> scroll one page right *<C-ScrollWheelRight>*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000261This should work in all modes, except when editing the command line.
262
LemonBoyc27747e2022-05-07 12:25:40 +0100263The value of N depends on the system. By default Vim scrolls three lines when
264moving vertically, and six columns when moving horizontally. On MS-Windows
265the amount of lines and columns for each scroll action is taken from the
266system-wide settings.
267
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +0200268Note that horizontal scrolling only works if 'nowrap' is set. Also, unless
269the "h" flag in 'guioptions' is set, the cursor moves to the longest visible
270line if the cursor line is about to be scrolled off the screen (similarly to
271how the horizontal scrollbar works).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000272
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +0200273You can modify the default behavior by mapping the keys. For example, to make
274the scroll wheel move one line or half a page in Normal mode: >
275 :map <ScrollWheelUp> <C-Y>
276 :map <S-ScrollWheelUp> <C-U>
277 :map <ScrollWheelDown> <C-E>
278 :map <S-ScrollWheelDown> <C-D>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000279You can also use Alt and Ctrl modifiers.
280
281This only works when Vim gets the scroll wheel events, of course. You can
282check if this works with the "xev" program.
283
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000284When using XFree86, the /etc/XF86Config file should have the correct entry for
Bram Moolenaar071d4272004-06-13 20:20:40 +0000285your mouse. For FreeBSD, this entry works for a Logitech scrollmouse: >
286 Protocol "MouseMan"
287 Device "/dev/psm0"
288 ZAxisMapping 4 5
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000289See the XFree86 documentation for information.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000290
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +0200291 *<MouseDown>* *<MouseUp>*
292The keys <MouseDown> and <MouseUp> have been deprecated. Use <ScrollWheelUp>
293instead of <MouseDown> and use <ScrollWheelDown> instead of <MouseUp>.
294
Bram Moolenaar071d4272004-06-13 20:20:40 +0000295 *xterm-mouse-wheel*
296To use the mouse wheel in a new xterm you only have to make the scroll wheel
297work in your Xserver, as mentioned above.
298
299To use the mouse wheel in an older xterm you must do this:
3001. Make it work in your Xserver, as mentioned above.
3012. Add translations for the xterm, so that the xterm will pass a scroll event
302 to Vim as an escape sequence.
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +02003033. Add mappings in Vim, to interpret the escape sequences as <ScrollWheelDown>
304 or <ScrollWheelUp> keys.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000305
306You can do the translations by adding this to your ~.Xdefaults file (or other
307file where your X resources are kept): >
308
309 XTerm*VT100.Translations: #override \n\
310 s<Btn4Down>: string("0x9b") string("[64~") \n\
311 s<Btn5Down>: string("0x9b") string("[65~") \n\
312 <Btn4Down>: string("0x9b") string("[62~") \n\
313 <Btn5Down>: string("0x9b") string("[63~") \n\
314 <Btn4Up>: \n\
315 <Btn5Up>:
316
317Add these mappings to your vimrc file: >
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +0200318 :map <M-Esc>[62~ <ScrollWheelUp>
319 :map! <M-Esc>[62~ <ScrollWheelUp>
320 :map <M-Esc>[63~ <ScrollWheelDown>
321 :map! <M-Esc>[63~ <ScrollWheelDown>
322 :map <M-Esc>[64~ <S-ScrollWheelUp>
323 :map! <M-Esc>[64~ <S-ScrollWheelUp>
324 :map <M-Esc>[65~ <S-ScrollWheelDown>
325 :map! <M-Esc>[65~ <S-ScrollWheelDown>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000326<
Bram Moolenaar91f84f62018-07-29 15:07:52 +0200327 vim:tw=78:ts=8:noet:ft=help:norl: