robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
98d767cd53
master
1*motion.txt* Nvim 2 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 13General remarks: 14 15If you want to know where you are in the file use the "CTRL-G" command 16|CTRL-G| or the "g CTRL-G" command |g_CTRL-G|. If you set the 'ruler' option, 17the cursor position is continuously shown in the status line (which slows down 18Vim a little). 19 20Experienced users prefer the hjkl keys because they are always right under 21their fingers. Beginners often prefer the arrow keys, because they do not 22know what the hjkl keys do. The mnemonic value of hjkl is clear from looking 23at the keyboard. Think of j as an arrow pointing downwards. 24 25The 'virtualedit' option can be set to make it possible to move the cursor to 26positions where there is no character or within a multi-column character (like 27a tab). 28 29 Type |gO| to see the table of contents. 30 31============================================================================== 321. Motions and operators *operator* 33 34The motion commands can be used after an operator command, to have the command 35operate on the text that was moved over. That is the text between the cursor 36position before and after the motion. Operators are generally used to delete 37or change text. The following operators are available: 38 39 |c| c change 40 |d| d delete 41 |y| y yank into register (does not change the text) 42 |~| ~ swap case (only if 'tildeop' is set) 43 |g~| g~ swap case 44 |gu| gu make lowercase 45 |gU| gU make uppercase 46 |!| ! filter through an external program 47 |=| = filter through 'equalprg' or C-indenting if empty 48 |gq| gq text formatting 49 |gw| gw text formatting with no cursor movement 50 |g?| g? ROT13 encoding 51 |>| > shift right 52 |<| < shift left 53 |zf| zf define a fold 54 |g@| g@ call function set with the 'operatorfunc' option 55 *motion-count-multiplied* 56If the motion includes a count and the operator also had a count before it, 57the two counts are multiplied. For example: "2d3w" deletes six words. 58 *operator-doubled* 59When doubling the operator it operates on a line. When using a count, before 60or after the first character, that many lines are operated upon. Thus `3dd` 61deletes three lines. A count before and after the first character is 62multiplied, thus `2y3y` yanks six lines. 63 *operator-resulting-pos* 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. 67The 'startofline' option applies only to the "d", "<<", "==" and ">>" linewise 68operations. 69 70 *linewise* *charwise* *characterwise* 71The operator either affects whole lines, or the characters between the start 72and end position. Generally, motions that move between lines affect lines 73(are linewise), and motions that move within a line affect characters (are 74charwise). However, there are some exceptions. 75 76 *exclusive* *inclusive* 77Character motion is either inclusive or exclusive. When inclusive, the 78start and end position of the motion are included in the operation. When 79exclusive, the last character towards the end of the buffer is not included. 80Linewise motions always include the start and end position. Plugins can 81check the v:event.inclusive flag of the |TextYankPost| event. 82 83Which motions are linewise, inclusive or exclusive is mentioned with the 84command. There are however, two general exceptions: 851. If the motion is exclusive and the end of the motion is in column 1, the 86 end of the motion is moved to the end of the previous line and the motion 87 becomes inclusive. Example: "}" moves to the first line after a paragraph, 88 but "d}" will not include that line. 89 *exclusive-linewise* 902. If the motion is exclusive, the end of the motion is in column 1 and the 91 start of the motion was at or before the first non-blank in the line, the 92 motion becomes linewise. Example: If a paragraph begins with some blanks 93 and you do "d}" while standing on the first non-blank, all the lines of 94 the paragraph are deleted, including the blanks. If you do a put now, the 95 deleted lines will be inserted below the cursor position. 96 97Note that when the operator is pending (the operator command is typed, but the 98motion isn't yet), a special set of mappings can be used. See |:omap|. 99 100Instead of first giving the operator and then a motion you can use Visual 101mode: mark the start of the text with "v", move the cursor to the end of the 102text that is to be affected and then hit the operator. The text between the 103start and the cursor position is highlighted, so you can see what text will 104be operated upon. This allows much more freedom, but requires more key 105strokes and has limited redo functionality. See the chapter on Visual mode 106|Visual-mode|. 107 108You can use a ":" command for a motion. For example "d:call FindEnd()". 109But this can't be repeated with "." if the command is more than one line. 110This can be repeated: > 111 d:call search("f")<CR> 112This cannot be repeated: > 113 d:if 1<CR> 114 call search("f")<CR> 115 endif<CR> 116Note that when using ":" any motion becomes charwise exclusive. 117 118 *inclusive-motion-selection-exclusive* 119When 'selection' is "exclusive", |Visual| mode is active and an inclusive 120motion has been used, the cursor position will be adjusted by another 121character to the right, so that the Visual selection includes the expected 122text and can be acted upon. 123 124 *forced-motion* 125FORCING A MOTION TO BE LINEWISE, CHARWISE OR BLOCKWISE 126 127When a motion is not of the type you would like to use, you can force another 128type by using "v", "V" or CTRL-V just after the operator. 129Example: > 130 dj 131deletes two lines > 132 dvj 133deletes from the cursor position until the character below the cursor > 134 d<C-V>j 135deletes the character under the cursor and the character below the cursor. > 136 137Be careful with forcing a linewise movement to be used charwise or blockwise, 138the column may not always be defined. 139 140 *o_v* 141v When used after an operator, before the motion command: Force 142 the operator to work charwise, also when the motion is 143 linewise. If the motion was linewise, it will become 144 |exclusive|. 145 If the motion already was charwise, toggle 146 inclusive/exclusive. This can be used to make an exclusive 147 motion inclusive and an inclusive motion exclusive. 148 149 *o_V* 150V When used after an operator, before the motion command: Force 151 the operator to work linewise, also when the motion is 152 charwise. 153 154 *o_CTRL-V* 155CTRL-V When used after an operator, before the motion command: Force 156 the operator to work blockwise. This works like Visual block 157 mode selection, with the corners defined by the cursor 158 position before and after the motion. 159 160============================================================================== 1612. Left-right motions *left-right-motions* 162 163These commands move the cursor to the specified column in the current line. 164They stop at the first column and at the end of the line, except "$", which 165may move to one of the next lines. See 'whichwrap' option to make some of the 166commands move across line boundaries. 167 168h or *h* 169<Left> or *<Left>* 170CTRL-H or *CTRL-H* *<BS>* 171<BS> [count] characters to the left. |exclusive| motion. 172 Note: If you prefer <BS> to delete a character, use 173 the mapping: > 174 :map CTRL-V<BS> X 175< (to enter "CTRL-V<BS>" type the CTRL-V key, followed 176 by the <BS> key) 177 178l or *l* 179<Right> or *<Right>* *<Space>* 180<Space> [count] characters to the right. |exclusive| motion. 181 See the 'whichwrap' option for adjusting the behavior 182 at end of line 183 184 *0* 1850 To the first character of the line. |exclusive| 186 motion. 187 188 *<Home>* *<kHome>* 189<Home> To the first character of the line. |exclusive| 190 motion. When moving up or down next, stay in same 191 TEXT column (if possible). Most other commands stay 192 in the same SCREEN column. <Home> works like "1|", 193 which differs from "0" when the line starts with a 194 <Tab>. 195 196 *^* 197^ To the first non-blank character of the line. 198 |exclusive| motion. Any count is ignored. 199 200 *$* *<End>* *<kEnd>* 201$ or <End> To the end of the line. When a count is given also go 202 [count - 1] lines downward, or as far is possible. 203 |inclusive| motion. If a count of 2 or larger is 204 given and the cursor is on the last line, that is an 205 error and the cursor doesn't move. 206 In Visual mode the cursor goes to just after the last 207 character in the line. 208 When 'virtualedit' is active, "$" may move the cursor 209 back from past the end of the line to the last 210 character in the line. 211 212 *g_* 213g_ To the last non-blank character of the line and 214 [count - 1] lines downward |inclusive|. 215 216 *g0* *g<Home>* 217g0 or g<Home> When lines wrap ('wrap' on): To the first character of 218 the screen line. |exclusive| motion. Differs from 219 "0" when a line is wider than the screen. 220 When lines don't wrap ('wrap' off): To the leftmost 221 character of the current line that is on the screen. 222 Differs from "0" when the first character of the line 223 is not on the screen. 224 225 *g^* 226g^ When lines wrap ('wrap' on): To the first non-blank 227 character of the screen line. |exclusive| motion. 228 Differs from "^" when a line is wider than the screen. 229 When lines don't wrap ('wrap' off): To the leftmost 230 non-blank character of the current line that is on the 231 screen. Differs from "^" when the first non-blank 232 character of the line is not on the screen. 233 234 *gm* 235gm Like "g0", but half a screenwidth to the right (or as 236 much as possible). 237 238 *gM* 239gM Like "g0", but to halfway the text of the line. 240 With a count: to this percentage of text in the line. 241 Thus "10gM" is near the start of the text and "90gM" 242 is near the end of the text. 243 244 *g$* 245g$ When lines wrap ('wrap' on): To the last character of 246 the screen line and [count - 1] screen lines downward 247 |inclusive|. Differs from "$" when a line is wider 248 than the screen. 249 When lines don't wrap ('wrap' off): To the rightmost 250 character of the current line that is visible on the 251 screen. Differs from "$" when the last character of 252 the line is not on the screen or when a count is used. 253 Additionally, vertical movements keep the column, 254 instead of going to the end of the line. 255 When 'virtualedit' is enabled moves to the end of the 256 screen line. 257 258 *g<End>* *g<kEnd>* 259g<End> Like |g$| but to the last non-blank character 260 instead of the last character. 261 262 *bar* 263| To screen column [count] in the current line. 264 |exclusive| motion. Ceci n'est pas une pipe. 265 266 *f* 267f{char} To [count]'th occurrence of {char} to the right. The 268 cursor is placed on {char} |inclusive|. 269 {char} can be entered as a digraph |digraph-arg|. 270 Composing characters may be used |utf-8-char-arg|. 271 |:lmap| mappings apply to {char}. The CTRL-^ command 272 in Insert mode can be used to switch this on/off 273 |i_CTRL-^|. 274 275 See |getcharsearch() |setcharsearch() 276 277 *F* 278F{char} To the [count]'th occurrence of {char} to the left. 279 The cursor is placed on {char} |exclusive|. 280 {char} can be entered like with the |f| command. 281 282 *t* 283t{char} Till before [count]'th occurrence of {char} to the 284 right. The cursor is placed on the character left of 285 {char} |inclusive|. 286 {char} can be entered like with the |f| command. 287 288 See |getcharsearch() |setcharsearch() 289 290 *T* 291T{char} Till after [count]'th occurrence of {char} to the 292 left. The cursor is placed on the character right of 293 {char} |exclusive|. 294 {char} can be entered like with the |f| command. 295 296 *;* 297; Repeat latest f, t, F or T [count] times. 298 299 See |getcharsearch() |setcharsearch() |cpo-;| 300 301 *,* 302, Repeat latest f, t, F or T in opposite direction 303 [count] times. 304 305 See |getcharsearch() |setcharsearch() |cpo-;| 306 307============================================================================== 3083. Up-down motions *up-down-motions* 309 310k or *k* 311<Up> or *<Up>* *CTRL-P* 312CTRL-P [count] lines upward |linewise|. 313 314j or *j* 315<Down> or *<Down>* 316CTRL-J or *CTRL-J* 317<NL> or *<NL>* *CTRL-N* 318CTRL-N [count] lines downward |linewise|. 319 320gk or *gk* *g<Up>* 321g<Up> [count] display lines upward. |exclusive| motion. 322 Differs from 'k' when lines wrap, and when used with 323 an operator, because it's not linewise. 324 325gj or *gj* *g<Down>* 326g<Down> [count] display lines downward. |exclusive| motion. 327 Differs from 'j' when lines wrap, and when used with 328 an operator, because it's not linewise. 329 330 *-* 331`-` <minus> [count] lines upward, on the first non-blank 332 character |linewise|. 333 *-_default* 334 By default "-" is mapped to open the parent directory 335 of the current buffer. |dir-mappings| |default-mappings| 336 337`+` or *+* 338CTRL-M or *CTRL-M* *<CR>* 339<CR> [count] lines downward, on the first non-blank 340 character |linewise|. 341 342 *_* 343_ <underscore> [count] - 1 lines downward, on the first non-blank 344 character |linewise|. 345 346 *G* 347G Goto line [count], default last line, on the first 348 non-blank character |linewise|. If 'startofline' not 349 set, keep the same column. 350 G is one of the |jump-motions|. 351 352 *<C-End>* 353<C-End> Goto line [count], default last line, on the last 354 character |inclusive|. 355 356<C-Home> or *gg* *<C-Home>* 357gg Goto line [count], default first line, on the first 358 non-blank character |linewise|. If 'startofline' not 359 set, keep the same column. 360 361 *:[range]* 362:[range] Set the cursor on the last line number in [range]. 363 In Ex mode, print the lines in [range]. 364 [range] can also be just one line number, e.g., ":1" 365 or ":'m". 366 In contrast with |G| this command does not modify the 367 |jumplist|. 368 *N%* 369{count}% Go to {count} percentage in the file, on the first 370 non-blank in the line |linewise|. To compute the new 371 line number this formula is used: 372 ({count} * number-of-lines + 99) / 100 373 See also 'startofline' option. 374 375:[range]go[to] [count] *:go* *:goto* *go* 376[count]go Go to [count] byte in the buffer. |exclusive| motion. 377 Default [count] is one, start of the file. When 378 giving [range], the last number in it used as the byte 379 count. End-of-line characters are counted depending 380 on the current 'fileformat' setting. 381 Also see the |line2byte()| function, and the 'o' 382 option in 'statusline'. 383 384These commands move to the specified line. They stop when reaching the first 385or the last line. The first two commands put the cursor in the same column 386(if possible) as it was after the last command that changed the column, 387except after the "$" command, then the cursor will be put on the last 388character of the line. 389 390============================================================================== 3914. Word motions *word-motions* 392 393<S-Right> or *<S-Right>* *w* 394w [count] words forward. |exclusive| motion. 395 396<C-Right> or *<C-Right>* *W* 397W [count] WORDS forward. |exclusive| motion. 398 399 *e* 400e Forward to the end of word [count] |inclusive|. 401 Does not stop in an empty line. 402 403 *E* 404E Forward to the end of WORD [count] |inclusive|. 405 Does not stop in an empty line. 406 407<S-Left> or *<S-Left>* *b* 408b [count] words backward. |exclusive| motion. 409 410<C-Left> or *<C-Left>* *B* 411B [count] WORDS backward. |exclusive| motion. 412 413 *ge* 414ge Backward to the end of word [count] |inclusive|. 415 416 *gE* 417gE Backward to the end of WORD [count] |inclusive|. 418 419These commands move over words or WORDS. 420 *word* 421A word consists of a sequence of letters, digits and underscores, or a 422sequence of other non-blank characters, separated with white space (spaces, 423tabs, <EOL>). This can be changed with the 'iskeyword' option. For 424characters above 255, a word ends when the Unicode character class changes 425(e.g., between letters, subscripts, emojis, etc). An empty line is also 426considered to be a word. 427 *WORD* 428A WORD consists of a sequence of non-blank characters, separated with white 429space. An empty line is also considered to be a WORD. 430 431A sequence of folded lines is counted for one word of a single character. 432"w" and "W", "e" and "E" move to the start/end of the first word or WORD after 433a range of folded lines. "b" and "B" move to the start of the first word or 434WORD before the fold. 435 436Special case: "cw" and "cW" are treated like "ce" and "cE" if the cursor is 437on a non-blank. This is Vi-compatible, see |cpo-_| to change the behavior. 438 439Another special case: When using the "w" motion in combination with an 440operator and the last word moved over is at the end of a line, the end of 441that word becomes the end of the operated text, not the first word in the 442next line. 443 444The original Vi implementation of "e" is buggy. For example, the "e" command 445will stop on the first character of a line if the previous line was empty. 446But when you use "2e" this does not happen. In Vim "ee" and "2e" are the 447same, which is more logical. However, this causes a small incompatibility 448between Vi and Vim. 449 450============================================================================== 4515. Text object motions *object-motions* 452 453 *(* 454( [count] |sentence|s backward. |exclusive| motion. 455 456 *)* 457) [count] |sentence|s forward. |exclusive| motion. 458 459 *{* 460{ [count] |paragraph|s backward. |exclusive| motion. 461 462 *}* 463} [count] |paragraph|s forward. |exclusive| motion. 464 465 *]]* 466]] [count] |section|s forward or to the next "{" in the 467 first column. When used after an operator, then also 468 stops below a "}" in the first column. |exclusive| 469 Note that |exclusive-linewise| often applies. 470 In a :terminal buffer each shell prompt is treated as 471 a section. |terminal_]]| 472 473 *][* 474][ [count] |section|s forward or to the next '}' in the 475 first column. |exclusive| 476 Note that |exclusive-linewise| often applies. 477 478 *[[* 479[[ [count] |section|s backward or to the previous "{" in 480 the first column. |exclusive| 481 Note that |exclusive-linewise| often applies. 482 In a :terminal buffer each shell prompt is treated as 483 a section. |terminal_]]| 484 485 *[]* 486[] [count] |section|s backward or to the previous "}" in 487 the first column. |exclusive| 488 Note that |exclusive-linewise| often applies. 489 490These commands move over three kinds of text objects. 491 492 *sentence* 493A sentence is defined as ending at a '.', '!' or '?' followed by either the 494end of a line, or by a space or tab. Any number of closing ')', ']', '"' 495and ''' characters may appear after the '.', '!' or '?' before the spaces, 496tabs or end of line. A paragraph and section boundary is also a sentence 497boundary. 498If the 'J' flag is present in 'cpoptions', at least two spaces have to 499follow the punctuation mark; <Tab>s are not recognized as white space. 500The definition of a sentence cannot be changed. 501 502 *paragraph* 503A paragraph begins after each empty line, and also at each of a set of 504paragraph macros, specified by the pairs of characters in the 'paragraphs' 505option. The default is "IPLPPPQPP TPHPLIPpLpItpplpipbp", which corresponds to 506the macros ".IP", ".LP", etc. (These are nroff macros, so the dot must be in 507the first column). A section boundary is also a paragraph boundary. 508Note that a blank line (only containing white space) is NOT a paragraph 509boundary. 510Note: this does not include a '{' or '}' in the first column. 511 512 *section* 513A section begins after a form-feed (<C-L>) in the first column and at each of 514a set of section macros, specified by the pairs of characters in the 515'sections' option. The default is "SHNHH HUnhsh", which defines a section to 516start at the nroff macros ".SH", ".NH", ".H", ".HU", ".nh" and ".sh". 517In a :terminal buffer each shell prompt is treated as a section. |terminal_]]| 518 519The "]]" and "[[" commands stop at the '{' in the first column. This is 520useful to find the start of a function in a C program. To search for a '}' in 521the first column, the end of a C function, use "][" (forward) or "[]" 522(backward). Note that the first character of the command determines the 523search direction. 524 525If your '{' or '}' are not in the first column, and you would like to use "[[" 526and "]]" anyway, try these mappings: > 527 :map [[ ?{<CR>w99[{ 528 :map ][ /}<CR>b99]} 529 :map ]] j0[[%/{<CR> 530 :map [] k$][%?}<CR> 531[type these literally, see |<>|] 532 533============================================================================== 5346. Text object selection *object-select* *text-objects* 535 *v_a* *v_i* 536 537This is a series of commands that can only be used while in Visual mode or 538after an operator. The commands that start with "a" select "a"n object 539including white space, the commands starting with "i" select an "inner" object 540without white space, or just the white space. Thus the "inner" commands 541always select less text than the "a" commands. 542 543Also see `gn` and `gN`, operating on the last search pattern. 544 545 *v_aw* *aw* 546aw "a word", select [count] words (see |word|). 547 Leading or trailing white space is included, but not 548 counted. 549 When used in Visual linewise mode "aw" switches to 550 Visual charwise mode. 551 552 *v_iw* *iw* 553iw "inner word", select [count] words (see |word|). 554 White space between words is counted too. 555 When used in Visual linewise mode "iw" switches to 556 Visual charwise mode. 557 558 *v_aW* *aW* 559aW "a WORD", select [count] WORDs (see |WORD|). 560 Leading or trailing white space is included, but not 561 counted. 562 When used in Visual linewise mode "aW" switches to 563 Visual charwise mode. 564 565 *v_iW* *iW* 566iW "inner WORD", select [count] WORDs (see |WORD|). 567 White space between words is counted too. 568 When used in Visual linewise mode "iW" switches to 569 Visual charwise mode. 570 571 *v_as* *as* 572as "a sentence", select [count] sentences (see 573 |sentence|). 574 When used in Visual mode it is made charwise. 575 576 *v_is* *is* 577is "inner sentence", select [count] sentences (see 578 |sentence|). 579 When used in Visual mode it is made charwise. 580 581 *v_ap* *ap* 582ap "a paragraph", select [count] paragraphs (see 583 |paragraph|). 584 Exception: a blank line (only containing white space) 585 is also a paragraph boundary. 586 When used in Visual mode it is made linewise. 587 588 *v_ip* *ip* 589ip "inner paragraph", select [count] paragraphs (see 590 |paragraph|). 591 Exception: a blank line (only containing white space) 592 is also a paragraph boundary. 593 When used in Visual mode it is made linewise. 594 595 *v_al* *al* 596al "all lines", select the whole buffer. 597 When used in Visual mode it is made linewise. 598 599 *v_il* *il* 600il "inner line", select the current line without leading 601 or trailing white space. Fails on a blank or 602 white-space-only line. 603 When used in Visual mode it selects the line under the 604 cursor and switches to charwise Visual mode. 605 606a] *v_a]* *v_a[* *a]* *a[* 607a[ "a [] block", select [count] '[' ']' blocks. This 608 goes backwards to the [count] unclosed '[', and finds 609 the matching ']'. The enclosed text is selected, 610 including the '[' and ']'. The |cpo-M| option flag 611 is used to handle escaped brackets. 612 When used in Visual mode it is made charwise. 613 614i] *v_i]* *v_i[* *i]* *i[* 615i[ "inner [] block", select [count] '[' ']' blocks. This 616 goes backwards to the [count] unclosed '[', and finds 617 the matching ']'. The enclosed text is selected, 618 excluding the '[' and ']'. It's an error to select an 619 empty inner block like "[]". The |cpo-M| option flag 620 is used to handle escaped brackets. 621 When used in Visual mode it is made charwise. 622 623a) *v_a)* *a)* *a(* 624a( *vab* *v_ab* *v_a(* *ab* 625ab "a block", select [count] blocks, from "[count] [(" to 626 the matching ')', including the '(' and ')' (see 627 |[(|). Does not include white space outside of the 628 parenthesis. The |cpo-M| option flag is used to 629 handle escaped parenthesis. 630 When used in Visual mode it is made charwise. 631 632i) *v_i)* *i)* *i(* 633i( *vib* *v_ib* *v_i(* *ib* 634ib "inner block", select [count] blocks, from "[count] [(" 635 to the matching ')', excluding the '(' and ')' (see 636 |[(|). If the cursor is not inside a () block, then 637 find the next "(". It's an error to select an empty 638 inner block like "()". The |cpo-M| option flag 639 is used to handle escaped parenthesis. 640 When used in Visual mode it is made charwise. 641 642a> *v_a>* *v_a<* *a>* *a<* 643a< "a <> block", select [count] <> blocks, from the 644 [count]'th unmatched '<' backwards to the matching 645 '>', including the '<' and '>'. The |cpo-M| option flag 646 is used to handle escaped '<' and '>'. 647 When used in Visual mode it is made charwise. 648 649i> *v_i>* *v_i<* *i>* *i<* 650i< "inner <> block", select [count] <> blocks, from 651 the [count]'th unmatched '<' backwards to the matching 652 '>', excluding the '<' and '>'. It's an error to 653 select an empty inner block like "<>". The |cpo-M| 654 option flag is used to handle escaped '<' and '>'. 655 When used in Visual mode it is made charwise. 656 657 *v_at* *at* 658at "a tag block", select [count] tag blocks, from the 659 [count]'th unmatched "<aaa>" backwards to the matching 660 "</aaa>", including the "<aaa>" and "</aaa>". 661 See |tag-blocks| about the details. 662 When used in Visual mode it is made charwise. 663 664 *v_it* *it* 665it "inner tag block", select [count] tag blocks, from the 666 [count]'th unmatched "<aaa>" backwards to the matching 667 "</aaa>", excluding the "<aaa>" and "</aaa>". 668 See |tag-blocks| about the details. 669 When used in Visual mode it is made charwise. 670 671a} *v_a}* *a}* *a{* 672a{ *v_aB* *v_a{* *aB* 673aB "a Block", select [count] Blocks, from `[count] [{` to 674 the matching "}", including the "{" and "}" (see 675 |[{|). The |cpo-M| option flag is used to handle 676 escaped braces. 677 When used in Visual mode it is made charwise. 678 679i} *v_i}* *i}* *i{* 680i{ *v_iB* *v_i{* *iB* 681iB "inner Block", select [count] Blocks, from `[count] [{` 682 to the matching "}", excluding the "{" and "}" (see 683 |[{|). It"s an error to select an empty inner block 684 like "{}". The |cpo-M| option flag is used to handle 685 escaped braces. 686 When used in Visual mode it is made charwise. 687 688a" *v_aquote* *aquote* 689a' *v_a'* *a'* 690a` *v_a`* *a`* 691 "a quoted string". Selects the text from the previous 692 quote until the next quote. The 'quoteescape' option 693 is used to skip escaped quotes. 694 Only works within one line. 695 When the cursor starts on a quote, Vim will figure out 696 which quote pairs form a string by searching from the 697 start of the line. 698 Any trailing white space is included, unless there is 699 none, then leading white space is included. 700 When used in Visual mode it is made charwise. 701 Repeating this object in Visual mode another string is 702 included. A count is currently not used. 703 704i" *v_iquote* *iquote* 705i' *v_i'* *i'* 706i` *v_i`* *i`* 707 Like a", a' and a`, but exclude the quotes and 708 repeating won't extend the Visual selection. 709 Special case: With a count of 2 the quotes are 710 included, but no extra white space as with a"/a'/a`. 711 712 *o_object-select* 713When used after an operator: 714For non-block objects: 715 For the "a" commands: The operator applies to the object and the white 716 space after the object. If there is no white space after the object 717 or when the cursor was in the white space before the object, the white 718 space before the object is included. 719 For the "inner" commands: If the cursor was on the object, the 720 operator applies to the object. If the cursor was on white space, the 721 operator applies to the white space. 722For a block object: 723 The operator applies to the block where the cursor is in, or the block 724 on which the cursor is on one of the braces. For the "inner" commands 725 the surrounding braces are excluded. For the "a" commands, the braces 726 are included. 727 728 *v_object-select* 729When used in Visual mode: 730When start and end of the Visual area are the same (just after typing "v"): 731 One object is selected, the same as for using an operator. 732When start and end of the Visual area are not the same: 733 For non-block objects the area is extended by one object or the white 734 space up to the next object, or both for the "a" objects. The 735 direction in which this happens depends on which side of the Visual 736 area the cursor is. For the block objects the block is extended one 737 level outwards. 738 739For illustration, here is a list of delete commands, grouped from small to big 740objects. Note that for a single character and a whole line the existing vi 741movement commands are used. 742 "dl" delete character (alias: "x") |dl| 743 "diw" delete inner word *diw* 744 "daw" delete a word *daw* 745 "diW" delete inner WORD (see |WORD|) *diW* 746 "daW" delete a WORD (see |WORD|) *daW* 747 "dgn" delete the next search pattern match *dgn* 748 "dd" delete one line |dd| 749 "dis" delete inner sentence *dis* 750 "das" delete a sentence *das* 751 "dib" delete inner '(' ')' block *dib* 752 "dab" delete a '(' ')' block *dab* 753 "dip" delete inner paragraph *dip* 754 "dap" delete a paragraph *dap* 755 "diB" delete inner '{' '}' block *diB* 756 "daB" delete a '{' '}' block *daB* 757 758Note the difference between using a movement command and an object. The 759movement command operates from here (cursor position) to where the movement 760takes us. When using an object the whole object is operated upon, no matter 761where on the object the cursor is. For example, compare "dw" and "daw": "dw" 762deletes from the cursor position to the start of the next word, "daw" deletes 763the word under the cursor and the space after or before it. 764 765 766Tag blocks *tag-blocks* 767 768For the "it" and "at" text objects an attempt is done to select blocks between 769matching tags for HTML and XML. But since these are not completely compatible 770there are a few restrictions. 771 772The normal method is to select a <tag> until the matching </tag>. For "at" 773the tags are included, for "it" they are excluded. But when "it" is repeated 774the tags will be included (otherwise nothing would change). Also, "it" used 775on a tag block with no contents will select the leading tag. 776 777"<aaa/>" items are skipped. Case is ignored, also for XML where case does 778matter. 779 780In HTML it is possible to have a tag like <br> or <meta ...> without a 781matching end tag. These are ignored. 782 783The text objects are tolerant about mistakes. Stray end tags are ignored. 784 785------------------------------------------------------------------------------ 786Custom text object *text-object-define* 787 788The following code example shows how to define your own custom text-object. 789Notice how the Visual-mode (xnoremap) mapping is defined as an <expr> mapping 790which sets the |'[| |']| marks, then the Operator-pending (onoremap) mapping 791is implemented using Visual-mode. 792 793>vim 794 " text-object: entire buffer 795 function! s:line_outer_movement(count) abort 796 if empty(getline(1)) && 1 == line('$') 797 return "\<Esc>" 798 endif 799 let [lopen, copen, lclose, cclose] = [1, 1, line('$'), 1] 800 call setpos("'[", [0, lopen, copen, 0]) 801 call setpos("']", [0, lclose, cclose, 0]) 802 return "'[o']" 803 endfunction 804 xnoremap <expr> al <SID>line_outer_movement(v:count1) 805 onoremap <silent> al :normal Val<CR> 806 807 " text-object: line 808 function! s:line_inner_movement(count) abort 809 "TODO: handle count 810 if empty(getline('.')) 811 return "\<Esc>" 812 endif 813 let [lopen, copen, lclose, cclose] = [line('.'), 1, line('.'), col('$')-1] 814 call setpos("'[", [0, lopen, copen, 0]) 815 call setpos("']", [0, lclose, cclose, 0]) 816 return "`[o`]" 817 endfunction 818 xnoremap <expr> il <SID>line_inner_movement(v:count1) 819 onoremap <silent> il :normal vil<CR> 820< 821 822============================================================================== 8237. Marks *mark-motions* *E20* *E78* 824 825Jumping to a mark can be done in two ways: 8261. With ` (backtick): The cursor is positioned at the specified location 827 and the motion is |exclusive|. 8282. With ' (single quote): The cursor is positioned on the first non-blank 829 character in the line of the specified location and 830 the motion is linewise. 831 *mark-view* 8323. Apart from the above if 'jumpoptions' contains "view", they will also try to 833restore the mark view. This is the number of lines between the cursor position 834and the window topline (first buffer line displayed in the window) when it was 835set. 836 837 *m* *mark* *Mark* 838m{a-zA-Z} Set mark {a-zA-Z} at cursor position (does not move 839 the cursor, this is not a motion command). 840 841 *m'* *m`* 842m' or m` Set the previous context mark. This can be jumped to 843 with the "''" or "``" command (does not move the 844 cursor, this is not a motion command). 845 846 *m[* *m]* 847m[ or m] Set the |'[| or |']| mark. Useful when an operator is 848 to be simulated by multiple commands. (does not move 849 the cursor, this is not a motion command). 850 851 *m<* *m>* 852m< or m> Set the |'<| or |'>| mark. Useful to change what the 853 `gv` command selects. (does not move the cursor, this 854 is not a motion command). 855 Note that the Visual mode cannot be set, only the 856 start and end position. 857 858 *:ma* *:mark* *E191* 859:[range]ma[rk] {a-zA-Z'} 860 Set mark {a-zA-Z'} at last line number in [range], 861 column 0. Default is cursor line. 862 863 *:k* 864:[range]k{a-zA-Z'} Same as :mark, but the space before the mark name can 865 be omitted. 866 867 *'* *'a* *`* *`a* 868'{a-z} `{a-z} Jump to the mark {a-z} in the current buffer. 869 870 *'A* *'0* *`A* *`0* 871'{A-Z0-9} `{A-Z0-9} To the mark {A-Z0-9} in the file where it was set (not 872 a motion command when in another file). 873 874 *g'* *g'a* *g`* *g`a* 875g'{mark} g`{mark} 876 Jump to the {mark}, but don't change the jumplist when 877 jumping within the current buffer. Example: > 878 g`" 879< jumps to the last known position in a file. 880 See also |:keepjumps|. 881 882 *:marks* 883:marks List all marks, and |extmarks| namespaces (use ":marks 884 {ns}" to list them). 885 886 The |'(|, |')|, |'{| and |'}| marks are not listed. 887 The first column has number zero. 888 *E283* 889:marks {arg} List the marks that are mentioned in {arg} (not a 890 motion command). For example: > 891 :marks aB 892< to list marks 'a' and 'B'. 893 If {arg} is |extmark| |namespace|, the extmarks for 894 current buffer are listed: > 895 :marks nvim.multicursor 896< 897 *:delm* *:delmarks* 898:delm[arks] {marks} Delete the specified marks. Marks that can be deleted 899 include A-Z and 0-9. You cannot delete the ' mark. 900 They can be specified by giving the list of mark 901 names, or with a range, separated with a dash. Spaces 902 are ignored. Examples: > 903 :delmarks a deletes mark a 904 :delmarks a b 1 deletes marks a, b and 1 905 :delmarks Aa deletes marks A and a 906 :delmarks p-z deletes marks in the range p to z 907 :delmarks ^.[] deletes marks ^ . [ ] 908 :delmarks \" deletes mark " 909< 910 911:delm[arks]! Delete all marks for the current buffer, but not marks 912 A-Z or 0-9. Also clear the |changelist|. 913 914A mark is not visible in any way. It is just a position in the file that is 915remembered. Do not confuse marks with named registers, they are totally 916unrelated. 917 918'a - 'z lowercase marks, valid within one file 919'A - 'Z uppercase marks, also called file marks, valid between files 920'0 - '9 numbered marks, set from |shada| file 921 922Lowercase marks 'a to 'z are remembered as long as the file remains in the 923buffer list. If you remove the file from the buffer list, all its marks are 924lost. If you delete a line that contains a mark, that mark is erased. 925 926Lowercase marks can be used in combination with operators. For example: "d't" 927deletes the lines from the cursor position to mark 't'. Hint: Use mark 't' 928for Top, 'b' for Bottom, etc.. Lowercase marks are restored when using undo 929and redo. 930 931Uppercase marks 'A to 'Z include the file name. You can use them to jump from 932file to file. You can only use an uppercase mark with an operator if the mark 933is in the current file. The line number of the mark remains correct, even if 934you insert/delete lines or edit another file for a moment. When the 'shada' 935option is not empty, uppercase marks are kept in the .shada file. See 936|shada-file-marks|. 937 938Numbered marks '0 to '9 are quite different. They can not be set directly. 939They are only present when using a shada file |shada-file|. Basically '0 940is the location of the cursor when you last exited Vim, '1 the last but one 941time, etc. Use the "r" flag in 'shada' to specify files for which no 942Numbered mark should be stored. See |shada-file-marks|. 943 944 945 *'[* *`[* 946'[ `[ To the first character of the previously changed, 947 or yanked text. Also set when writing the buffer. 948 949 *']* *`]* 950'] `] To the last character of the previously changed or 951 yanked text. Also set when writing the buffer. 952 953After executing an operator the Cursor is put at the beginning of the text 954that was operated upon. After a put command ("p" or "P") the cursor is 955sometimes placed at the first inserted line and sometimes on the last inserted 956character. The four commands above put the cursor at either end. Example: 957After yanking 10 lines you want to go to the last one of them: "10Y']". After 958inserting several lines with the "p" command you want to jump to the lowest 959inserted line: "p']". This also works for text that has been inserted. 960 961Note: After deleting text, the start and end positions are the same, except 962when using blockwise Visual mode. These commands do not work when no change 963was made yet in the current file. 964 965 *'<* *`<* 966'< `< To the first line or character of the last selected 967 Visual area in the current buffer. For block mode it 968 may also be the last character in the first line (to 969 be able to define the block). 970 971 *'>* *`>* 972'> `> To the last line or character of the last selected 973 Visual area in the current buffer. For block mode it 974 may also be the first character of the last line (to 975 be able to define the block). Note that 'selection' 976 applies, the position may be just after the Visual 977 area. 978 979 *''* *``* 980'' `` To the position before the latest jump, or where the 981 last "m'" or "m`" command was given. Not set when the 982 |:keepjumps| command modifier was used. 983 Also see |restore-position|. 984 985 *'quote* *`quote* 986'" `" To the cursor position when last exiting the current 987 buffer. Defaults to the first character of the first 988 line. See |last-position-jump| for how to use this 989 for each opened file. 990 Only one position is remembered per buffer, not one 991 for each window. As long as the buffer is visible in 992 a window the position won't be changed. Mark is also 993 reset when |:wshada| is run. 994 995 *'^* *`^* 996'^ `^ To the position where the cursor was the last time 997 when Insert mode was stopped. This is used by the 998 |gi| command. Not set when the |:keepjumps| command 999 modifier was used. 1000 1001 *'.* *`.* 1002'. `. To the position where the last change was made. The 1003 position is at or near where the change started. 1004 Sometimes a command is executed as several changes, 1005 then the position can be near the end of what the 1006 command changed. For example when inserting a word, 1007 the position will be on the last character. 1008 To jump to older changes use |g;|. 1009 1010 *':* *`:* 1011': In a prompt buffer, the start of the current user 1012 input. Text from this mark until end of buffer will be 1013 submitted when the user submits the prompt. 1014 1015 *'(* *`(* 1016'( `( To the start of the current sentence, like the |(| 1017 command. 1018 1019 *')* *`)* 1020') `) To the end of the current sentence, like the |)| 1021 command. 1022 1023 *'{* *`{* 1024'{ `{ To the start of the current paragraph, like the |{| 1025 command. 1026 1027 *'}* *`}* 1028'} `} To the end of the current paragraph, like the |}| 1029 command. 1030 1031These commands are not marks themselves, but jump to a mark: 1032 1033 *]'* 1034]' [count] times to next line with a lowercase mark below 1035 the cursor, on the first non-blank character in the 1036 line. 1037 1038 *]`* 1039]` [count] times to lowercase mark after the cursor. 1040 1041 *['* 1042[' [count] times to previous line with a lowercase mark 1043 before the cursor, on the first non-blank character in 1044 the line. 1045 1046 *[`* 1047[` [count] times to lowercase mark before the cursor. 1048 1049 1050:loc[kmarks] {command} *:loc* *:lock* *:lockmarks* 1051 Execute {command} without adjusting marks. This is 1052 useful when changing text in a way that the line count 1053 will be the same when the change has completed. 1054 WARNING: When the line count does change, marks below 1055 the change will keep their line number, thus move to 1056 another text line. 1057 These items will not be adjusted for deleted/inserted 1058 lines: 1059 - lower case letter marks 'a - 'z 1060 - upper case letter marks 'A - 'Z 1061 - numbered marks '0 - '9 1062 - last insert position '^ 1063 - last change position '. 1064 - last affected text area '[ and '] 1065 - the Visual area '< and '> 1066 - line numbers in placed signs 1067 - line numbers in quickfix positions 1068 - positions in the |jumplist| 1069 - positions in the |tagstack| 1070 These items will still be adjusted: 1071 - previous context mark '' 1072 - the cursor position 1073 - the view of a window on a buffer 1074 - folds 1075 - diffs 1076 1077:kee[pmarks] {command} *:kee* *:keep* *:keepmarks* 1078 Currently only has effect for the filter command 1079 |:range!|: 1080 - When the number of lines after filtering is equal to 1081 or larger than before, all marks are kept at the 1082 same line number. 1083 - When the number of lines decreases, the marks in the 1084 lines that disappeared are deleted. 1085 In any case the marks below the filtered text have 1086 their line numbers adjusted, thus stick to the text, 1087 as usual. 1088 When the 'R' flag is missing from 'cpoptions' this has 1089 the same effect as using ":keepmarks". 1090 1091 *:keepj* *:keepjumps* 1092:keepj[umps] {command} 1093 Moving around in {command} does not change the |''|, 1094 |'.| and |'^| marks, the |jumplist| or the 1095 |changelist|. 1096 Useful when making a change or inserting text 1097 automatically and the user doesn't want to go to this 1098 position. E.g., when updating a "Last change" 1099 timestamp in the first line: > 1100 1101 :let lnum = line(".") 1102 :keepjumps normal gg 1103 :call SetLastChange() 1104 :keepjumps exe "normal " .. lnum .. "G" 1105< 1106 Note that ":keepjumps" must be used for every command. 1107 When invoking a function the commands in that function 1108 can still change the jumplist. Also, for 1109 `:keepjumps exe 'command '` the "command" won't keep 1110 jumps. Instead use: `:exe 'keepjumps command'` 1111 1112============================================================================== 11138. Jumps *jump-motions* 1114 1115A "jump" is a command that normally moves the cursor several lines away. If 1116you make the cursor "jump" the position of the cursor before the jump is 1117remembered. You can return to that position with the "''" and "``" commands, 1118unless the line containing that position was changed or deleted. The 1119following commands are "jump" commands: "'", "`", "G", "/", "?", "n", "N", 1120"%", "(", ")", "[[", "]]", "{", "}", ":s", ":tag", "L", "M", "H" and the 1121commands that start editing a new file. 1122 1123 *CTRL-O* 1124CTRL-O Go to [count] Older cursor position in jump list 1125 (not a motion command). 1126 1127<Tab> or *CTRL-I* *<Tab>* 1128CTRL-I Go to [count] newer cursor position in jump list 1129 (not a motion command). 1130 1131 NOTE: In the GUI and in a terminal supporting 1132 |tui-modifyOtherKeys| or |tui-csiu|, CTRL-I can be 1133 mapped separately from <Tab>, on the condition that 1134 both keys are mapped, otherwise the mapping applies to 1135 both. Except in tmux: https://github.com/tmux/tmux/issues/2705 1136 1137 *:ju* *:jumps* 1138:ju[mps] Print the jump list (not a motion command). 1139 1140 *:cle* *:clearjumps* 1141:cle[arjumps] Clear the jump list of the current window. 1142 1143 *jumplist* 1144Jumps are remembered in a jump list. With the CTRL-O and CTRL-I command you 1145can go to cursor positions before older jumps, and back again. Thus you can 1146move up and down the list. There is a separate jump list for each window. 1147The maximum number of entries is fixed at 100. 1148 1149For example, after three jump commands you have this jump list: > 1150 1151 jump line col file/text 1152 3 1 0 some text 1153 2 70 0 another line 1154 1 1154 23 end. 1155 > 1156< 1157The "file/text" column shows the file name, or the text at the jump if it is 1158in the current file (an indent is removed and a long line is truncated to fit 1159in the window). 1160 1161The marker ">" indicates the current position in the jumplist. It may not be 1162shown when filtering the |:jumps| command using |:filter| 1163 1164You are currently in line 1167. If you then use the CTRL-O command, the 1165cursor is put in line 1154. This results in: > 1166 1167 jump line col file/text 1168 2 1 0 some text 1169 1 70 0 another line 1170 > 0 1154 23 end. 1171 1 1167 0 foo bar 1172< 1173The pointer will be set at the last used jump position. The next CTRL-O 1174command will use the entry above it, the next CTRL-I command will use the 1175entry below it. If the pointer is below the last entry, this indicates that 1176you did not use a CTRL-I or CTRL-O before. In this case the CTRL-O command 1177will cause the cursor position to be added to the jump list, so you can get 1178back to the position before the CTRL-O. In this case this is line 1167. 1179 1180With more CTRL-O commands you will go to lines 70 and 1. If you use CTRL-I 1181you can go back to 1154 and 1167 again. Note that the number in the "jump" 1182column indicates the count for the CTRL-O or CTRL-I command that takes you to 1183this position. 1184 1185If you use a jump command, the current line number is inserted at the end of 1186the jump list. If the same line was already in the jump list, it is removed. 1187The result is that when repeating CTRL-O you will get back to old positions 1188only once. 1189 1190When the |:keepjumps| command modifier is used, jumps are not stored in the 1191jumplist. Jumps are also not stored in other cases, e.g., in a |:global| 1192command. You can explicitly add a jump by setting the ' mark with "m'". Note 1193that calling setpos() does not do this. 1194 1195After the CTRL-O command that got you into line 1154 you could give another 1196jump command (e.g., "G"). The jump list would then become: > 1197 1198 jump line col file/text 1199 4 1 0 some text 1200 3 70 0 another line 1201 2 1167 0 foo bar 1202 1 1154 23 end. 1203 > 1204< 1205The line numbers will be adjusted for deleted and inserted lines. This fails 1206if you stop editing a file without writing, like with ":n!". 1207 1208When you split a window, the jumplist will be copied to the new window. 1209 1210If you have included the ' item in the 'shada' option the jumplist will be 1211stored in the ShaDa file and restored when starting Vim. 1212 1213 *jumplist-stack* 1214When 'jumpoptions' option includes "stack", the jumplist behaves like the tag 1215stack. When jumping to a new location from the middle of the jumplist, the 1216locations after the current position will be discarded. With this option set 1217you can move through a tree of jump locations. When going back up a branch 1218and then down another branch, CTRL-O still takes you further up the tree. 1219 1220Given a jumplist like the following in which CTRL-O has been used to move back 1221three times to location X: > 1222 1223 jump line col file/text 1224 2 1260 8 mark.c <-- location X-2 1225 1 685 0 eval.c <-- location X-1 1226 > 0 462 36 eval.c <-- location X 1227 1 479 39 eval.c 1228 2 213 2 mark.c 1229 3 181 0 mark.c 1230< 1231jumping to (new) location Y results in the locations after the current 1232locations being removed: > 1233 1234 jump line col file/text 1235 3 1260 8 mark.c <-- location X-2 1236 2 685 0 eval.c <-- location X-1 1237 1 462 36 eval.c <-- location X 1238 > 1239< 1240Then, when yet another location Z is jumped to, the new location Y appears 1241directly after location X in the jumplist and location X remains in the same 1242position relative to the locations (X-1, X-2, etc., ...) that had been before 1243it prior to the original jump from X to Y: > 1244 1245 jump line col file/text 1246 4 1260 8 mark.c <-- location X-2 1247 3 685 0 eval.c <-- location X-1 1248 2 462 36 eval.c <-- location X 1249 1 100 0 buffer.c <-- location Y 1250 > 1251< 1252CHANGE LIST JUMPS *changelist* *change-list-jumps* *E664* 1253 1254When making a change the cursor position is remembered. One position is 1255remembered for every change that can be undone, unless it is close to a 1256previous change. Two commands can be used to jump to positions of changes, 1257also those that have been undone: 1258 1259 *g;* *E662* 1260g; Go to [count] older position in change list. 1261 If [count] is larger than the number of older change 1262 positions go to the oldest change. 1263 If there is no older change an error message is given. 1264 (not a motion command) 1265 1266 *g,* *E663* 1267g, Go to [count] newer position in change list. 1268 Just like |g;| but in the opposite direction. 1269 (not a motion command) 1270 1271When using a count you jump as far back or forward as possible. Thus you can 1272use "999g;" to go to the first change for which the position is still 1273remembered. The number of entries in the change list is fixed and is the same 1274as for the |jumplist|. 1275 1276When two undo-able changes are in the same line and at a column position less 1277than 'textwidth' apart only the last one is remembered. This avoids that a 1278sequence of small changes in a line, for example "xxxxx", adds many positions 1279to the change list. When 'textwidth' is zero 'wrapmargin' is used. When that 1280also isn't set a fixed number of 79 is used. Detail: For the computations 1281bytes are used, not characters, to avoid a speed penalty (this only matters 1282for multibyte encodings). 1283 1284Note that when text has been inserted or deleted the cursor position might be 1285a bit different from the position of the change. Especially when lines have 1286been deleted. 1287 1288When the `:keepjumps` command modifier is used the position of a change is not 1289remembered. 1290 1291 *:changes* 1292:changes Print the change list. A ">" character indicates the 1293 current position. Just after a change it is below the 1294 newest entry, indicating that `g;` takes you to the 1295 newest entry position. The first column indicates the 1296 count needed to take you to this position. Example: 1297 1298 change line col text ~ 1299 3 9 8 bla bla bla 1300 2 11 57 foo is a bar 1301 1 14 54 the latest changed line 1302 > 1303 1304 The `3g;` command takes you to line 9. Then the 1305 output of `:changes` is: 1306 1307 change line col text ~ 1308 > 0 9 8 bla bla bla 1309 1 11 57 foo is a bar 1310 2 14 54 the latest changed line 1311 1312 Now you can use "g," to go to line 11 and "2g," to go 1313 to line 14. 1314 1315============================================================================== 13169. Various motions *various-motions* 1317 1318 *%* 1319% Find the next item in this line after or under the 1320 cursor and jump to its match. |inclusive| motion. 1321 Items can be: 1322 ([{}]) parenthesis or (curly/square) brackets 1323 (this can be changed with the 1324 'matchpairs' option) 1325 `/* */` start or end of C-style comment 1326 #if, #ifdef, #else, #elif, #endif 1327 C preprocessor conditionals (when the 1328 cursor is on the # or no ([{ 1329 is following) 1330 For other items the matchit plugin can be used, see 1331 |matchit|. This plugin also helps to skip matches in 1332 comments. 1333 1334 When 'cpoptions' contains "M" |cpo-M| backslashes 1335 before parens and braces are ignored. Without "M" the 1336 number of backslashes matters: an even number doesn't 1337 match with an odd number. Thus in "( \) )" and "\( ( 1338 \)" the first and last parenthesis match. 1339 1340 When the '%' character is not present in 'cpoptions' 1341 |cpo-%|, parens and braces inside double quotes are 1342 ignored, unless the number of parens/braces in a line 1343 is uneven and this line and the previous one does not 1344 end in a backslash. '(', '{', '[', ']', '}' and ')' 1345 are also ignored (parens and braces inside single 1346 quotes). Note that this works fine for C, but not for 1347 Perl, where single quotes are used for strings. 1348 1349 When in addition 'comments' defines C-style "//" or 1350 "/*" comments, parens and braces inside such comments 1351 are skipped, like the |=| operator does. This does 1352 not happen when the cursor is inside a comment, so a 1353 match inside that comment can still be found. 1354 Otherwise you can use the |matchit| plugin or put 1355 quotes around matches. 1356 1357 No count is allowed, {count}% jumps to a line {count} 1358 percentage down the file |N%|. Using '%' on 1359 #if/#else/#endif makes the movement linewise. 1360 1361 *[(* 1362[( Go to [count] previous unmatched '('. 1363 |exclusive| motion. 1364 1365 *[{* 1366[{ Go to [count] previous unmatched '{'. 1367 |exclusive| motion. 1368 1369 *])* 1370]) Go to [count] next unmatched ')'. 1371 |exclusive| motion. 1372 1373 *]}* 1374]} Go to [count] next unmatched '}'. 1375 |exclusive| motion. 1376 1377The above four commands can be used to go to the start or end of the current 1378code block. It is like doing "%" on the "(", ")", "{" or "}" at the other 1379end of the code block, but you can do this from anywhere in the code block. 1380Very useful for C programs. Example: When standing on "case x:", `[{` will 1381bring you back to the switch statement. 1382 1383 *]m* 1384]m Go to [count] next start of a method (for Java or 1385 similar structured language). When not before the 1386 start of a method, jump to the start or end of the 1387 class. |exclusive| motion. 1388 *]M* 1389]M Go to [count] next end of a method (for Java or 1390 similar structured language). When not before the end 1391 of a method, jump to the start or end of the class. 1392 |exclusive| motion. 1393 *[m* 1394[m Go to [count] previous start of a method (for Java or 1395 similar structured language). When not after the 1396 start of a method, jump to the start or end of the 1397 class. When no '{' is found before the cursor this is 1398 an error. |exclusive| motion. 1399 *[M* 1400[M Go to [count] previous end of a method (for Java or 1401 similar structured language). When not after the 1402 end of a method, jump to the start or end of the 1403 class. When no '}' is found before the cursor this is 1404 an error. |exclusive| motion. 1405 1406The above four commands assume that the file contains a class with methods. 1407The class definition is surrounded in '{' and '}'. Each method in the class 1408is also surrounded with '{' and '}'. This applies to the Java language. The 1409file looks like this: > 1410 1411 // comment 1412 class foo { 1413 int method_one() { 1414 body_one(); 1415 } 1416 int method_two() { 1417 body_two(); 1418 } 1419 } 1420 1421[To try this out copy the text and put it in a new buffer, the help text above 1422confuses the jump commands] 1423 1424Starting with the cursor on "body_two()", using "[m" will jump to the '{' at 1425the start of "method_two()" (obviously this is much more useful when the 1426method is long!). Using "2[m" will jump to the start of "method_one()". 1427Using "3[m" will jump to the start of the class. 1428 1429 *[#* 1430[# Go to [count] previous unmatched "#if" or "#else". 1431 |exclusive| motion. 1432 1433 *]#* 1434]# Go to [count] next unmatched "#else" or "#endif". 1435 |exclusive| motion. 1436 1437These two commands work in C programs that contain #if/#else/#endif 1438constructs. It brings you to the start or end of the #if/#else/#endif where 1439the current line is included. You can then use "%" to go to the matching 1440line. 1441 1442 *[star* *[/* 1443[* or [/ Go to [count] previous start of a C comment "/*". 1444 |exclusive| motion. 1445 1446 *]star* *]/* 1447]* or ]/ Go to [count] next end of a C comment "*/". 1448 |exclusive| motion. 1449 1450 1451 *H* 1452H To line [count] from top (Home) of window (default: 1453 first line on the window) on the first non-blank 1454 character |linewise|. See also 'startofline' option. 1455 Cursor is adjusted for 'scrolloff' option, unless an 1456 operator is pending, in which case the text may 1457 scroll. E.g. "yH" yanks from the first visible line 1458 until the cursor line (inclusive). 1459 1460 *M* 1461M To Middle line of window, on the first non-blank 1462 character |linewise|. See also 'startofline' option. 1463 1464 *L* 1465L To line [count] from bottom of window (default: Last 1466 line on the window) on the first non-blank character 1467 |linewise|. See also 'startofline' option. 1468 Cursor is adjusted for 'scrolloff' option, unless an 1469 operator is pending, in which case the text may 1470 scroll. E.g. "yL" yanks from the cursor to the last 1471 visible line. 1472 1473<LeftMouse> Moves to the position on the screen where the mouse 1474 click is |exclusive|. See also |<LeftMouse>|. If the 1475 position is in a status line, that window is made the 1476 active window and the cursor is not moved. 1477 1478 vim:tw=78:ts=8:noet:ft=help:norl: