blob: 38282e7825843d272a6bf75d39130c3fac5025a3 [file] [log] [blame]
Bram Moolenaar207f0092020-08-30 17:20:20 +02001*motion.txt* For Vim version 8.2. Last change: 2020 Aug 24
Bram Moolenaar071d4272004-06-13 20:20:40 +00002
3
4 VIM REFERENCE MANUAL by Bram Moolenaar
5
6
7Cursor motions *cursor-motions* *navigation*
8
9These commands move the cursor position. If the new position is off of the
10screen, the screen is scrolled to show the cursor (see also 'scrolljump' and
11'scrolloff' options).
12
131. Motions and operators |operator|
142. Left-right motions |left-right-motions|
153. Up-down motions |up-down-motions|
164. Word motions |word-motions|
175. Text object motions |object-motions|
186. Text object selection |object-select|
197. Marks |mark-motions|
208. Jumps |jump-motions|
219. Various motions |various-motions|
22
23General remarks:
24
25If you want to know where you are in the file use the "CTRL-G" command
26|CTRL-G| or the "g CTRL-G" command |g_CTRL-G|. If you set the 'ruler' option,
27the cursor position is continuously shown in the status line (which slows down
28Vim a little).
29
30Experienced users prefer the hjkl keys because they are always right under
31their fingers. Beginners often prefer the arrow keys, because they do not
32know what the hjkl keys do. The mnemonic value of hjkl is clear from looking
33at the keyboard. Think of j as an arrow pointing downwards.
34
35The 'virtualedit' option can be set to make it possible to move the cursor to
36positions where there is no character or halfway a character.
37
38==============================================================================
391. Motions and operators *operator*
40
41The motion commands can be used after an operator command, to have the command
42operate on the text that was moved over. That is the text between the cursor
43position before and after the motion. Operators are generally used to delete
44or change text. The following operators are available:
45
46 |c| c change
47 |d| d delete
48 |y| y yank into register (does not change the text)
49 |~| ~ swap case (only if 'tildeop' is set)
50 |g~| g~ swap case
51 |gu| gu make lowercase
52 |gU| gU make uppercase
53 |!| ! filter through an external program
54 |=| = filter through 'equalprg' or C-indenting if empty
55 |gq| gq text formatting
Bram Moolenaar68e65602019-05-26 21:33:31 +020056 |gw| gw text formatting with no cursor movement
Bram Moolenaar071d4272004-06-13 20:20:40 +000057 |g?| g? ROT13 encoding
58 |>| > shift right
59 |<| < shift left
60 |zf| zf define a fold
Bram Moolenaar6c35bea2012-07-25 17:49:10 +020061 |g@| g@ call function set with the 'operatorfunc' option
Bram Moolenaar071d4272004-06-13 20:20:40 +000062
63If the motion includes a count and the operator also had a count before it,
64the two counts are multiplied. For example: "2d3w" deletes six words.
65
66After applying the operator the cursor is mostly left at the start of the text
67that was operated upon. For example, "yfe" doesn't move the cursor, but "yFe"
68moves the cursor leftwards to the "e" where the yank started.
69
70 *linewise* *characterwise*
71The operator either affects whole lines, or the characters between the start
72and end position. Generally, motions that move between lines affect lines
73(are linewise), and motions that move within a line affect characters (are
74characterwise). However, there are some exceptions.
75
76 *exclusive* *inclusive*
Bram Moolenaar78984f52005-08-01 07:19:10 +000077A character motion is either inclusive or exclusive. When inclusive, the
78start and end position of the motion are included in the operation. When
79exclusive, the last character towards the end of the buffer is not included.
80Linewise motions always include the start and end position.
Bram Moolenaar071d4272004-06-13 20:20:40 +000081
Bram Moolenaar78984f52005-08-01 07:19:10 +000082Which motions are linewise, inclusive or exclusive is mentioned with the
83command. There are however, two general exceptions:
Bram Moolenaar071d4272004-06-13 20:20:40 +0000841. If the motion is exclusive and the end of the motion is in column 1, the
85 end of the motion is moved to the end of the previous line and the motion
86 becomes inclusive. Example: "}" moves to the first line after a paragraph,
87 but "d}" will not include that line.
Bram Moolenaar5eb86f92004-07-26 12:53:41 +000088 *exclusive-linewise*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000892. If the motion is exclusive, the end of the motion is in column 1 and the
90 start of the motion was at or before the first non-blank in the line, the
91 motion becomes linewise. Example: If a paragraph begins with some blanks
92 and you do "d}" while standing on the first non-blank, all the lines of
93 the paragraph are deleted, including the blanks. If you do a put now, the
94 deleted lines will be inserted below the cursor position.
95
96Note that when the operator is pending (the operator command is typed, but the
97motion isn't yet), a special set of mappings can be used. See |:omap|.
98
99Instead of first giving the operator and then a motion you can use Visual
100mode: mark the start of the text with "v", move the cursor to the end of the
101text that is to be affected and then hit the operator. The text between the
102start and the cursor position is highlighted, so you can see what text will
103be operated upon. This allows much more freedom, but requires more key
104strokes and has limited redo functionality. See the chapter on Visual mode
105|Visual-mode|.
106
107You can use a ":" command for a motion. For example "d:call FindEnd()".
Bram Moolenaarac7bd632013-03-19 11:35:58 +0100108But this can't be repeated with "." if the command is more than one line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000109This can be repeated: >
110 d:call search("f")<CR>
111This cannot be repeated: >
112 d:if 1<CR>
113 call search("f")<CR>
114 endif<CR>
Bram Moolenaarac7bd632013-03-19 11:35:58 +0100115Note that when using ":" any motion becomes characterwise exclusive.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000116
Bram Moolenaarc8c88492018-12-27 23:59:26 +0100117 *forced-motion*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000118FORCING A MOTION TO BE LINEWISE, CHARACTERWISE OR BLOCKWISE
119
120When a motion is not of the type you would like to use, you can force another
121type by using "v", "V" or CTRL-V just after the operator.
122Example: >
123 dj
124deletes two lines >
125 dvj
126deletes from the cursor position until the character below the cursor >
127 d<C-V>j
128deletes the character under the cursor and the character below the cursor. >
129
130Be careful with forcing a linewise movement to be used characterwise or
131blockwise, the column may not always be defined.
132
133 *o_v*
134v When used after an operator, before the motion command: Force
135 the operator to work characterwise, also when the motion is
136 linewise. If the motion was linewise, it will become
137 |exclusive|.
138 If the motion already was characterwise, toggle
139 inclusive/exclusive. This can be used to make an exclusive
140 motion inclusive and an inclusive motion exclusive.
141
142 *o_V*
143V When used after an operator, before the motion command: Force
144 the operator to work linewise, also when the motion is
145 characterwise.
146
147 *o_CTRL-V*
148CTRL-V When used after an operator, before the motion command: Force
149 the operator to work blockwise. This works like Visual block
150 mode selection, with the corners defined by the cursor
151 position before and after the motion.
152
153==============================================================================
1542. Left-right motions *left-right-motions*
155
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +0100156These commands move the cursor to the specified column in the current line.
157They stop at the first column and at the end of the line, except "$", which
158may move to one of the next lines. See 'whichwrap' option to make some of the
159commands move across line boundaries.
160
Bram Moolenaar071d4272004-06-13 20:20:40 +0000161h or *h*
162<Left> or *<Left>*
163CTRL-H or *CTRL-H* *<BS>*
164<BS> [count] characters to the left. |exclusive| motion.
165 Note: If you prefer <BS> to delete a character, use
166 the mapping:
167 :map CTRL-V<BS> X
168 (to enter "CTRL-V<BS>" type the CTRL-V key, followed
169 by the <BS> key)
170 See |:fixdel| if the <BS> key does not do what you
171 want.
172
173l or *l*
174<Right> or *<Right>* *<Space>*
175<Space> [count] characters to the right. |exclusive| motion.
Bram Moolenaarf2571c62015-06-09 19:44:55 +0200176 See the 'whichwrap' option for adjusting the behavior
177 at end of line
Bram Moolenaar071d4272004-06-13 20:20:40 +0000178
179 *0*
1800 To the first character of the line. |exclusive|
Bram Moolenaar9964e462007-05-05 17:54:07 +0000181 motion.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000182
183 *<Home>* *<kHome>*
184<Home> To the first character of the line. |exclusive|
Bram Moolenaar9964e462007-05-05 17:54:07 +0000185 motion. When moving up or down next, stay in same
186 TEXT column (if possible). Most other commands stay
187 in the same SCREEN column. <Home> works like "1|",
188 which differs from "0" when the line starts with a
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200189 <Tab>.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000190
191 *^*
192^ To the first non-blank character of the line.
193 |exclusive| motion.
194
195 *$* *<End>* *<kEnd>*
196$ or <End> To the end of the line. When a count is given also go
Bram Moolenaar036986f2017-03-16 17:41:02 +0100197 [count - 1] lines downward. |inclusive| motion.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000198 In Visual mode the cursor goes to just after the last
199 character in the line.
200 When 'virtualedit' is active, "$" may move the cursor
201 back from past the end of the line to the last
202 character in the line.
203
204 *g_*
205g_ To the last non-blank character of the line and
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200206 [count - 1] lines downward |inclusive|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000207
208 *g0* *g<Home>*
209g0 or g<Home> When lines wrap ('wrap' on): To the first character of
210 the screen line. |exclusive| motion. Differs from
211 "0" when a line is wider than the screen.
212 When lines don't wrap ('wrap' off): To the leftmost
213 character of the current line that is on the screen.
214 Differs from "0" when the first character of the line
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200215 is not on the screen.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000216
217 *g^*
218g^ When lines wrap ('wrap' on): To the first non-blank
219 character of the screen line. |exclusive| motion.
220 Differs from "^" when a line is wider than the screen.
221 When lines don't wrap ('wrap' off): To the leftmost
222 non-blank character of the current line that is on the
223 screen. Differs from "^" when the first non-blank
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200224 character of the line is not on the screen.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000225
226 *gm*
227gm Like "g0", but half a screenwidth to the right (or as
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200228 much as possible).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000229
Bram Moolenaar1ff14ba2019-11-02 14:09:23 +0100230 *gM*
Bram Moolenaar8b530c12019-10-28 02:13:05 +0100231gM Like "g0", but to halfway the text of the line.
232 With a count: to this percentage of text in the line.
233 Thus "10gM" is near the start of the text and "90gM"
234 is near the end of the text.
235
Bram Moolenaar071d4272004-06-13 20:20:40 +0000236 *g$* *g<End>*
237g$ or g<End> When lines wrap ('wrap' on): To the last character of
238 the screen line and [count - 1] screen lines downward
239 |inclusive|. Differs from "$" when a line is wider
240 than the screen.
241 When lines don't wrap ('wrap' off): To the rightmost
242 character of the current line that is visible on the
243 screen. Differs from "$" when the last character of
244 the line is not on the screen or when a count is used.
245 Additionally, vertical movements keep the column,
246 instead of going to the end of the line.
Bram Moolenaar9ba7e172013-07-17 22:37:26 +0200247 When 'virtualedit' is enabled moves to the end of the
248 screen line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000249
250 *bar*
251| To screen column [count] in the current line.
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +0100252 |exclusive| motion. Ceci n'est pas une pipe.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000253
254 *f*
255f{char} To [count]'th occurrence of {char} to the right. The
256 cursor is placed on {char} |inclusive|.
257 {char} can be entered as a digraph |digraph-arg|.
258 When 'encoding' is set to Unicode, composing
259 characters may be used, see |utf-8-char-arg|.
260 |:lmap| mappings apply to {char}. The CTRL-^ command
261 in Insert mode can be used to switch this on/off
262 |i_CTRL-^|.
263
264 *F*
265F{char} To the [count]'th occurrence of {char} to the left.
Bram Moolenaar78984f52005-08-01 07:19:10 +0000266 The cursor is placed on {char} |exclusive|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000267 {char} can be entered like with the |f| command.
268
269 *t*
270t{char} Till before [count]'th occurrence of {char} to the
271 right. The cursor is placed on the character left of
272 {char} |inclusive|.
273 {char} can be entered like with the |f| command.
274
275 *T*
276T{char} Till after [count]'th occurrence of {char} to the
277 left. The cursor is placed on the character right of
Bram Moolenaar78984f52005-08-01 07:19:10 +0000278 {char} |exclusive|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000279 {char} can be entered like with the |f| command.
280
281 *;*
Bram Moolenaar8b3e0332011-06-26 05:36:34 +0200282; Repeat latest f, t, F or T [count] times. See |cpo-;|
Bram Moolenaar071d4272004-06-13 20:20:40 +0000283
284 *,*
285, Repeat latest f, t, F or T in opposite direction
Bram Moolenaar8b3e0332011-06-26 05:36:34 +0200286 [count] times. See also |cpo-;|
Bram Moolenaar071d4272004-06-13 20:20:40 +0000287
Bram Moolenaar071d4272004-06-13 20:20:40 +0000288==============================================================================
2893. Up-down motions *up-down-motions*
290
291k or *k*
292<Up> or *<Up>* *CTRL-P*
293CTRL-P [count] lines upward |linewise|.
294
295j or *j*
296<Down> or *<Down>*
297CTRL-J or *CTRL-J*
298<NL> or *<NL>* *CTRL-N*
299CTRL-N [count] lines downward |linewise|.
300
301gk or *gk* *g<Up>*
302g<Up> [count] display lines upward. |exclusive| motion.
303 Differs from 'k' when lines wrap, and when used with
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200304 an operator, because it's not linewise.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000305
306gj or *gj* *g<Down>*
307g<Down> [count] display lines downward. |exclusive| motion.
308 Differs from 'j' when lines wrap, and when used with
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200309 an operator, because it's not linewise.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000310
311 *-*
312- <minus> [count] lines upward, on the first non-blank
313 character |linewise|.
314
315+ or *+*
316CTRL-M or *CTRL-M* *<CR>*
317<CR> [count] lines downward, on the first non-blank
318 character |linewise|.
319
320 *_*
321_ <underscore> [count] - 1 lines downward, on the first non-blank
322 character |linewise|.
323
324 *G*
325G Goto line [count], default last line, on the first
326 non-blank character |linewise|. If 'startofline' not
327 set, keep the same column.
Bram Moolenaar26967612019-03-17 17:13:16 +0100328 G is one of the |jump-motions|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000329
330 *<C-End>*
331<C-End> Goto line [count], default last line, on the last
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200332 character |inclusive|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000333
334<C-Home> or *gg* *<C-Home>*
335gg Goto line [count], default first line, on the first
336 non-blank character |linewise|. If 'startofline' not
337 set, keep the same column.
338
Bram Moolenaar9b451252012-08-15 17:43:31 +0200339 *:[range]*
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +0100340:[range] Set the cursor on the last line number in [range].
341 [range] can also be just one line number, e.g., ":1"
342 or ":'m".
Bram Moolenaar00a927d2010-05-14 23:24:24 +0200343 In contrast with |G| this command does not modify the
344 |jumplist|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000345 *N%*
346{count}% Go to {count} percentage in the file, on the first
347 non-blank in the line |linewise|. To compute the new
348 line number this formula is used:
349 ({count} * number-of-lines + 99) / 100
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200350 See also 'startofline' option.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000351
352:[range]go[to] [count] *:go* *:goto* *go*
Bram Moolenaar92dff182014-02-11 19:15:50 +0100353[count]go Go to [count] byte in the buffer. Default [count] is
Bram Moolenaar071d4272004-06-13 20:20:40 +0000354 one, start of the file. When giving [range], the
355 last number in it used as the byte count. End-of-line
356 characters are counted depending on the current
357 'fileformat' setting.
Bram Moolenaar251e1912011-06-19 05:09:16 +0200358 Also see the |line2byte()| function, and the 'o'
359 option in 'statusline'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000360 {not available when compiled without the
361 |+byte_offset| feature}
362
363These commands move to the specified line. They stop when reaching the first
364or the last line. The first two commands put the cursor in the same column
365(if possible) as it was after the last command that changed the column,
366except after the "$" command, then the cursor will be put on the last
367character of the line.
368
Bram Moolenaar7c626922005-02-07 22:01:03 +0000369If "k", "-" or CTRL-P is used with a [count] and there are less than [count]
370lines above the cursor and the 'cpo' option includes the "-" flag it is an
371error. |cpo--|.
372
Bram Moolenaar071d4272004-06-13 20:20:40 +0000373==============================================================================
3744. Word motions *word-motions*
375
376<S-Right> or *<S-Right>* *w*
377w [count] words forward. |exclusive| motion.
378
379<C-Right> or *<C-Right>* *W*
380W [count] WORDS forward. |exclusive| motion.
381
382 *e*
383e Forward to the end of word [count] |inclusive|.
Bram Moolenaar446cb832008-06-24 21:56:24 +0000384 Does not stop in an empty line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000385
386 *E*
387E Forward to the end of WORD [count] |inclusive|.
Bram Moolenaar446cb832008-06-24 21:56:24 +0000388 Does not stop in an empty line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000389
390<S-Left> or *<S-Left>* *b*
391b [count] words backward. |exclusive| motion.
392
393<C-Left> or *<C-Left>* *B*
394B [count] WORDS backward. |exclusive| motion.
395
396 *ge*
397ge Backward to the end of word [count] |inclusive|.
398
399 *gE*
400gE Backward to the end of WORD [count] |inclusive|.
401
402These commands move over words or WORDS.
403 *word*
404A word consists of a sequence of letters, digits and underscores, or a
405sequence of other non-blank characters, separated with white space (spaces,
Bram Moolenaar4770d092006-01-12 23:22:24 +0000406tabs, <EOL>). This can be changed with the 'iskeyword' option. An empty line
407is also considered to be a word.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000408 *WORD*
409A WORD consists of a sequence of non-blank characters, separated with white
Bram Moolenaar4770d092006-01-12 23:22:24 +0000410space. An empty line is also considered to be a WORD.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000411
412A sequence of folded lines is counted for one word of a single character.
413"w" and "W", "e" and "E" move to the start/end of the first word or WORD after
414a range of folded lines. "b" and "B" move to the start of the first word or
415WORD before the fold.
416
417Special case: "cw" and "cW" are treated like "ce" and "cE" if the cursor is
418on a non-blank. This is because "cw" is interpreted as change-word, and a
Bram Moolenaara6c27c42019-05-09 19:16:22 +0200419word does not include the following white space.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000420
421Another special case: When using the "w" motion in combination with an
422operator and the last word moved over is at the end of a line, the end of
423that word becomes the end of the operated text, not the first word in the
424next line.
425
426The original Vi implementation of "e" is buggy. For example, the "e" command
427will stop on the first character of a line if the previous line was empty.
428But when you use "2e" this does not happen. In Vim "ee" and "2e" are the
429same, which is more logical. However, this causes a small incompatibility
430between Vi and Vim.
431
432==============================================================================
4335. Text object motions *object-motions*
434
435 *(*
436( [count] sentences backward. |exclusive| motion.
437
438 *)*
439) [count] sentences forward. |exclusive| motion.
440
441 *{*
442{ [count] paragraphs backward. |exclusive| motion.
443
444 *}*
445} [count] paragraphs forward. |exclusive| motion.
446
447 *]]*
448]] [count] sections forward or to the next '{' in the
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000449 first column. When used after an operator, then also
450 stops below a '}' in the first column. |exclusive|
451 Note that |exclusive-linewise| often applies.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000452
453 *][*
454][ [count] sections forward or to the next '}' in the
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000455 first column. |exclusive|
456 Note that |exclusive-linewise| often applies.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000457
458 *[[*
459[[ [count] sections backward or to the previous '{' in
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000460 the first column. |exclusive|
461 Note that |exclusive-linewise| often applies.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000462
463 *[]*
464[] [count] sections backward or to the previous '}' in
Bram Moolenaar5eb86f92004-07-26 12:53:41 +0000465 the first column. |exclusive|
466 Note that |exclusive-linewise| often applies.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000467
468These commands move over three kinds of text objects.
469
470 *sentence*
471A sentence is defined as ending at a '.', '!' or '?' followed by either the
472end of a line, or by a space or tab. Any number of closing ')', ']', '"'
473and ''' characters may appear after the '.', '!' or '?' before the spaces,
474tabs or end of line. A paragraph and section boundary is also a sentence
475boundary.
476If the 'J' flag is present in 'cpoptions', at least two spaces have to
477follow the punctuation mark; <Tab>s are not recognized as white space.
478The definition of a sentence cannot be changed.
479
480 *paragraph*
481A paragraph begins after each empty line, and also at each of a set of
482paragraph macros, specified by the pairs of characters in the 'paragraphs'
Bram Moolenaar446cb832008-06-24 21:56:24 +0000483option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to
484the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in
485the first column). A section boundary is also a paragraph boundary.
Bram Moolenaar4399ef42005-02-12 14:29:27 +0000486Note that a blank line (only containing white space) is NOT a paragraph
487boundary.
488Also note that this does not include a '{' or '}' in the first column. When
489the '{' flag is in 'cpoptions' then '{' in the first column is used as a
490paragraph boundary |posix|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000491
492 *section*
493A section begins after a form-feed (<C-L>) in the first column and at each of
494a set of section macros, specified by the pairs of characters in the
495'sections' option. The default is "SHNHH HUnhsh", which defines a section to
496start at the nroff macros ".SH", ".NH", ".H", ".HU", ".nh" and ".sh".
497
Bram Moolenaar207f0092020-08-30 17:20:20 +0200498The "]]" and "[[" commands stop at the '{' in the first column. This is
499useful to find the start of a function in a C program. To search for a '}' in
500the first column, the end of a C function, use "][" (forward) or "[]"
501(backward). Note that the first character of the command determines the
502search direction.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000503
504If your '{' or '}' are not in the first column, and you would like to use "[["
505and "]]" anyway, try these mappings: >
506 :map [[ ?{<CR>w99[{
507 :map ][ /}<CR>b99]}
508 :map ]] j0[[%/{<CR>
509 :map [] k$][%?}<CR>
510[type these literally, see |<>|]
511
512==============================================================================
5136. Text object selection *object-select* *text-objects*
514 *v_a* *v_i*
515
516This is a series of commands that can only be used while in Visual mode or
517after an operator. The commands that start with "a" select "a"n object
518including white space, the commands starting with "i" select an "inner" object
519without white space, or just the white space. Thus the "inner" commands
520always select less text than the "a" commands.
521
Bram Moolenaar071d4272004-06-13 20:20:40 +0000522These commands are not available when the |+textobjects| feature has been
523disabled at compile time.
Bram Moolenaar6c35bea2012-07-25 17:49:10 +0200524Also see `gn` and `gN`, operating on the last search pattern.
525
Bram Moolenaar071d4272004-06-13 20:20:40 +0000526 *v_aw* *aw*
527aw "a word", select [count] words (see |word|).
528 Leading or trailing white space is included, but not
529 counted.
530 When used in Visual linewise mode "aw" switches to
531 Visual characterwise mode.
532
533 *v_iw* *iw*
534iw "inner word", select [count] words (see |word|).
535 White space between words is counted too.
536 When used in Visual linewise mode "iw" switches to
537 Visual characterwise mode.
538
539 *v_aW* *aW*
540aW "a WORD", select [count] WORDs (see |WORD|).
541 Leading or trailing white space is included, but not
542 counted.
543 When used in Visual linewise mode "aW" switches to
544 Visual characterwise mode.
545
546 *v_iW* *iW*
547iW "inner WORD", select [count] WORDs (see |WORD|).
548 White space between words is counted too.
549 When used in Visual linewise mode "iW" switches to
550 Visual characterwise mode.
551
552 *v_as* *as*
553as "a sentence", select [count] sentences (see
554 |sentence|).
555 When used in Visual mode it is made characterwise.
556
557 *v_is* *is*
558is "inner sentence", select [count] sentences (see
559 |sentence|).
560 When used in Visual mode it is made characterwise.
561
562 *v_ap* *ap*
563ap "a paragraph", select [count] paragraphs (see
564 |paragraph|).
565 Exception: a blank line (only containing white space)
566 is also a paragraph boundary.
567 When used in Visual mode it is made linewise.
568
569 *v_ip* *ip*
570ip "inner paragraph", select [count] paragraphs (see
571 |paragraph|).
572 Exception: a blank line (only containing white space)
573 is also a paragraph boundary.
574 When used in Visual mode it is made linewise.
575
576a] *v_a]* *v_a[* *a]* *a[*
577a[ "a [] block", select [count] '[' ']' blocks. This
578 goes backwards to the [count] unclosed '[', and finds
579 the matching ']'. The enclosed text is selected,
580 including the '[' and ']'.
581 When used in Visual mode it is made characterwise.
582
583i] *v_i]* *v_i[* *i]* *i[*
584i[ "inner [] block", select [count] '[' ']' blocks. This
585 goes backwards to the [count] unclosed '[', and finds
586 the matching ']'. The enclosed text is selected,
587 excluding the '[' and ']'.
588 When used in Visual mode it is made characterwise.
589
590a) *v_a)* *a)* *a(*
Bram Moolenaar269f5952016-07-15 22:54:41 +0200591a( *vab* *v_ab* *v_a(* *ab*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000592ab "a block", select [count] blocks, from "[count] [(" to
593 the matching ')', including the '(' and ')' (see
594 |[(|). Does not include white space outside of the
595 parenthesis.
596 When used in Visual mode it is made characterwise.
597
598i) *v_i)* *i)* *i(*
Bram Moolenaar269f5952016-07-15 22:54:41 +0200599i( *vib* *v_ib* *v_i(* *ib*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000600ib "inner block", select [count] blocks, from "[count] [("
601 to the matching ')', excluding the '(' and ')' (see
602 |[(|).
603 When used in Visual mode it is made characterwise.
604
605a> *v_a>* *v_a<* *a>* *a<*
606a< "a <> block", select [count] <> blocks, from the
607 [count]'th unmatched '<' backwards to the matching
608 '>', including the '<' and '>'.
609 When used in Visual mode it is made characterwise.
610
611i> *v_i>* *v_i<* *i>* *i<*
612i< "inner <> block", select [count] <> blocks, from
613 the [count]'th unmatched '<' backwards to the matching
614 '>', excluding the '<' and '>'.
615 When used in Visual mode it is made characterwise.
616
Bram Moolenaar6c131c42005-07-19 22:17:30 +0000617 *v_at* *at*
618at "a tag block", select [count] tag blocks, from the
619 [count]'th unmatched "<aaa>" backwards to the matching
620 "</aaa>", including the "<aaa>" and "</aaa>".
621 See |tag-blocks| about the details.
622 When used in Visual mode it is made characterwise.
623
624 *v_it* *it*
625it "inner tag block", select [count] tag blocks, from the
626 [count]'th unmatched "<aaa>" backwards to the matching
627 "</aaa>", excluding the "<aaa>" and "</aaa>".
628 See |tag-blocks| about the details.
629 When used in Visual mode it is made characterwise.
630
Bram Moolenaar071d4272004-06-13 20:20:40 +0000631a} *v_a}* *a}* *a{*
632a{ *v_aB* *v_a{* *aB*
633aB "a Block", select [count] Blocks, from "[count] [{" to
634 the matching '}', including the '{' and '}' (see
635 |[{|).
636 When used in Visual mode it is made characterwise.
637
638i} *v_i}* *i}* *i{*
639i{ *v_iB* *v_i{* *iB*
640iB "inner Block", select [count] Blocks, from "[count] [{"
641 to the matching '}', excluding the '{' and '}' (see
642 |[{|).
643 When used in Visual mode it is made characterwise.
644
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000645a" *v_aquote* *aquote*
646a' *v_a'* *a'*
647a` *v_a`* *a`*
648 "a quoted string". Selects the text from the previous
Bram Moolenaar5a305422006-04-28 22:38:25 +0000649 quote until the next quote. The 'quoteescape' option
650 is used to skip escaped quotes.
651 Only works within one line.
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000652 When the cursor starts on a quote, Vim will figure out
653 which quote pairs form a string by searching from the
654 start of the line.
Bram Moolenaar8f3f58f2010-01-06 20:52:26 +0100655 Any trailing white space is included, unless there is
656 none, then leading white space is included.
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000657 When used in Visual mode it is made characterwise.
658 Repeating this object in Visual mode another string is
659 included. A count is currently not used.
660
661i" *v_iquote* *iquote*
662i' *v_i'* *i'*
663i` *v_i`* *i`*
664 Like a", a' and a`, but exclude the quotes and
665 repeating won't extend the Visual selection.
Bram Moolenaarab194812005-09-14 21:40:12 +0000666 Special case: With a count of 2 the quotes are
667 included, but no extra white space as with a"/a'/a`.
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000668
Bram Moolenaar071d4272004-06-13 20:20:40 +0000669When used after an operator:
670For non-block objects:
671 For the "a" commands: The operator applies to the object and the white
672 space after the object. If there is no white space after the object
673 or when the cursor was in the white space before the object, the white
674 space before the object is included.
675 For the "inner" commands: If the cursor was on the object, the
676 operator applies to the object. If the cursor was on white space, the
677 operator applies to the white space.
678For a block object:
679 The operator applies to the block where the cursor is in, or the block
680 on which the cursor is on one of the braces. For the "inner" commands
681 the surrounding braces are excluded. For the "a" commands, the braces
682 are included.
683
684When used in Visual mode:
685When start and end of the Visual area are the same (just after typing "v"):
686 One object is selected, the same as for using an operator.
687When start and end of the Visual area are not the same:
688 For non-block objects the area is extended by one object or the white
689 space up to the next object, or both for the "a" objects. The
690 direction in which this happens depends on which side of the Visual
691 area the cursor is. For the block objects the block is extended one
692 level outwards.
693
694For illustration, here is a list of delete commands, grouped from small to big
695objects. Note that for a single character and a whole line the existing vi
696movement commands are used.
697 "dl" delete character (alias: "x") |dl|
698 "diw" delete inner word *diw*
699 "daw" delete a word *daw*
700 "diW" delete inner WORD (see |WORD|) *diW*
701 "daW" delete a WORD (see |WORD|) *daW*
Bram Moolenaar6c35bea2012-07-25 17:49:10 +0200702 "dgn" delete the next search pattern match *dgn*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000703 "dd" delete one line |dd|
704 "dis" delete inner sentence *dis*
705 "das" delete a sentence *das*
706 "dib" delete inner '(' ')' block *dib*
707 "dab" delete a '(' ')' block *dab*
708 "dip" delete inner paragraph *dip*
709 "dap" delete a paragraph *dap*
710 "diB" delete inner '{' '}' block *diB*
711 "daB" delete a '{' '}' block *daB*
712
713Note the difference between using a movement command and an object. The
714movement command operates from here (cursor position) to where the movement
715takes us. When using an object the whole object is operated upon, no matter
716where on the object the cursor is. For example, compare "dw" and "daw": "dw"
717deletes from the cursor position to the start of the next word, "daw" deletes
718the word under the cursor and the space after or before it.
719
Bram Moolenaar6c131c42005-07-19 22:17:30 +0000720
721Tag blocks *tag-blocks*
722
723For the "it" and "at" text objects an attempt is done to select blocks between
724matching tags for HTML and XML. But since these are not completely compatible
725there are a few restrictions.
726
727The normal method is to select a <tag> until the matching </tag>. For "at"
728the tags are included, for "it" they are excluded. But when "it" is repeated
Bram Moolenaar06a89a52006-04-29 22:01:03 +0000729the tags will be included (otherwise nothing would change). Also, "it" used
730on a tag block with no contents will select the leading tag.
Bram Moolenaar6c131c42005-07-19 22:17:30 +0000731
732"<aaa/>" items are skipped. Case is ignored, also for XML where case does
733matter.
734
735In HTML it is possible to have a tag like <br> or <meta ...> without a
736matching end tag. These are ignored.
737
738The text objects are tolerant about mistakes. Stray end tags are ignored.
739
Bram Moolenaar071d4272004-06-13 20:20:40 +0000740==============================================================================
7417. Marks *mark-motions* *E20* *E78*
742
743Jumping to a mark can be done in two ways:
7441. With ` (backtick): The cursor is positioned at the specified location
745 and the motion is |exclusive|.
7462. With ' (single quote): The cursor is positioned on the first non-blank
747 character in the line of the specified location and
748 the motion is linewise.
749
750 *m* *mark* *Mark*
751m{a-zA-Z} Set mark {a-zA-Z} at cursor position (does not move
752 the cursor, this is not a motion command).
753
754 *m'* *m`*
755m' or m` Set the previous context mark. This can be jumped to
756 with the "''" or "``" command (does not move the
757 cursor, this is not a motion command).
758
759 *m[* *m]*
760m[ or m] Set the |'[| or |']| mark. Useful when an operator is
761 to be simulated by multiple commands. (does not move
762 the cursor, this is not a motion command).
763
Bram Moolenaar30b65812012-07-12 22:01:11 +0200764 *m<* *m>*
765m< or m> Set the |'<| or |'>| mark. Useful to change what the
766 `gv` command selects. (does not move the cursor, this
767 is not a motion command).
768 Note that the Visual mode cannot be set, only the
769 start and end position.
770
Bram Moolenaar071d4272004-06-13 20:20:40 +0000771 *:ma* *:mark* *E191*
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000772:[range]ma[rk] {a-zA-Z'}
773 Set mark {a-zA-Z'} at last line number in [range],
Bram Moolenaar071d4272004-06-13 20:20:40 +0000774 column 0. Default is cursor line.
775
776 *:k*
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000777:[range]k{a-zA-Z'} Same as :mark, but the space before the mark name can
Bram Moolenaar071d4272004-06-13 20:20:40 +0000778 be omitted.
779
780 *'* *'a* *`* *`a*
Bram Moolenaar9964e462007-05-05 17:54:07 +0000781'{a-z} `{a-z} Jump to the mark {a-z} in the current buffer.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000782
783 *'A* *'0* *`A* *`0*
Bram Moolenaar9964e462007-05-05 17:54:07 +0000784'{A-Z0-9} `{A-Z0-9} To the mark {A-Z0-9} in the file where it was set (not
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200785 a motion command when in another file).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000786
787 *g'* *g'a* *g`* *g`a*
788g'{mark} g`{mark}
789 Jump to the {mark}, but don't change the jumplist when
790 jumping within the current buffer. Example: >
791 g`"
792< jumps to the last known position in a file. See
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000793 $VIMRUNTIME/vimrc_example.vim.
794 Also see |:keepjumps|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000795
796 *:marks*
797:marks List all the current marks (not a motion command).
798 The |'(|, |')|, |'{| and |'}| marks are not listed.
Bram Moolenaar551dbcc2006-04-25 22:13:59 +0000799 The first column has number zero.
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200800
Bram Moolenaar071d4272004-06-13 20:20:40 +0000801 *E283*
802:marks {arg} List the marks that are mentioned in {arg} (not a
803 motion command). For example: >
804 :marks aB
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200805< to list marks 'a' and 'B'.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000806
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000807 *:delm* *:delmarks*
Bram Moolenaarc9b4b052006-04-30 18:54:39 +0000808:delm[arks] {marks} Delete the specified marks. Marks that can be deleted
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000809 include A-Z and 0-9. You cannot delete the ' mark.
810 They can be specified by giving the list of mark
811 names, or with a range, separated with a dash. Spaces
812 are ignored. Examples: >
813 :delmarks a deletes mark a
814 :delmarks a b 1 deletes marks a, b and 1
815 :delmarks Aa deletes marks A and a
816 :delmarks p-z deletes marks in the range p to z
817 :delmarks ^.[] deletes marks ^ . [ ]
818 :delmarks \" deletes mark "
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000819
820:delm[arks]! Delete all marks for the current buffer, but not marks
821 A-Z or 0-9.
Bram Moolenaarc0197e22004-09-13 20:26:32 +0000822
Bram Moolenaar071d4272004-06-13 20:20:40 +0000823A mark is not visible in any way. It is just a position in the file that is
824remembered. Do not confuse marks with named registers, they are totally
825unrelated.
826
827'a - 'z lowercase marks, valid within one file
828'A - 'Z uppercase marks, also called file marks, valid between files
829'0 - '9 numbered marks, set from .viminfo file
830
831Lowercase marks 'a to 'z are remembered as long as the file remains in the
832buffer list. If you remove the file from the buffer list, all its marks are
833lost. If you delete a line that contains a mark, that mark is erased.
834
Bram Moolenaar071d4272004-06-13 20:20:40 +0000835Lowercase marks can be used in combination with operators. For example: "d't"
836deletes the lines from the cursor position to mark 't'. Hint: Use mark 't' for
837Top, 'b' for Bottom, etc.. Lowercase marks are restored when using undo and
838redo.
839
Bram Moolenaara6c27c42019-05-09 19:16:22 +0200840Uppercase marks 'A to 'Z include the file name. You can use them to jump from
841file to file. You can only use an uppercase mark with an operator if the mark
842is in the current file. The line number of the mark remains correct, even if
843you insert/delete lines or edit another file for a moment. When the 'viminfo'
844option is not empty, uppercase marks are kept in the .viminfo file. See
845|viminfo-file-marks|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000846
847Numbered marks '0 to '9 are quite different. They can not be set directly.
848They are only present when using a viminfo file |viminfo-file|. Basically '0
849is the location of the cursor when you last exited Vim, '1 the last but one
850time, etc. Use the "r" flag in 'viminfo' to specify files for which no
851Numbered mark should be stored. See |viminfo-file-marks|.
852
853
854 *'[* *`[*
855'[ `[ To the first character of the previously changed
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200856 or yanked text.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000857
858 *']* *`]*
859'] `] To the last character of the previously changed or
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200860 yanked text.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000861
862After executing an operator the Cursor is put at the beginning of the text
863that was operated upon. After a put command ("p" or "P") the cursor is
864sometimes placed at the first inserted line and sometimes on the last inserted
865character. The four commands above put the cursor at either end. Example:
866After yanking 10 lines you want to go to the last one of them: "10Y']". After
867inserting several lines with the "p" command you want to jump to the lowest
868inserted line: "p']". This also works for text that has been inserted.
869
870Note: After deleting text, the start and end positions are the same, except
871when using blockwise Visual mode. These commands do not work when no change
872was made yet in the current file.
873
874 *'<* *`<*
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000875'< `< To the first line or character of the last selected
876 Visual area in the current buffer. For block mode it
877 may also be the last character in the first line (to
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200878 be able to define the block).
Bram Moolenaar071d4272004-06-13 20:20:40 +0000879
880 *'>* *`>*
Bram Moolenaare37d50a2008-08-06 17:06:04 +0000881'> `> To the last line or character of the last selected
882 Visual area in the current buffer. For block mode it
883 may also be the first character of the last line (to
884 be able to define the block). Note that 'selection'
Bram Moolenaarc9b4b052006-04-30 18:54:39 +0000885 applies, the position may be just after the Visual
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200886 area.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000887
888 *''* *``*
Bram Moolenaar293ee4d2004-12-09 21:34:53 +0000889'' `` To the position before the latest jump, or where the
890 last "m'" or "m`" command was given. Not set when the
Bram Moolenaar071d4272004-06-13 20:20:40 +0000891 |:keepjumps| command modifier was used.
892 Also see |restore-position|.
893
894 *'quote* *`quote*
895'" `" To the cursor position when last exiting the current
896 buffer. Defaults to the first character of the first
897 line. See |last-position-jump| for how to use this
898 for each opened file.
899 Only one position is remembered per buffer, not one
900 for each window. As long as the buffer is visible in
901 a window the position won't be changed.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000902
903 *'^* *`^*
904'^ `^ To the position where the cursor was the last time
Bram Moolenaar81695252004-12-29 20:58:21 +0000905 when Insert mode was stopped. This is used by the
906 |gi| command. Not set when the |:keepjumps| command
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200907 modifier was used.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000908
909 *'.* *`.*
910'. `. To the position where the last change was made. The
911 position is at or near where the change started.
912 Sometimes a command is executed as several changes,
913 then the position can be near the end of what the
914 command changed. For example when inserting a word,
915 the position will be on the last character.
Bram Moolenaar51628222016-12-01 23:03:28 +0100916 To jump to older changes use |g;|.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000917
918 *'(* *`(*
919'( `( To the start of the current sentence, like the |(|
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200920 command.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000921
922 *')* *`)*
923') `) To the end of the current sentence, like the |)|
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200924 command.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000925
926 *'{* *`{*
927'{ `{ To the start of the current paragraph, like the |{|
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200928 command.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000929
930 *'}* *`}*
931'} `} To the end of the current paragraph, like the |}|
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200932 command.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000933
934These commands are not marks themselves, but jump to a mark:
935
936 *]'*
937]' [count] times to next line with a lowercase mark below
938 the cursor, on the first non-blank character in the
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200939 line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000940
941 *]`*
942]` [count] times to lowercase mark after the cursor. {not
943 in Vi}
944
945 *['*
946[' [count] times to previous line with a lowercase mark
947 before the cursor, on the first non-blank character in
Bram Moolenaar25c9c682019-05-05 18:13:34 +0200948 the line.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000949
950 *[`*
951[` [count] times to lowercase mark before the cursor.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000952
953
Bram Moolenaar61da1bf2019-06-06 12:14:49 +0200954:loc[kmarks] {command} *:loc* *:lock* *:lockmarks*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000955 Execute {command} without adjusting marks. This is
956 useful when changing text in a way that the line count
957 will be the same when the change has completed.
958 WARNING: When the line count does change, marks below
959 the change will keep their line number, thus move to
960 another text line.
961 These items will not be adjusted for deleted/inserted
962 lines:
963 - lower case letter marks 'a - 'z
964 - upper case letter marks 'A - 'Z
965 - numbered marks '0 - '9
966 - last insert position '^
967 - last change position '.
Bram Moolenaar09c6f262019-11-17 15:55:14 +0100968 - last affected text area '[ and ']
Bram Moolenaar071d4272004-06-13 20:20:40 +0000969 - the Visual area '< and '>
970 - line numbers in placed signs
971 - line numbers in quickfix positions
972 - positions in the |jumplist|
973 - positions in the |tagstack|
974 These items will still be adjusted:
975 - previous context mark ''
976 - the cursor position
977 - the view of a window on a buffer
978 - folds
979 - diffs
980
Bram Moolenaar61da1bf2019-06-06 12:14:49 +0200981:kee[pmarks] {command} *:kee* *:keep* *:keepmarks*
Bram Moolenaar071d4272004-06-13 20:20:40 +0000982 Currently only has effect for the filter command
983 |:range!|:
984 - When the number of lines after filtering is equal to
985 or larger than before, all marks are kept at the
986 same line number.
987 - When the number of lines decreases, the marks in the
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000988 lines that disappeared are deleted.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000989 In any case the marks below the filtered text have
990 their line numbers adjusted, thus stick to the text,
991 as usual.
992 When the 'R' flag is missing from 'cpoptions' this has
993 the same effect as using ":keepmarks".
994
995 *:keepj* *:keepjumps*
996:keepj[umps] {command}
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000997 Moving around in {command} does not change the |''|,
998 |'.| and |'^| marks, the |jumplist| or the
999 |changelist|.
1000 Useful when making a change or inserting text
1001 automatically and the user doesn't want to go to this
1002 position. E.g., when updating a "Last change"
1003 timestamp in the first line: >
1004
Bram Moolenaare5180522005-12-10 20:19:46 +00001005 :let lnum = line(".")
Bram Moolenaar69a7cb42004-06-20 12:51:53 +00001006 :keepjumps normal gg
1007 :call SetLastChange()
1008 :keepjumps exe "normal " . lnum . "G"
1009<
1010 Note that ":keepjumps" must be used for every command.
1011 When invoking a function the commands in that function
Bram Moolenaarc9b4b052006-04-30 18:54:39 +00001012 can still change the jumplist. Also, for
Bram Moolenaar13065c42005-01-08 16:08:21 +00001013 ":keepjumps exe 'command '" the "command" won't keep
1014 jumps. Instead use: ":exe 'keepjumps command'"
Bram Moolenaar071d4272004-06-13 20:20:40 +00001015
1016==============================================================================
10178. Jumps *jump-motions*
1018
Bram Moolenaarb477af22018-07-15 20:20:18 +02001019A "jump" is a command that normally moves the cursor several lines away. If
1020you make the cursor "jump" the position of the cursor before the jump is
Bram Moolenaar26967612019-03-17 17:13:16 +01001021remembered. You can return to that position with the "''" and "``" commands,
Bram Moolenaarb477af22018-07-15 20:20:18 +02001022unless the line containing that position was changed or deleted. The
1023following commands are "jump" commands: "'", "`", "G", "/", "?", "n", "N",
1024"%", "(", ")", "[[", "]]", "{", "}", ":s", ":tag", "L", "M", "H" and the
Bram Moolenaarf0d58ef2018-11-16 16:13:44 +01001025commands that start editing a new file.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001026
1027 *CTRL-O*
1028CTRL-O Go to [count] Older cursor position in jump list
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001029 (not a motion command).
Bram Moolenaardb84e452010-08-15 13:50:43 +02001030 {not available without the |+jumplist| feature}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001031
1032<Tab> or *CTRL-I* *<Tab>*
1033CTRL-I Go to [count] newer cursor position in jump list
1034 (not a motion command).
Bram Moolenaardb84e452010-08-15 13:50:43 +02001035 {not available without the |+jumplist| feature}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001036
1037 *:ju* *:jumps*
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001038:ju[mps] Print the jump list (not a motion command).
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001039 {not available without the |+jumplist| feature}
1040
1041 *:cle* *:clearjumps*
1042:cle[arjumps] Clear the jump list of the current window.
Bram Moolenaarc95a3022016-06-12 23:01:46 +02001043 {not available without the |+jumplist| feature}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001044
1045 *jumplist*
1046Jumps are remembered in a jump list. With the CTRL-O and CTRL-I command you
1047can go to cursor positions before older jumps, and back again. Thus you can
1048move up and down the list. There is a separate jump list for each window.
1049The maximum number of entries is fixed at 100.
Bram Moolenaardb84e452010-08-15 13:50:43 +02001050{not available without the |+jumplist| feature}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001051
1052For example, after three jump commands you have this jump list:
1053
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +01001054 jump line col file/text ~
Bram Moolenaar071d4272004-06-13 20:20:40 +00001055 3 1 0 some text ~
1056 2 70 0 another line ~
1057 1 1154 23 end. ~
1058 > ~
1059
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +01001060The "file/text" column shows the file name, or the text at the jump if it is
Bram Moolenaar071d4272004-06-13 20:20:40 +00001061in the current file (an indent is removed and a long line is truncated to fit
1062in the window).
1063
1064You are currently in line 1167. If you then use the CTRL-O command, the
1065cursor is put in line 1154. This results in:
1066
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +01001067 jump line col file/text ~
Bram Moolenaar071d4272004-06-13 20:20:40 +00001068 2 1 0 some text ~
1069 1 70 0 another line ~
1070 > 0 1154 23 end. ~
1071 1 1167 0 foo bar ~
1072
1073The pointer will be set at the last used jump position. The next CTRL-O
1074command will use the entry above it, the next CTRL-I command will use the
1075entry below it. If the pointer is below the last entry, this indicates that
1076you did not use a CTRL-I or CTRL-O before. In this case the CTRL-O command
1077will cause the cursor position to be added to the jump list, so you can get
1078back to the position before the CTRL-O. In this case this is line 1167.
1079
1080With more CTRL-O commands you will go to lines 70 and 1. If you use CTRL-I
1081you can go back to 1154 and 1167 again. Note that the number in the "jump"
1082column indicates the count for the CTRL-O or CTRL-I command that takes you to
1083this position.
1084
1085If you use a jump command, the current line number is inserted at the end of
1086the jump list. If the same line was already in the jump list, it is removed.
1087The result is that when repeating CTRL-O you will get back to old positions
1088only once.
1089
1090When the |:keepjumps| command modifier is used, jumps are not stored in the
Bram Moolenaarc1e37902006-04-18 21:55:01 +00001091jumplist. Jumps are also not stored in other cases, e.g., in a |:global|
Bram Moolenaar9ba7e172013-07-17 22:37:26 +02001092command. You can explicitly add a jump by setting the ' mark with "m'". Note
1093that calling setpos() does not do this.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001094
1095After the CTRL-O command that got you into line 1154 you could give another
1096jump command (e.g., "G"). The jump list would then become:
1097
Bram Moolenaar2a8a3ec2011-01-08 16:06:37 +01001098 jump line col file/text ~
Bram Moolenaar071d4272004-06-13 20:20:40 +00001099 4 1 0 some text ~
1100 3 70 0 another line ~
1101 2 1167 0 foo bar ~
1102 1 1154 23 end. ~
1103 > ~
1104
1105The line numbers will be adjusted for deleted and inserted lines. This fails
1106if you stop editing a file without writing, like with ":n!".
1107
1108When you split a window, the jumplist will be copied to the new window.
1109
1110If you have included the ' item in the 'viminfo' option the jumplist will be
1111stored in the viminfo file and restored when starting Vim.
1112
1113
1114CHANGE LIST JUMPS *changelist* *change-list-jumps* *E664*
1115
1116When making a change the cursor position is remembered. One position is
1117remembered for every change that can be undone, unless it is close to a
1118previous change. Two commands can be used to jump to positions of changes,
1119also those that have been undone:
1120
1121 *g;* *E662*
1122g; Go to [count] older position in change list.
1123 If [count] is larger than the number of older change
1124 positions go to the oldest change.
1125 If there is no older change an error message is given.
1126 (not a motion command)
Bram Moolenaardb84e452010-08-15 13:50:43 +02001127 {not available without the |+jumplist| feature}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001128
1129 *g,* *E663*
1130g, Go to [count] newer cursor position in change list.
Bram Moolenaar402d2fe2005-04-15 21:00:38 +00001131 Just like |g;| but in the opposite direction.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001132 (not a motion command)
Bram Moolenaardb84e452010-08-15 13:50:43 +02001133 {not available without the |+jumplist| feature}
Bram Moolenaar071d4272004-06-13 20:20:40 +00001134
1135When using a count you jump as far back or forward as possible. Thus you can
1136use "999g;" to go to the first change for which the position is still
1137remembered. The number of entries in the change list is fixed and is the same
1138as for the |jumplist|.
1139
1140When two undo-able changes are in the same line and at a column position less
1141than 'textwidth' apart only the last one is remembered. This avoids that a
1142sequence of small changes in a line, for example "xxxxx", adds many positions
1143to the change list. When 'textwidth' is zero 'wrapmargin' is used. When that
1144also isn't set a fixed number of 79 is used. Detail: For the computations
1145bytes are used, not characters, to avoid a speed penalty (this only matters
Bram Moolenaar207f0092020-08-30 17:20:20 +02001146for multibyte encodings).
Bram Moolenaar071d4272004-06-13 20:20:40 +00001147
1148Note that when text has been inserted or deleted the cursor position might be
1149a bit different from the position of the change. Especially when lines have
1150been deleted.
1151
1152When the |:keepjumps| command modifier is used the position of a change is not
1153remembered.
1154
1155 *:changes*
1156:changes Print the change list. A ">" character indicates the
1157 current position. Just after a change it is below the
Bram Moolenaara9604e62018-07-21 05:56:22 +02001158 newest entry, indicating that `g;` takes you to the
Bram Moolenaar071d4272004-06-13 20:20:40 +00001159 newest entry position. The first column indicates the
1160 count needed to take you to this position. Example:
1161
1162 change line col text ~
1163 3 9 8 bla bla bla
1164 2 11 57 foo is a bar
1165 1 14 54 the latest changed line
1166 >
1167
Bram Moolenaara9604e62018-07-21 05:56:22 +02001168 The `3g;` command takes you to line 9. Then the
1169 output of `:changes` is:
Bram Moolenaar071d4272004-06-13 20:20:40 +00001170
1171 change line col text ~
1172 > 0 9 8 bla bla bla
1173 1 11 57 foo is a bar
1174 2 14 54 the latest changed line
1175
1176 Now you can use "g," to go to line 11 and "2g," to go
1177 to line 14.
1178
1179==============================================================================
11809. Various motions *various-motions*
1181
1182 *%*
1183% Find the next item in this line after or under the
1184 cursor and jump to its match. |inclusive| motion.
1185 Items can be:
1186 ([{}]) parenthesis or (curly/square) brackets
1187 (this can be changed with the
1188 'matchpairs' option)
1189 /* */ start or end of C-style comment
1190 #if, #ifdef, #else, #elif, #endif
1191 C preprocessor conditionals (when the
1192 cursor is on the # or no ([{
1193 following)
1194 For other items the matchit plugin can be used, see
Bram Moolenaar446cb832008-06-24 21:56:24 +00001195 |matchit-install|. This plugin also helps to skip
1196 matches in comments.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001197
1198 When 'cpoptions' contains "M" |cpo-M| backslashes
1199 before parens and braces are ignored. Without "M" the
1200 number of backslashes matters: an even number doesn't
1201 match with an odd number. Thus in "( \) )" and "\( (
1202 \)" the first and last parenthesis match.
Bram Moolenaar446cb832008-06-24 21:56:24 +00001203
Bram Moolenaar071d4272004-06-13 20:20:40 +00001204 When the '%' character is not present in 'cpoptions'
1205 |cpo-%|, parens and braces inside double quotes are
1206 ignored, unless the number of parens/braces in a line
1207 is uneven and this line and the previous one does not
1208 end in a backslash. '(', '{', '[', ']', '}' and ')'
1209 are also ignored (parens and braces inside single
1210 quotes). Note that this works fine for C, but not for
1211 Perl, where single quotes are used for strings.
Bram Moolenaar446cb832008-06-24 21:56:24 +00001212
1213 Nothing special is done for matches in comments. You
1214 can either use the matchit plugin |matchit-install| or
1215 put quotes around matches.
1216
1217 No count is allowed, {count}% jumps to a line {count}
1218 percentage down the file |N%|. Using '%' on
Bram Moolenaar071d4272004-06-13 20:20:40 +00001219 #if/#else/#endif makes the movement linewise.
1220
1221 *[(*
1222[( go to [count] previous unmatched '('.
Bram Moolenaar25c9c682019-05-05 18:13:34 +02001223 |exclusive| motion.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001224
1225 *[{*
1226[{ go to [count] previous unmatched '{'.
Bram Moolenaar25c9c682019-05-05 18:13:34 +02001227 |exclusive| motion.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001228
1229 *])*
1230]) go to [count] next unmatched ')'.
Bram Moolenaar25c9c682019-05-05 18:13:34 +02001231 |exclusive| motion.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001232
1233 *]}*
1234]} go to [count] next unmatched '}'.
Bram Moolenaar25c9c682019-05-05 18:13:34 +02001235 |exclusive| motion.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001236
1237The above four commands can be used to go to the start or end of the current
1238code block. It is like doing "%" on the '(', ')', '{' or '}' at the other
1239end of the code block, but you can do this from anywhere in the code block.
1240Very useful for C programs. Example: When standing on "case x:", "[{" will
1241bring you back to the switch statement.
1242
1243 *]m*
1244]m Go to [count] next start of a method (for Java or
1245 similar structured language). When not before the
1246 start of a method, jump to the start or end of the
1247 class. When no '{' is found after the cursor, this is
Bram Moolenaar25c9c682019-05-05 18:13:34 +02001248 an error. |exclusive| motion.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001249 *]M*
1250]M Go to [count] next end of a method (for Java or
1251 similar structured language). When not before the end
1252 of a method, jump to the start or end of the class.
1253 When no '}' is found after the cursor, this is an
Bram Moolenaar25c9c682019-05-05 18:13:34 +02001254 error. |exclusive| motion.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001255 *[m*
1256[m Go to [count] previous start of a method (for Java or
1257 similar structured language). When not after the
1258 start of a method, jump to the start or end of the
1259 class. When no '{' is found before the cursor this is
Bram Moolenaar25c9c682019-05-05 18:13:34 +02001260 an error. |exclusive| motion.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001261 *[M*
1262[M Go to [count] previous end of a method (for Java or
1263 similar structured language). When not after the
1264 end of a method, jump to the start or end of the
1265 class. When no '}' is found before the cursor this is
Bram Moolenaar25c9c682019-05-05 18:13:34 +02001266 an error. |exclusive| motion.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001267
1268The above two commands assume that the file contains a class with methods.
1269The class definition is surrounded in '{' and '}'. Each method in the class
1270is also surrounded with '{' and '}'. This applies to the Java language. The
1271file looks like this: >
1272
1273 // comment
1274 class foo {
1275 int method_one() {
1276 body_one();
1277 }
1278 int method_two() {
1279 body_two();
1280 }
1281 }
1282Starting with the cursor on "body_two()", using "[m" will jump to the '{' at
1283the start of "method_two()" (obviously this is much more useful when the
1284method is long!). Using "2[m" will jump to the start of "method_one()".
1285Using "3[m" will jump to the start of the class.
1286
1287 *[#*
1288[# go to [count] previous unmatched "#if" or "#else".
Bram Moolenaar25c9c682019-05-05 18:13:34 +02001289 |exclusive| motion.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001290
1291 *]#*
1292]# go to [count] next unmatched "#else" or "#endif".
Bram Moolenaar25c9c682019-05-05 18:13:34 +02001293 |exclusive| motion.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001294
1295These two commands work in C programs that contain #if/#else/#endif
1296constructs. It brings you to the start or end of the #if/#else/#endif where
1297the current line is included. You can then use "%" to go to the matching line.
1298
1299 *[star* *[/*
1300[* or [/ go to [count] previous start of a C comment "/*".
Bram Moolenaar25c9c682019-05-05 18:13:34 +02001301 |exclusive| motion.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001302
1303 *]star* *]/*
1304]* or ]/ go to [count] next end of a C comment "*/".
Bram Moolenaar25c9c682019-05-05 18:13:34 +02001305 |exclusive| motion.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001306
1307
1308 *H*
1309H To line [count] from top (Home) of window (default:
1310 first line on the window) on the first non-blank
1311 character |linewise|. See also 'startofline' option.
Bram Moolenaar44cc4cf2017-10-15 22:13:37 +02001312 Cursor is adjusted for 'scrolloff' option, unless an
1313 operator is pending, in which case the text may
1314 scroll. E.g. "yH" yanks from the first visible line
1315 until the cursor line (inclusive).
Bram Moolenaar071d4272004-06-13 20:20:40 +00001316
1317 *M*
1318M To Middle line of window, on the first non-blank
1319 character |linewise|. See also 'startofline' option.
1320
1321 *L*
1322L To line [count] from bottom of window (default: Last
1323 line on the window) on the first non-blank character
1324 |linewise|. See also 'startofline' option.
Bram Moolenaar44cc4cf2017-10-15 22:13:37 +02001325 Cursor is adjusted for 'scrolloff' option, unless an
1326 operator is pending, in which case the text may
1327 scroll. E.g. "yL" yanks from the cursor to the last
1328 visible line.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001329
1330<LeftMouse> Moves to the position on the screen where the mouse
Bram Moolenaar293ee4d2004-12-09 21:34:53 +00001331 click is |exclusive|. See also |<LeftMouse>|. If the
Bram Moolenaar071d4272004-06-13 20:20:40 +00001332 position is in a status line, that window is made the
Bram Moolenaar25c9c682019-05-05 18:13:34 +02001333 active window and the cursor is not moved.
Bram Moolenaar071d4272004-06-13 20:20:40 +00001334
Bram Moolenaar91f84f62018-07-29 15:07:52 +02001335 vim:tw=78:ts=8:noet:ft=help:norl: