blob: 35301f618c9354b6b5bf007f0e4f273ebcc40e48 [file] [log] [blame]
Bram Moolenaarc0514bf2016-11-17 14:50:09 +01001*scroll.txt* For Vim version 8.0. Last change: 2016 Nov 10
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.
35 Mnemonic: Extra lines.
36
37 *CTRL-D*
38CTRL-D Scroll window Downwards in the buffer. The number of
39 lines comes from the 'scroll' option (default: half a
40 screen). If [count] given, first set 'scroll' option
41 to [count]. The cursor is moved the same number of
42 lines down in the file (if possible; when lines wrap
43 and when hitting the end of the file there may be a
44 difference). When the cursor is on the last line of
45 the buffer nothing happens and a beep is produced.
46 See also 'startofline' option.
47 {difference from vi: Vim scrolls 'scroll' screen
48 lines, instead of file lines; makes a difference when
49 lines wrap}
50
51<S-Down> or *<S-Down>* *<kPageDown>*
52<PageDown> or *<PageDown>* *CTRL-F*
53CTRL-F Scroll window [count] pages Forwards (downwards) in
54 the buffer. See also 'startofline' option.
Bram Moolenaar4399ef42005-02-12 14:29:27 +000055 When there is only one window the 'window' option
56 might be used.
Bram Moolenaar071d4272004-06-13 20:20:40 +000057
58 *z+*
59z+ Without [count]: Redraw with the line just below the
60 window at the top of the window. Put the cursor in
61 that line, at the first non-blank in the line.
62 With [count]: just like "z<CR>".
63
64==============================================================================
652. Scrolling upwards *scroll-up*
66
67The following commands move the edit window (the part of the buffer that you
68see) upwards (this means that more lines upwards in the text buffer can be
69seen):
70
71 *CTRL-Y*
72CTRL-Y Scroll window [count] lines upwards in the buffer.
73 Note: When using the MS-Windows key bindings CTRL-Y is
74 remapped to redo.
75
76 *CTRL-U*
77CTRL-U Scroll window Upwards in the buffer. The number of
78 lines comes from the 'scroll' option (default: half a
79 screen). If [count] given, first set the 'scroll'
80 option to [count]. The cursor is moved the same
81 number of lines up in the file (if possible; when
82 lines wrap and when hitting the end of the file there
83 may be a difference). When the cursor is on the first
84 line of the buffer nothing happens and a beep is
85 produced. See also 'startofline' option.
86 {difference from vi: Vim scrolls 'scroll' screen
87 lines, instead of file lines; makes a difference when
88 lines wrap}
89
90<S-Up> or *<S-Up>* *<kPageUp>*
91<PageUp> or *<PageUp>* *CTRL-B*
92CTRL-B Scroll window [count] pages Backwards (upwards) in the
93 buffer. See also 'startofline' option.
Bram Moolenaar4399ef42005-02-12 14:29:27 +000094 When there is only one window the 'window' option
95 might be used.
Bram Moolenaar071d4272004-06-13 20:20:40 +000096
97 *z^*
98z^ Without [count]: Redraw with the line just above the
99 window at the bottom of the window. Put the cursor in
100 that line, at the first non-blank in the line.
101 With [count]: First scroll the text to put the [count]
102 line at the bottom of the window, then redraw with the
103 line which is now at the top of the window at the
104 bottom of the window. Put the cursor in that line, at
105 the first non-blank in the line.
106
107==============================================================================
1083. Scrolling relative to cursor *scroll-cursor*
109
110The following commands reposition the edit window (the part of the buffer that
Bram Moolenaarc0514bf2016-11-17 14:50:09 +0100111you see) while keeping the cursor on the same line. Note that the 'scrolloff'
112option may cause context lines to show above and below the cursor.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000113
114 *z<CR>*
115z<CR> Redraw, line [count] at top of window (default
116 cursor line). Put cursor at first non-blank in the
117 line.
118
119 *zt*
120zt Like "z<CR>", but leave the cursor in the same
121 column. {not in Vi}
122
123 *zN<CR>*
124z{height}<CR> Redraw, make window {height} lines tall. This is
125 useful to make the number of lines small when screen
126 updating is very slow. Cannot make the height more
127 than the physical screen height.
128
129 *z.*
130z. Redraw, line [count] at center of window (default
131 cursor line). Put cursor at first non-blank in the
132 line.
133
134 *zz*
135zz Like "z.", but leave the cursor in the same column.
Bram Moolenaar06b5d512010-05-22 15:37:44 +0200136 Careful: If caps-lock is on, this command becomes
Bram Moolenaar071d4272004-06-13 20:20:40 +0000137 "ZZ": write buffer and exit! {not in Vi}
138
139 *z-*
140z- Redraw, line [count] at bottom of window (default
141 cursor line). Put cursor at first non-blank in the
142 line.
143
144 *zb*
145zb Like "z-", but leave the cursor in the same column.
146 {not in Vi}
147
148==============================================================================
1494. Scrolling horizontally *scroll-horizontal*
150
151For the following four commands the cursor follows the screen. If the
152character that the cursor is on is moved off the screen, the cursor is moved
153to the closest character that is on the screen. The value of 'sidescroll' is
154not used.
155
156z<Right> or *zl* *z<Right>*
Bram Moolenaar146522e2005-12-16 21:55:46 +0000157zl Move the view on the text [count] characters to the
158 right, thus scroll the text [count] characters to the
159 left. This only works when 'wrap' is off. {not in
160 Vi}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000161
162z<Left> or *zh* *z<Left>*
Bram Moolenaar146522e2005-12-16 21:55:46 +0000163zh Move the view on the text [count] characters to the
164 left, thus scroll the text [count] characters to the
165 right. This only works when 'wrap' is off. {not in
166 Vi}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000167
168 *zL*
Bram Moolenaar146522e2005-12-16 21:55:46 +0000169zL Move the view on the text half a screenwidth to the
170 right, thus scroll the text half a screenwidth to the
171 left. This only works when 'wrap' is off. {not in
172 Vi}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000173
174 *zH*
Bram Moolenaar146522e2005-12-16 21:55:46 +0000175zH Move the view on the text half a screenwidth to the
176 left, thus scroll the text half a screenwidth to the
177 right. This only works when 'wrap' is off. {not in
178 Vi}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000179
180For the following two commands the cursor is not moved in the text, only the
181text scrolls on the screen.
182
183 *zs*
Bram Moolenaar146522e2005-12-16 21:55:46 +0000184zs Scroll the text horizontally to position the cursor
Bram Moolenaar071d4272004-06-13 20:20:40 +0000185 at the start (left side) of the screen. This only
186 works when 'wrap' is off. {not in Vi}
187
188 *ze*
Bram Moolenaar146522e2005-12-16 21:55:46 +0000189ze Scroll the text horizontally to position the cursor
Bram Moolenaar071d4272004-06-13 20:20:40 +0000190 at the end (right side) of the screen. This only
191 works when 'wrap' is off. {not in Vi}
192
193==============================================================================
1945. Scrolling synchronously *scroll-binding*
195
196Occasionally, it is desirable to bind two or more windows together such that
Bram Moolenaar06b5d512010-05-22 15:37:44 +0200197when one window is scrolled, the other windows are also scrolled. In Vim,
Bram Moolenaar071d4272004-06-13 20:20:40 +0000198windows can be given this behavior by setting the (window-specific)
199'scrollbind' option. When a window that has 'scrollbind' set is scrolled, all
200other 'scrollbind' windows are scrolled the same amount, if possible. The
201behavior of 'scrollbind' can be modified by the 'scrollopt' option.
202
203When using the scrollbars, the binding only happens when scrolling the window
204with focus (where the cursor is). You can use this to avoid scroll-binding
205for a moment without resetting options.
206
207When a window also has the 'diff' option set, the scroll-binding uses the
208differences between the two buffers to synchronize the position precisely.
209Otherwise the following method is used.
210
211 *scrollbind-relative*
212Each 'scrollbind' window keeps track of its "relative offset," which can be
213thought of as the difference between the current window's vertical scroll
214position and the other window's vertical scroll position. When one of the
215'scrollbind' windows is asked to vertically scroll past the beginning or end
216limit of its text, the window no longer scrolls, but remembers how far past
217the limit it wishes to be. The window keeps this information so that it can
218maintain the same relative offset, regardless of its being asked to scroll
219past its buffer's limits.
220
221However, if a 'scrollbind' window that has a relative offset that is past its
222buffer's limits is given the cursor focus, the other 'scrollbind' windows must
223jump to a location where the current window's relative offset is valid. This
Bram Moolenaar214641f2017-03-05 17:04:09 +0100224behavior can be changed by clearing the "jump" flag from the 'scrollopt'
Bram Moolenaar071d4272004-06-13 20:20:40 +0000225option.
226
Bram Moolenaarc81e5e72007-05-05 18:24:42 +0000227 *syncbind* *:syncbind* *:sync*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000228:syncbind Force all 'scrollbind' windows to have the same
229 relative offset. I.e., when any of the 'scrollbind'
230 windows is scrolled to the top of its buffer, all of
231 the 'scrollbind' windows will also be at the top of
232 their buffers.
233
234 *scrollbind-quickadj*
235The 'scrollbind' flag is meaningful when using keyboard commands to vertically
236scroll a window, and also meaningful when using the vertical scrollbar of the
237window which has the cursor focus. However, when using the vertical scrollbar
238of a window which doesn't have the cursor focus, 'scrollbind' is ignored.
239This allows quick adjustment of the relative offset of 'scrollbind' windows.
240
241==============================================================================
2426. Scrolling with a mouse wheel *scroll-mouse-wheel*
243
244When your mouse has a scroll wheel, it should work with Vim in the GUI. How
245it works depends on your system. It might also work in an xterm
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +0200246|xterm-mouse-wheel|. By default only vertical scroll wheels are supported,
247but some GUIs also support horizontal scroll wheels.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000248
249For the Win32 GUI the scroll action is hard coded. It works just like
250dragging the scrollbar of the current window. How many lines are scrolled
251depends on your mouse driver. If the scroll action causes input focus
252problems, see |intellimouse-wheel-problems|.
253
254For the X11 GUIs (Motif, Athena and GTK) scrolling the wheel generates key
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +0200255presses <ScrollWheelUp>, <ScrollWheelDown>, <ScrollWheelLeft> and
256<ScrollWheelRight>. For example, if you push the scroll wheel upwards a
257<ScrollWheelUp> key press is generated causing the window to scroll upwards
258(while the text is actually moving downwards). The default action for these
259keys are:
260 <ScrollWheelUp> scroll three lines up *<ScrollWheelUp>*
261 <S-ScrollWheelUp> scroll one page up *<S-ScrollWheelUp>*
262 <C-ScrollWheelUp> scroll one page up *<C-ScrollWheelUp>*
263 <ScrollWheelDown> scroll three lines down *<ScrollWheelDown>*
264 <S-ScrollWheelDown> scroll one page down *<S-ScrollWheelDown>*
265 <C-ScrollWheelDown> scroll one page down *<C-ScrollWheelDown>*
266 <ScrollWheelLeft> scroll six columns left *<ScrollWheelLeft>*
267 <S-ScrollWheelLeft> scroll one page left *<S-ScrollWheelLeft>*
268 <C-ScrollWheelLeft> scroll one page left *<C-ScrollWheelLeft>*
269 <ScrollWheelRight> scroll six columns right *<ScrollWheelRight>*
270 <S-ScrollWheelRight> scroll one page right *<S-ScrollWheelRight>*
271 <C-ScrollWheelRight> scroll one page right *<C-ScrollWheelRight>*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000272This should work in all modes, except when editing the command line.
273
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +0200274Note that horizontal scrolling only works if 'nowrap' is set. Also, unless
275the "h" flag in 'guioptions' is set, the cursor moves to the longest visible
276line if the cursor line is about to be scrolled off the screen (similarly to
277how the horizontal scrollbar works).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000278
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +0200279You can modify the default behavior by mapping the keys. For example, to make
280the scroll wheel move one line or half a page in Normal mode: >
281 :map <ScrollWheelUp> <C-Y>
282 :map <S-ScrollWheelUp> <C-U>
283 :map <ScrollWheelDown> <C-E>
284 :map <S-ScrollWheelDown> <C-D>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000285You can also use Alt and Ctrl modifiers.
286
287This only works when Vim gets the scroll wheel events, of course. You can
288check if this works with the "xev" program.
289
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000290When using XFree86, the /etc/XF86Config file should have the correct entry for
Bram Moolenaar071d4272004-06-13 20:20:40 +0000291your mouse. For FreeBSD, this entry works for a Logitech scrollmouse: >
292 Protocol "MouseMan"
293 Device "/dev/psm0"
294 ZAxisMapping 4 5
Bram Moolenaar13fcaaf2005-04-15 21:13:42 +0000295See the XFree86 documentation for information.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000296
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +0200297 *<MouseDown>* *<MouseUp>*
298The keys <MouseDown> and <MouseUp> have been deprecated. Use <ScrollWheelUp>
299instead of <MouseDown> and use <ScrollWheelDown> instead of <MouseUp>.
300
Bram Moolenaar071d4272004-06-13 20:20:40 +0000301 *xterm-mouse-wheel*
302To use the mouse wheel in a new xterm you only have to make the scroll wheel
303work in your Xserver, as mentioned above.
304
305To use the mouse wheel in an older xterm you must do this:
3061. Make it work in your Xserver, as mentioned above.
3072. Add translations for the xterm, so that the xterm will pass a scroll event
308 to Vim as an escape sequence.
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +02003093. Add mappings in Vim, to interpret the escape sequences as <ScrollWheelDown>
310 or <ScrollWheelUp> keys.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000311
312You can do the translations by adding this to your ~.Xdefaults file (or other
313file where your X resources are kept): >
314
315 XTerm*VT100.Translations: #override \n\
316 s<Btn4Down>: string("0x9b") string("[64~") \n\
317 s<Btn5Down>: string("0x9b") string("[65~") \n\
318 <Btn4Down>: string("0x9b") string("[62~") \n\
319 <Btn5Down>: string("0x9b") string("[63~") \n\
320 <Btn4Up>: \n\
321 <Btn5Up>:
322
323Add these mappings to your vimrc file: >
Bram Moolenaar8d9b40e2010-07-25 15:49:07 +0200324 :map <M-Esc>[62~ <ScrollWheelUp>
325 :map! <M-Esc>[62~ <ScrollWheelUp>
326 :map <M-Esc>[63~ <ScrollWheelDown>
327 :map! <M-Esc>[63~ <ScrollWheelDown>
328 :map <M-Esc>[64~ <S-ScrollWheelUp>
329 :map! <M-Esc>[64~ <S-ScrollWheelUp>
330 :map <M-Esc>[65~ <S-ScrollWheelDown>
331 :map! <M-Esc>[65~ <S-ScrollWheelDown>
Bram Moolenaar071d4272004-06-13 20:20:40 +0000332<
333 vim:tw=78:ts=8:ft=help:norl: