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