blob: a3e73b394663900b1e4c824c3502edc7f272257f [file] [log] [blame]
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +00001*motion.txt* For Vim version 7.0aa. Last change: 2004 Jul 02
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
56 |g?| g? ROT13 encoding
57 |>| > shift right
58 |<| < shift left
59 |zf| zf define a fold
60
61If the motion includes a count and the operator also had a count before it,
62the two counts are multiplied. For example: "2d3w" deletes six words.
63
64After applying the operator the cursor is mostly left at the start of the text
65that was operated upon. For example, "yfe" doesn't move the cursor, but "yFe"
66moves the cursor leftwards to the "e" where the yank started.
67
68 *linewise* *characterwise*
69The operator either affects whole lines, or the characters between the start
70and end position. Generally, motions that move between lines affect lines
71(are linewise), and motions that move within a line affect characters (are
72characterwise). However, there are some exceptions.
73
74 *exclusive* *inclusive*
75A character motion is either inclusive or exclusive. When inclusive, the start
76and end position of the motion are included in the operation. When exclusive,
77the last character towards the end of the buffer is not included. Linewise
78motions always include the start and end position.
79
80Which motions are linewise, inclusive or exclusive is mentioned below. There
81are however, two general exceptions:
821. If the motion is exclusive and the end of the motion is in column 1, the
83 end of the motion is moved to the end of the previous line and the motion
84 becomes inclusive. Example: "}" moves to the first line after a paragraph,
85 but "d}" will not include that line.
862. If the motion is exclusive, the end of the motion is in column 1 and the
87 start of the motion was at or before the first non-blank in the line, the
88 motion becomes linewise. Example: If a paragraph begins with some blanks
89 and you do "d}" while standing on the first non-blank, all the lines of
90 the paragraph are deleted, including the blanks. If you do a put now, the
91 deleted lines will be inserted below the cursor position.
92
93Note that when the operator is pending (the operator command is typed, but the
94motion isn't yet), a special set of mappings can be used. See |:omap|.
95
96Instead of first giving the operator and then a motion you can use Visual
97mode: mark the start of the text with "v", move the cursor to the end of the
98text that is to be affected and then hit the operator. The text between the
99start and the cursor position is highlighted, so you can see what text will
100be operated upon. This allows much more freedom, but requires more key
101strokes and has limited redo functionality. See the chapter on Visual mode
102|Visual-mode|.
103
104You can use a ":" command for a motion. For example "d:call FindEnd()".
105But this can't be redone with "." if the command is more than one line.
106This can be repeated: >
107 d:call search("f")<CR>
108This cannot be repeated: >
109 d:if 1<CR>
110 call search("f")<CR>
111 endif<CR>
112
113
114FORCING A MOTION TO BE LINEWISE, CHARACTERWISE OR BLOCKWISE
115
116When a motion is not of the type you would like to use, you can force another
117type by using "v", "V" or CTRL-V just after the operator.
118Example: >
119 dj
120deletes two lines >
121 dvj
122deletes from the cursor position until the character below the cursor >
123 d<C-V>j
124deletes the character under the cursor and the character below the cursor. >
125
126Be careful with forcing a linewise movement to be used characterwise or
127blockwise, the column may not always be defined.
128
129 *o_v*
130v When used after an operator, before the motion command: Force
131 the operator to work characterwise, also when the motion is
132 linewise. If the motion was linewise, it will become
133 |exclusive|.
134 If the motion already was characterwise, toggle
135 inclusive/exclusive. This can be used to make an exclusive
136 motion inclusive and an inclusive motion exclusive.
137
138 *o_V*
139V When used after an operator, before the motion command: Force
140 the operator to work linewise, also when the motion is
141 characterwise.
142
143 *o_CTRL-V*
144CTRL-V When used after an operator, before the motion command: Force
145 the operator to work blockwise. This works like Visual block
146 mode selection, with the corners defined by the cursor
147 position before and after the motion.
148
149==============================================================================
1502. Left-right motions *left-right-motions*
151
152h or *h*
153<Left> or *<Left>*
154CTRL-H or *CTRL-H* *<BS>*
155<BS> [count] characters to the left. |exclusive| motion.
156 Note: If you prefer <BS> to delete a character, use
157 the mapping:
158 :map CTRL-V<BS> X
159 (to enter "CTRL-V<BS>" type the CTRL-V key, followed
160 by the <BS> key)
161 See |:fixdel| if the <BS> key does not do what you
162 want.
163
164l or *l*
165<Right> or *<Right>* *<Space>*
166<Space> [count] characters to the right. |exclusive| motion.
167
168 *0*
1690 To the first character of the line. |exclusive|
170 motion. When moving up or down, stay in same screen
171 column (if possible).
172
173 *<Home>* *<kHome>*
174<Home> To the first character of the line. |exclusive|
175 motion. When moving up or down, stay in same text
176 column (if possible). Works like "1|", which differs
177 from "0" when the line starts with a <Tab>. {not in
178 Vi}
179
180 *^*
181^ To the first non-blank character of the line.
182 |exclusive| motion.
183
184 *$* *<End>* *<kEnd>*
185$ or <End> To the end of the line. When a count is given also go
186 [count - 1] lines downward |inclusive|.
187 In Visual mode the cursor goes to just after the last
188 character in the line.
189 When 'virtualedit' is active, "$" may move the cursor
190 back from past the end of the line to the last
191 character in the line.
192
193 *g_*
194g_ To the last non-blank character of the line and
195 [count - 1] lines downward |inclusive|. {not in Vi}
196
197 *g0* *g<Home>*
198g0 or g<Home> When lines wrap ('wrap' on): To the first character of
199 the screen line. |exclusive| motion. Differs from
200 "0" when a line is wider than the screen.
201 When lines don't wrap ('wrap' off): To the leftmost
202 character of the current line that is on the screen.
203 Differs from "0" when the first character of the line
204 is not on the screen. {not in Vi}
205
206 *g^*
207g^ When lines wrap ('wrap' on): To the first non-blank
208 character of the screen line. |exclusive| motion.
209 Differs from "^" when a line is wider than the screen.
210 When lines don't wrap ('wrap' off): To the leftmost
211 non-blank character of the current line that is on the
212 screen. Differs from "^" when the first non-blank
213 character of the line is not on the screen. {not in
214 Vi}
215
216 *gm*
217gm Like "g0", but half a screenwidth to the right (or as
218 much as possible). {not in Vi}
219
220 *g$* *g<End>*
221g$ or g<End> When lines wrap ('wrap' on): To the last character of
222 the screen line and [count - 1] screen lines downward
223 |inclusive|. Differs from "$" when a line is wider
224 than the screen.
225 When lines don't wrap ('wrap' off): To the rightmost
226 character of the current line that is visible on the
227 screen. Differs from "$" when the last character of
228 the line is not on the screen or when a count is used.
229 Additionally, vertical movements keep the column,
230 instead of going to the end of the line.
231 {not in Vi}
232
233 *bar*
234| To screen column [count] in the current line.
235 |exclusive| motion.
236
237 *f*
238f{char} To [count]'th occurrence of {char} to the right. The
239 cursor is placed on {char} |inclusive|.
240 {char} can be entered as a digraph |digraph-arg|.
241 When 'encoding' is set to Unicode, composing
242 characters may be used, see |utf-8-char-arg|.
243 |:lmap| mappings apply to {char}. The CTRL-^ command
244 in Insert mode can be used to switch this on/off
245 |i_CTRL-^|.
246
247 *F*
248F{char} To the [count]'th occurrence of {char} to the left.
249 The cursor is placed on {char} |inclusive|.
250 {char} can be entered like with the |f| command.
251
252 *t*
253t{char} Till before [count]'th occurrence of {char} to the
254 right. The cursor is placed on the character left of
255 {char} |inclusive|.
256 {char} can be entered like with the |f| command.
257
258 *T*
259T{char} Till after [count]'th occurrence of {char} to the
260 left. The cursor is placed on the character right of
261 {char} |inclusive|.
262 {char} can be entered like with the |f| command.
263
264 *;*
265; Repeat latest f, t, F or T [count] times.
266
267 *,*
268, Repeat latest f, t, F or T in opposite direction
269 [count] times.
270
271These commands move the cursor to the specified column in the current line.
272They stop at the first column and at the end of the line, except "$", which
273may move to one of the next lines. See 'whichwrap' option to make some of the
274commands move across line boundaries.
275
276==============================================================================
2773. Up-down motions *up-down-motions*
278
279k or *k*
280<Up> or *<Up>* *CTRL-P*
281CTRL-P [count] lines upward |linewise|.
282
283j or *j*
284<Down> or *<Down>*
285CTRL-J or *CTRL-J*
286<NL> or *<NL>* *CTRL-N*
287CTRL-N [count] lines downward |linewise|.
288
289gk or *gk* *g<Up>*
290g<Up> [count] display lines upward. |exclusive| motion.
291 Differs from 'k' when lines wrap, and when used with
292 an operator, because it's not linewise. {not in Vi}
293
294gj or *gj* *g<Down>*
295g<Down> [count] display lines downward. |exclusive| motion.
296 Differs from 'j' when lines wrap, and when used with
297 an operator, because it's not linewise. {not in Vi}
298
299 *-*
300- <minus> [count] lines upward, on the first non-blank
301 character |linewise|.
302
303+ or *+*
304CTRL-M or *CTRL-M* *<CR>*
305<CR> [count] lines downward, on the first non-blank
306 character |linewise|.
307
308 *_*
309_ <underscore> [count] - 1 lines downward, on the first non-blank
310 character |linewise|.
311
312 *G*
313G Goto line [count], default last line, on the first
314 non-blank character |linewise|. If 'startofline' not
315 set, keep the same column.
316
317 *<C-End>*
318<C-End> Goto line [count], default last line, on the last
319 character |inclusive|. {not in Vi}
320
321<C-Home> or *gg* *<C-Home>*
322gg Goto line [count], default first line, on the first
323 non-blank character |linewise|. If 'startofline' not
324 set, keep the same column.
325
326:[range] Set the cursor on the specified line number. If
327 there are several numbers, the last one is used.
328
329 *N%*
330{count}% Go to {count} percentage in the file, on the first
331 non-blank in the line |linewise|. To compute the new
332 line number this formula is used:
333 ({count} * number-of-lines + 99) / 100
334 See also 'startofline' option. {not in Vi}
335
336:[range]go[to] [count] *:go* *:goto* *go*
337[count]go Go to {count} byte in the buffer. Default [count] is
338 one, start of the file. When giving [range], the
339 last number in it used as the byte count. End-of-line
340 characters are counted depending on the current
341 'fileformat' setting.
342 {not in Vi}
343 {not available when compiled without the
344 |+byte_offset| feature}
345
346These commands move to the specified line. They stop when reaching the first
347or the last line. The first two commands put the cursor in the same column
348(if possible) as it was after the last command that changed the column,
349except after the "$" command, then the cursor will be put on the last
350character of the line.
351
352==============================================================================
3534. Word motions *word-motions*
354
355<S-Right> or *<S-Right>* *w*
356w [count] words forward. |exclusive| motion.
357
358<C-Right> or *<C-Right>* *W*
359W [count] WORDS forward. |exclusive| motion.
360
361 *e*
362e Forward to the end of word [count] |inclusive|.
363
364 *E*
365E Forward to the end of WORD [count] |inclusive|.
366
367<S-Left> or *<S-Left>* *b*
368b [count] words backward. |exclusive| motion.
369
370<C-Left> or *<C-Left>* *B*
371B [count] WORDS backward. |exclusive| motion.
372
373 *ge*
374ge Backward to the end of word [count] |inclusive|.
375
376 *gE*
377gE Backward to the end of WORD [count] |inclusive|.
378
379These commands move over words or WORDS.
380 *word*
381A word consists of a sequence of letters, digits and underscores, or a
382sequence of other non-blank characters, separated with white space (spaces,
383tabs, <EOL>). This can be changed with the 'iskeyword' option.
384 *WORD*
385A WORD consists of a sequence of non-blank characters, separated with white
386space. An empty line is also considered to be a word and a WORD.
387
388A sequence of folded lines is counted for one word of a single character.
389"w" and "W", "e" and "E" move to the start/end of the first word or WORD after
390a range of folded lines. "b" and "B" move to the start of the first word or
391WORD before the fold.
392
393Special case: "cw" and "cW" are treated like "ce" and "cE" if the cursor is
394on a non-blank. This is because "cw" is interpreted as change-word, and a
395word does not include the following white space. {Vi: "cw" when on a blank
396followed by other blanks changes only the first blank; this is probably a
397bug, because "dw" deletes all the blanks}
398
399Another special case: When using the "w" motion in combination with an
400operator and the last word moved over is at the end of a line, the end of
401that word becomes the end of the operated text, not the first word in the
402next line.
403
404The original Vi implementation of "e" is buggy. For example, the "e" command
405will stop on the first character of a line if the previous line was empty.
406But when you use "2e" this does not happen. In Vim "ee" and "2e" are the
407same, which is more logical. However, this causes a small incompatibility
408between Vi and Vim.
409
410==============================================================================
4115. Text object motions *object-motions*
412
413 *(*
414( [count] sentences backward. |exclusive| motion.
415
416 *)*
417) [count] sentences forward. |exclusive| motion.
418
419 *{*
420{ [count] paragraphs backward. |exclusive| motion.
421
422 *}*
423} [count] paragraphs forward. |exclusive| motion.
424
425 *]]*
426]] [count] sections forward or to the next '{' in the
427 first column. When used after an operator, then the
428 '}' in the first column. |linewise|
429
430 *][*
431][ [count] sections forward or to the next '}' in the
432 first column. |linewise|
433
434 *[[*
435[[ [count] sections backward or to the previous '{' in
436 the first column. |linewise|
437
438 *[]*
439[] [count] sections backward or to the previous '}' in
440 the first column. |linewise|
441
442These commands move over three kinds of text objects.
443
444 *sentence*
445A sentence is defined as ending at a '.', '!' or '?' followed by either the
446end of a line, or by a space or tab. Any number of closing ')', ']', '"'
447and ''' characters may appear after the '.', '!' or '?' before the spaces,
448tabs or end of line. A paragraph and section boundary is also a sentence
449boundary.
450If the 'J' flag is present in 'cpoptions', at least two spaces have to
451follow the punctuation mark; <Tab>s are not recognized as white space.
452The definition of a sentence cannot be changed.
453
454 *paragraph*
455A paragraph begins after each empty line, and also at each of a set of
456paragraph macros, specified by the pairs of characters in the 'paragraphs'
457option. The default is "IPLPPPQPP LIpplpipbp", which corresponds to the
458macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in the
459first column). A section boundary is also a paragraph boundary. Note that
460this does not include a '{' or '}' in the first column. Also note that a
461blank line (only containing white space) is NOT a paragraph boundary.
462
463 *section*
464A section begins after a form-feed (<C-L>) in the first column and at each of
465a set of section macros, specified by the pairs of characters in the
466'sections' option. The default is "SHNHH HUnhsh", which defines a section to
467start at the nroff macros ".SH", ".NH", ".H", ".HU", ".nh" and ".sh".
468
469The "]" and "[" commands stop at the '{' or '}' in the first column. This is
470useful to find the start or end of a function in a C program. Note that the
471first character of the command determines the search direction and the
472second character the type of brace found.
473
474If your '{' or '}' are not in the first column, and you would like to use "[["
475and "]]" anyway, try these mappings: >
476 :map [[ ?{<CR>w99[{
477 :map ][ /}<CR>b99]}
478 :map ]] j0[[%/{<CR>
479 :map [] k$][%?}<CR>
480[type these literally, see |<>|]
481
482==============================================================================
4836. Text object selection *object-select* *text-objects*
484 *v_a* *v_i*
485
486This is a series of commands that can only be used while in Visual mode or
487after an operator. The commands that start with "a" select "a"n object
488including white space, the commands starting with "i" select an "inner" object
489without white space, or just the white space. Thus the "inner" commands
490always select less text than the "a" commands.
491
492These commands are {not in Vi}.
493These commands are not available when the |+textobjects| feature has been
494disabled at compile time.
495 *v_aw* *aw*
496aw "a word", select [count] words (see |word|).
497 Leading or trailing white space is included, but not
498 counted.
499 When used in Visual linewise mode "aw" switches to
500 Visual characterwise mode.
501
502 *v_iw* *iw*
503iw "inner word", select [count] words (see |word|).
504 White space between words is counted too.
505 When used in Visual linewise mode "iw" switches to
506 Visual characterwise mode.
507
508 *v_aW* *aW*
509aW "a WORD", select [count] WORDs (see |WORD|).
510 Leading or trailing white space is included, but not
511 counted.
512 When used in Visual linewise mode "aW" switches to
513 Visual characterwise mode.
514
515 *v_iW* *iW*
516iW "inner WORD", select [count] WORDs (see |WORD|).
517 White space between words is counted too.
518 When used in Visual linewise mode "iW" switches to
519 Visual characterwise mode.
520
521 *v_as* *as*
522as "a sentence", select [count] sentences (see
523 |sentence|).
524 When used in Visual mode it is made characterwise.
525
526 *v_is* *is*
527is "inner sentence", select [count] sentences (see
528 |sentence|).
529 When used in Visual mode it is made characterwise.
530
531 *v_ap* *ap*
532ap "a paragraph", select [count] paragraphs (see
533 |paragraph|).
534 Exception: a blank line (only containing white space)
535 is also a paragraph boundary.
536 When used in Visual mode it is made linewise.
537
538 *v_ip* *ip*
539ip "inner paragraph", select [count] paragraphs (see
540 |paragraph|).
541 Exception: a blank line (only containing white space)
542 is also a paragraph boundary.
543 When used in Visual mode it is made linewise.
544
545a] *v_a]* *v_a[* *a]* *a[*
546a[ "a [] block", select [count] '[' ']' blocks. This
547 goes backwards to the [count] unclosed '[', and finds
548 the matching ']'. The enclosed text is selected,
549 including the '[' and ']'.
550 When used in Visual mode it is made characterwise.
551
552i] *v_i]* *v_i[* *i]* *i[*
553i[ "inner [] block", select [count] '[' ']' blocks. This
554 goes backwards to the [count] unclosed '[', and finds
555 the matching ']'. The enclosed text is selected,
556 excluding the '[' and ']'.
557 When used in Visual mode it is made characterwise.
558
559a) *v_a)* *a)* *a(*
560a( *v_ab* *v_a(* *ab*
561ab "a block", select [count] blocks, from "[count] [(" to
562 the matching ')', including the '(' and ')' (see
563 |[(|). Does not include white space outside of the
564 parenthesis.
565 When used in Visual mode it is made characterwise.
566
567i) *v_i)* *i)* *i(*
568i( *v_ib* *v_i(* *ib*
569ib "inner block", select [count] blocks, from "[count] [("
570 to the matching ')', excluding the '(' and ')' (see
571 |[(|).
572 When used in Visual mode it is made characterwise.
573
574a> *v_a>* *v_a<* *a>* *a<*
575a< "a <> block", select [count] <> blocks, from the
576 [count]'th unmatched '<' backwards to the matching
577 '>', including the '<' and '>'.
578 When used in Visual mode it is made characterwise.
579
580i> *v_i>* *v_i<* *i>* *i<*
581i< "inner <> block", select [count] <> blocks, from
582 the [count]'th unmatched '<' backwards to the matching
583 '>', excluding the '<' and '>'.
584 When used in Visual mode it is made characterwise.
585
586a} *v_a}* *a}* *a{*
587a{ *v_aB* *v_a{* *aB*
588aB "a Block", select [count] Blocks, from "[count] [{" to
589 the matching '}', including the '{' and '}' (see
590 |[{|).
591 When used in Visual mode it is made characterwise.
592
593i} *v_i}* *i}* *i{*
594i{ *v_iB* *v_i{* *iB*
595iB "inner Block", select [count] Blocks, from "[count] [{"
596 to the matching '}', excluding the '{' and '}' (see
597 |[{|).
598 When used in Visual mode it is made characterwise.
599
Bram Moolenaarcfbc5ee2004-07-02 15:38:35 +0000600a" *v_aquote* *aquote*
601a' *v_a'* *a'*
602a` *v_a`* *a`*
603 "a quoted string". Selects the text from the previous
604 quote until the next quote. The 'quoteescape' is used
605 to skip escaped quotes.
606 When the cursor starts on a quote, Vim will figure out
607 which quote pairs form a string by searching from the
608 start of the line.
609 Any trailing or leading white space is included.
610 When used in Visual mode it is made characterwise.
611 Repeating this object in Visual mode another string is
612 included. A count is currently not used.
613
614i" *v_iquote* *iquote*
615i' *v_i'* *i'*
616i` *v_i`* *i`*
617 Like a", a' and a`, but exclude the quotes and
618 repeating won't extend the Visual selection.
619
Bram Moolenaar071d4272004-06-13 20:20:40 +0000620When used after an operator:
621For non-block objects:
622 For the "a" commands: The operator applies to the object and the white
623 space after the object. If there is no white space after the object
624 or when the cursor was in the white space before the object, the white
625 space before the object is included.
626 For the "inner" commands: If the cursor was on the object, the
627 operator applies to the object. If the cursor was on white space, the
628 operator applies to the white space.
629For a block object:
630 The operator applies to the block where the cursor is in, or the block
631 on which the cursor is on one of the braces. For the "inner" commands
632 the surrounding braces are excluded. For the "a" commands, the braces
633 are included.
634
635When used in Visual mode:
636When start and end of the Visual area are the same (just after typing "v"):
637 One object is selected, the same as for using an operator.
638When start and end of the Visual area are not the same:
639 For non-block objects the area is extended by one object or the white
640 space up to the next object, or both for the "a" objects. The
641 direction in which this happens depends on which side of the Visual
642 area the cursor is. For the block objects the block is extended one
643 level outwards.
644
645For illustration, here is a list of delete commands, grouped from small to big
646objects. Note that for a single character and a whole line the existing vi
647movement commands are used.
648 "dl" delete character (alias: "x") |dl|
649 "diw" delete inner word *diw*
650 "daw" delete a word *daw*
651 "diW" delete inner WORD (see |WORD|) *diW*
652 "daW" delete a WORD (see |WORD|) *daW*
653 "dd" delete one line |dd|
654 "dis" delete inner sentence *dis*
655 "das" delete a sentence *das*
656 "dib" delete inner '(' ')' block *dib*
657 "dab" delete a '(' ')' block *dab*
658 "dip" delete inner paragraph *dip*
659 "dap" delete a paragraph *dap*
660 "diB" delete inner '{' '}' block *diB*
661 "daB" delete a '{' '}' block *daB*
662
663Note the difference between using a movement command and an object. The
664movement command operates from here (cursor position) to where the movement
665takes us. When using an object the whole object is operated upon, no matter
666where on the object the cursor is. For example, compare "dw" and "daw": "dw"
667deletes from the cursor position to the start of the next word, "daw" deletes
668the word under the cursor and the space after or before it.
669
670==============================================================================
6717. Marks *mark-motions* *E20* *E78*
672
673Jumping to a mark can be done in two ways:
6741. With ` (backtick): The cursor is positioned at the specified location
675 and the motion is |exclusive|.
6762. With ' (single quote): The cursor is positioned on the first non-blank
677 character in the line of the specified location and
678 the motion is linewise.
679
680 *m* *mark* *Mark*
681m{a-zA-Z} Set mark {a-zA-Z} at cursor position (does not move
682 the cursor, this is not a motion command).
683
684 *m'* *m`*
685m' or m` Set the previous context mark. This can be jumped to
686 with the "''" or "``" command (does not move the
687 cursor, this is not a motion command).
688
689 *m[* *m]*
690m[ or m] Set the |'[| or |']| mark. Useful when an operator is
691 to be simulated by multiple commands. (does not move
692 the cursor, this is not a motion command).
693
694 *:ma* *:mark* *E191*
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000695:[range]ma[rk] {a-zA-Z'}
696 Set mark {a-zA-Z'} at last line number in [range],
Bram Moolenaar071d4272004-06-13 20:20:40 +0000697 column 0. Default is cursor line.
698
699 *:k*
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000700:[range]k{a-zA-Z'} Same as :mark, but the space before the mark name can
Bram Moolenaar071d4272004-06-13 20:20:40 +0000701 be omitted.
702
703 *'* *'a* *`* *`a*
704'{a-z} `{a-z} Jump to the mark {a-z}.
705
706 *'A* *'0* *`A* *`0*
707'{A-Z0-9} `{A-Z0-9} To the mark {A-Z0-9} in the correct file (not a motion
708 command when in another file). {not in Vi}
709
710 *g'* *g'a* *g`* *g`a*
711g'{mark} g`{mark}
712 Jump to the {mark}, but don't change the jumplist when
713 jumping within the current buffer. Example: >
714 g`"
715< jumps to the last known position in a file. See
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000716 $VIMRUNTIME/vimrc_example.vim.
717 Also see |:keepjumps|.
718 {not in Vi}
Bram Moolenaar071d4272004-06-13 20:20:40 +0000719
720 *:marks*
721:marks List all the current marks (not a motion command).
722 The |'(|, |')|, |'{| and |'}| marks are not listed.
723 {not in Vi}
724 *E283*
725:marks {arg} List the marks that are mentioned in {arg} (not a
726 motion command). For example: >
727 :marks aB
728< to list marks 'a' and 'B'. {not in Vi}
729
730A mark is not visible in any way. It is just a position in the file that is
731remembered. Do not confuse marks with named registers, they are totally
732unrelated.
733
734'a - 'z lowercase marks, valid within one file
735'A - 'Z uppercase marks, also called file marks, valid between files
736'0 - '9 numbered marks, set from .viminfo file
737
738Lowercase marks 'a to 'z are remembered as long as the file remains in the
739buffer list. If you remove the file from the buffer list, all its marks are
740lost. If you delete a line that contains a mark, that mark is erased.
741
742To delete a mark: Create a new line, position the mark there, delete the line.
743E.g.: "o<Esc>mxdd". This does change the file though. Using "u" won't work,
744it also restores marks.
745
746Lowercase marks can be used in combination with operators. For example: "d't"
747deletes the lines from the cursor position to mark 't'. Hint: Use mark 't' for
748Top, 'b' for Bottom, etc.. Lowercase marks are restored when using undo and
749redo.
750
751Uppercase marks 'A to 'Z include the file name. {Vi: no uppercase marks} You
752can use them to jump from file to file. You can only use an uppercase mark
753with an operator if the mark is in the current file. The line number of the
754mark remains correct, even if you insert/delete lines or edit another file for
755a moment. When the 'viminfo' option is not empty, uppercase marks are kept in
756the .viminfo file. See |viminfo-file-marks|.
757
758Numbered marks '0 to '9 are quite different. They can not be set directly.
759They are only present when using a viminfo file |viminfo-file|. Basically '0
760is the location of the cursor when you last exited Vim, '1 the last but one
761time, etc. Use the "r" flag in 'viminfo' to specify files for which no
762Numbered mark should be stored. See |viminfo-file-marks|.
763
764
765 *'[* *`[*
766'[ `[ To the first character of the previously changed
767 or yanked text. {not in Vi}
768
769 *']* *`]*
770'] `] To the last character of the previously changed or
771 yanked text. {not in Vi}
772
773After executing an operator the Cursor is put at the beginning of the text
774that was operated upon. After a put command ("p" or "P") the cursor is
775sometimes placed at the first inserted line and sometimes on the last inserted
776character. The four commands above put the cursor at either end. Example:
777After yanking 10 lines you want to go to the last one of them: "10Y']". After
778inserting several lines with the "p" command you want to jump to the lowest
779inserted line: "p']". This also works for text that has been inserted.
780
781Note: After deleting text, the start and end positions are the same, except
782when using blockwise Visual mode. These commands do not work when no change
783was made yet in the current file.
784
785 *'<* *`<*
786'< `< To the first character of the last selected Visual
787 area in the current buffer. {not in Vi}.
788
789 *'>* *`>*
790'> `> To the last character of the last selected Visual
791 area in the current buffer. {not in Vi}.
792
793 *''* *``*
794'' `` To the position before latest jump, or where the last
795 "m'" or "m`" command was given. Not set when the
796 |:keepjumps| command modifier was used.
797 Also see |restore-position|.
798
799 *'quote* *`quote*
800'" `" To the cursor position when last exiting the current
801 buffer. Defaults to the first character of the first
802 line. See |last-position-jump| for how to use this
803 for each opened file.
804 Only one position is remembered per buffer, not one
805 for each window. As long as the buffer is visible in
806 a window the position won't be changed.
807 {not in Vi}.
808
809 *'^* *`^*
810'^ `^ To the position where the cursor was the last time
811 when Insert mode was stopped This is used by the |gi|
812 command. Not set when the |:keepjumps| command
813 modifier was used. {not in Vi}
814
815 *'.* *`.*
816'. `. To the position where the last change was made. The
817 position is at or near where the change started.
818 Sometimes a command is executed as several changes,
819 then the position can be near the end of what the
820 command changed. For example when inserting a word,
821 the position will be on the last character.
822 {not in Vi}
823
824 *'(* *`(*
825'( `( To the start of the current sentence, like the |(|
826 command. {not in Vi}
827
828 *')* *`)*
829') `) To the end of the current sentence, like the |)|
830 command. {not in Vi}
831
832 *'{* *`{*
833'{ `{ To the start of the current paragraph, like the |{|
834 command. {not in Vi}
835
836 *'}* *`}*
837'} `} To the end of the current paragraph, like the |}|
838 command. {not in Vi}
839
840These commands are not marks themselves, but jump to a mark:
841
842 *]'*
843]' [count] times to next line with a lowercase mark below
844 the cursor, on the first non-blank character in the
845 line. {not in Vi}
846
847 *]`*
848]` [count] times to lowercase mark after the cursor. {not
849 in Vi}
850
851 *['*
852[' [count] times to previous line with a lowercase mark
853 before the cursor, on the first non-blank character in
854 the line. {not in Vi}
855
856 *[`*
857[` [count] times to lowercase mark before the cursor.
858 {not in Vi}
859
860
861:loc[kmarks] {command} *:loc* *:lockmarks*
862 Execute {command} without adjusting marks. This is
863 useful when changing text in a way that the line count
864 will be the same when the change has completed.
865 WARNING: When the line count does change, marks below
866 the change will keep their line number, thus move to
867 another text line.
868 These items will not be adjusted for deleted/inserted
869 lines:
870 - lower case letter marks 'a - 'z
871 - upper case letter marks 'A - 'Z
872 - numbered marks '0 - '9
873 - last insert position '^
874 - last change position '.
875 - the Visual area '< and '>
876 - line numbers in placed signs
877 - line numbers in quickfix positions
878 - positions in the |jumplist|
879 - positions in the |tagstack|
880 These items will still be adjusted:
881 - previous context mark ''
882 - the cursor position
883 - the view of a window on a buffer
884 - folds
885 - diffs
886
887:kee[pmarks] {command} *:kee* *:keepmarks*
888 Currently only has effect for the filter command
889 |:range!|:
890 - When the number of lines after filtering is equal to
891 or larger than before, all marks are kept at the
892 same line number.
893 - When the number of lines decreases, the marks in the
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000894 lines that disappeared are deleted.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000895 In any case the marks below the filtered text have
896 their line numbers adjusted, thus stick to the text,
897 as usual.
898 When the 'R' flag is missing from 'cpoptions' this has
899 the same effect as using ":keepmarks".
900
901 *:keepj* *:keepjumps*
902:keepj[umps] {command}
Bram Moolenaar69a7cb42004-06-20 12:51:53 +0000903 Moving around in {command} does not change the |''|,
904 |'.| and |'^| marks, the |jumplist| or the
905 |changelist|.
906 Useful when making a change or inserting text
907 automatically and the user doesn't want to go to this
908 position. E.g., when updating a "Last change"
909 timestamp in the first line: >
910
911 :let lnum = getline(".")
912 :keepjumps normal gg
913 :call SetLastChange()
914 :keepjumps exe "normal " . lnum . "G"
915<
916 Note that ":keepjumps" must be used for every command.
917 When invoking a function the commands in that function
918 can still change the jumplist.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000919
920==============================================================================
9218. Jumps *jump-motions*
922
923A "jump" is one of the following commands: "'", "`", "G", "/", "?", "n",
924"N", "%", "(", ")", "[[", "]]", "{", "}", ":s", ":tag", "L", "M", "H" and
925the commands that start editing a new file. If you make the cursor "jump"
926with one of these commands, the position of the cursor before the jump is
927remembered. You can return to that position with the "''" and "``" command,
928unless the line containing that position was changed or deleted.
929
930 *CTRL-O*
931CTRL-O Go to [count] Older cursor position in jump list
932 (not a motion command). {not in Vi}
933 {not available without the +jumplist feature}
934
935<Tab> or *CTRL-I* *<Tab>*
936CTRL-I Go to [count] newer cursor position in jump list
937 (not a motion command).
938 In a |quickfix-window| it takes you to the position of
939 the error under the cursor.
940 {not in Vi}
941 {not available without the +jumplist feature}
942
943 *:ju* *:jumps*
944:ju[mps] Print the jump list (not a motion command). {not in
945 Vi} {not available without the +jumplist feature}
946
947 *jumplist*
948Jumps are remembered in a jump list. With the CTRL-O and CTRL-I command you
949can go to cursor positions before older jumps, and back again. Thus you can
950move up and down the list. There is a separate jump list for each window.
951The maximum number of entries is fixed at 100.
952{not available without the +jumplist feature}
953
954For example, after three jump commands you have this jump list:
955
956 jump line col file/line ~
957 3 1 0 some text ~
958 2 70 0 another line ~
959 1 1154 23 end. ~
960 > ~
961
962The "file/line" column shows the file name, or the text at the jump if it is
963in the current file (an indent is removed and a long line is truncated to fit
964in the window).
965
966You are currently in line 1167. If you then use the CTRL-O command, the
967cursor is put in line 1154. This results in:
968
969 jump line col file/line ~
970 2 1 0 some text ~
971 1 70 0 another line ~
972 > 0 1154 23 end. ~
973 1 1167 0 foo bar ~
974
975The pointer will be set at the last used jump position. The next CTRL-O
976command will use the entry above it, the next CTRL-I command will use the
977entry below it. If the pointer is below the last entry, this indicates that
978you did not use a CTRL-I or CTRL-O before. In this case the CTRL-O command
979will cause the cursor position to be added to the jump list, so you can get
980back to the position before the CTRL-O. In this case this is line 1167.
981
982With more CTRL-O commands you will go to lines 70 and 1. If you use CTRL-I
983you can go back to 1154 and 1167 again. Note that the number in the "jump"
984column indicates the count for the CTRL-O or CTRL-I command that takes you to
985this position.
986
987If you use a jump command, the current line number is inserted at the end of
988the jump list. If the same line was already in the jump list, it is removed.
989The result is that when repeating CTRL-O you will get back to old positions
990only once.
991
992When the |:keepjumps| command modifier is used, jumps are not stored in the
993jumplist.
994
995After the CTRL-O command that got you into line 1154 you could give another
996jump command (e.g., "G"). The jump list would then become:
997
998 jump line col file/line ~
999 4 1 0 some text ~
1000 3 70 0 another line ~
1001 2 1167 0 foo bar ~
1002 1 1154 23 end. ~
1003 > ~
1004
1005The line numbers will be adjusted for deleted and inserted lines. This fails
1006if you stop editing a file without writing, like with ":n!".
1007
1008When you split a window, the jumplist will be copied to the new window.
1009
1010If you have included the ' item in the 'viminfo' option the jumplist will be
1011stored in the viminfo file and restored when starting Vim.
1012
1013
1014CHANGE LIST JUMPS *changelist* *change-list-jumps* *E664*
1015
1016When making a change the cursor position is remembered. One position is
1017remembered for every change that can be undone, unless it is close to a
1018previous change. Two commands can be used to jump to positions of changes,
1019also those that have been undone:
1020
1021 *g;* *E662*
1022g; Go to [count] older position in change list.
1023 If [count] is larger than the number of older change
1024 positions go to the oldest change.
1025 If there is no older change an error message is given.
1026 (not a motion command)
1027 {not in Vi}
1028 {not available without the +jumplist feature}
1029
1030 *g,* *E663*
1031g, Go to [count] newer cursor position in change list.
1032 Just like "g;| but in the opposite direction.
1033 (not a motion command)
1034 {not in Vi}
1035 {not available without the +jumplist feature}
1036
1037When using a count you jump as far back or forward as possible. Thus you can
1038use "999g;" to go to the first change for which the position is still
1039remembered. The number of entries in the change list is fixed and is the same
1040as for the |jumplist|.
1041
1042When two undo-able changes are in the same line and at a column position less
1043than 'textwidth' apart only the last one is remembered. This avoids that a
1044sequence of small changes in a line, for example "xxxxx", adds many positions
1045to the change list. When 'textwidth' is zero 'wrapmargin' is used. When that
1046also isn't set a fixed number of 79 is used. Detail: For the computations
1047bytes are used, not characters, to avoid a speed penalty (this only matters
1048for multi-byte encodings).
1049
1050Note that when text has been inserted or deleted the cursor position might be
1051a bit different from the position of the change. Especially when lines have
1052been deleted.
1053
1054When the |:keepjumps| command modifier is used the position of a change is not
1055remembered.
1056
1057 *:changes*
1058:changes Print the change list. A ">" character indicates the
1059 current position. Just after a change it is below the
1060 newest entry, indicating that "g;" takes you to the
1061 newest entry position. The first column indicates the
1062 count needed to take you to this position. Example:
1063
1064 change line col text ~
1065 3 9 8 bla bla bla
1066 2 11 57 foo is a bar
1067 1 14 54 the latest changed line
1068 >
1069
1070 The "3g;" command takes you to line 9. Then the
1071 output of ":changes is:
1072
1073 change line col text ~
1074 > 0 9 8 bla bla bla
1075 1 11 57 foo is a bar
1076 2 14 54 the latest changed line
1077
1078 Now you can use "g," to go to line 11 and "2g," to go
1079 to line 14.
1080
1081==============================================================================
10829. Various motions *various-motions*
1083
1084 *%*
1085% Find the next item in this line after or under the
1086 cursor and jump to its match. |inclusive| motion.
1087 Items can be:
1088 ([{}]) parenthesis or (curly/square) brackets
1089 (this can be changed with the
1090 'matchpairs' option)
1091 /* */ start or end of C-style comment
1092 #if, #ifdef, #else, #elif, #endif
1093 C preprocessor conditionals (when the
1094 cursor is on the # or no ([{
1095 following)
1096 For other items the matchit plugin can be used, see
1097 |matchit-install|.
1098
1099 When 'cpoptions' contains "M" |cpo-M| backslashes
1100 before parens and braces are ignored. Without "M" the
1101 number of backslashes matters: an even number doesn't
1102 match with an odd number. Thus in "( \) )" and "\( (
1103 \)" the first and last parenthesis match.
1104 When the '%' character is not present in 'cpoptions'
1105 |cpo-%|, parens and braces inside double quotes are
1106 ignored, unless the number of parens/braces in a line
1107 is uneven and this line and the previous one does not
1108 end in a backslash. '(', '{', '[', ']', '}' and ')'
1109 are also ignored (parens and braces inside single
1110 quotes). Note that this works fine for C, but not for
1111 Perl, where single quotes are used for strings.
1112 No count is allowed ({count}% jumps to a line {count}
1113 percentage down the file |N%|). Using '%' on
1114 #if/#else/#endif makes the movement linewise.
1115
1116 *[(*
1117[( go to [count] previous unmatched '('.
1118 |exclusive| motion. {not in Vi}
1119
1120 *[{*
1121[{ go to [count] previous unmatched '{'.
1122 |exclusive| motion. {not in Vi}
1123
1124 *])*
1125]) go to [count] next unmatched ')'.
1126 |exclusive| motion. {not in Vi}
1127
1128 *]}*
1129]} go to [count] next unmatched '}'.
1130 |exclusive| motion. {not in Vi}
1131
1132The above four commands can be used to go to the start or end of the current
1133code block. It is like doing "%" on the '(', ')', '{' or '}' at the other
1134end of the code block, but you can do this from anywhere in the code block.
1135Very useful for C programs. Example: When standing on "case x:", "[{" will
1136bring you back to the switch statement.
1137
1138 *]m*
1139]m Go to [count] next start of a method (for Java or
1140 similar structured language). When not before the
1141 start of a method, jump to the start or end of the
1142 class. When no '{' is found after the cursor, this is
1143 an error. |exclusive| motion. {not in Vi}
1144 *]M*
1145]M Go to [count] next end of a method (for Java or
1146 similar structured language). When not before the end
1147 of a method, jump to the start or end of the class.
1148 When no '}' is found after the cursor, this is an
1149 error. |exclusive| motion. {not in Vi}
1150 *[m*
1151[m Go to [count] previous start of a method (for Java or
1152 similar structured language). When not after the
1153 start of a method, jump to the start or end of the
1154 class. When no '{' is found before the cursor this is
1155 an error. |exclusive| motion. {not in Vi}
1156 *[M*
1157[M Go to [count] previous end of a method (for Java or
1158 similar structured language). When not after the
1159 end of a method, jump to the start or end of the
1160 class. When no '}' is found before the cursor this is
1161 an error. |exclusive| motion. {not in Vi}
1162
1163The above two commands assume that the file contains a class with methods.
1164The class definition is surrounded in '{' and '}'. Each method in the class
1165is also surrounded with '{' and '}'. This applies to the Java language. The
1166file looks like this: >
1167
1168 // comment
1169 class foo {
1170 int method_one() {
1171 body_one();
1172 }
1173 int method_two() {
1174 body_two();
1175 }
1176 }
1177Starting with the cursor on "body_two()", using "[m" will jump to the '{' at
1178the start of "method_two()" (obviously this is much more useful when the
1179method is long!). Using "2[m" will jump to the start of "method_one()".
1180Using "3[m" will jump to the start of the class.
1181
1182 *[#*
1183[# go to [count] previous unmatched "#if" or "#else".
1184 |exclusive| motion. {not in Vi}
1185
1186 *]#*
1187]# go to [count] next unmatched "#else" or "#endif".
1188 |exclusive| motion. {not in Vi}
1189
1190These two commands work in C programs that contain #if/#else/#endif
1191constructs. It brings you to the start or end of the #if/#else/#endif where
1192the current line is included. You can then use "%" to go to the matching line.
1193
1194 *[star* *[/*
1195[* or [/ go to [count] previous start of a C comment "/*".
1196 |exclusive| motion. {not in Vi}
1197
1198 *]star* *]/*
1199]* or ]/ go to [count] next end of a C comment "*/".
1200 |exclusive| motion. {not in Vi}
1201
1202
1203 *H*
1204H To line [count] from top (Home) of window (default:
1205 first line on the window) on the first non-blank
1206 character |linewise|. See also 'startofline' option.
1207 Cursor is adjusted for 'scrolloff' option.
1208
1209 *M*
1210M To Middle line of window, on the first non-blank
1211 character |linewise|. See also 'startofline' option.
1212
1213 *L*
1214L To line [count] from bottom of window (default: Last
1215 line on the window) on the first non-blank character
1216 |linewise|. See also 'startofline' option.
1217 Cursor is adjusted for 'scrolloff' option.
1218
1219<LeftMouse> Moves to the position on the screen where the mouse
1220 click is |inclusive|. See also |<LeftMouse>|. If the
1221 position is in a status line, that window is made the
1222 active window and the cursor is not moved. {not in Vi}
1223
1224 vim:tw=78:ts=8:ft=help:norl: