Yochem van Rosmalen | 2090405 | 2025-06-03 20:54:33 +0200 | [diff] [blame] | 1 | *usr_02.txt* For Vim version 9.1. Last change: 2025 Jun 03 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2 | |
| 3 | VIM USER MANUAL - by Bram Moolenaar |
| 4 | |
| 5 | The first steps in Vim |
| 6 | |
| 7 | |
| 8 | This chapter provides just enough information to edit a file with Vim. Not |
| 9 | well or fast, but you can edit. Take some time to practice with these |
| 10 | commands, they form the base for what follows. |
| 11 | |
| 12 | |02.1| Running Vim for the First Time |
| 13 | |02.2| Inserting text |
| 14 | |02.3| Moving around |
| 15 | |02.4| Deleting characters |
| 16 | |02.5| Undo and Redo |
| 17 | |02.6| Other editing commands |
| 18 | |02.7| Getting out |
| 19 | |02.8| Finding help |
| 20 | |
| 21 | Next chapter: |usr_03.txt| Moving around |
| 22 | Previous chapter: |usr_01.txt| About the manuals |
| 23 | Table of contents: |usr_toc.txt| |
| 24 | |
| 25 | ============================================================================== |
| 26 | *02.1* Running Vim for the First Time |
| 27 | |
| 28 | To start Vim, enter this command: > |
| 29 | |
| 30 | gvim file.txt |
| 31 | |
| 32 | In UNIX you can type this at any command prompt. If you are running Microsoft |
Bram Moolenaar | 5666fcd | 2019-12-26 14:35:26 +0100 | [diff] [blame] | 33 | Windows, open a Command Prompt and enter the command. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 34 | In either case, Vim starts editing a file called file.txt. Because this |
h-east | 8ee0e0b | 2024-10-05 16:44:27 +0200 | [diff] [blame] | 35 | is a new file, you get a blank window. This is what your screen will look |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 36 | like: |
| 37 | |
| 38 | +---------------------------------------+ |
| 39 | |# | |
| 40 | |~ | |
| 41 | |~ | |
| 42 | |~ | |
| 43 | |~ | |
| 44 | |"file.txt" [New file] | |
| 45 | +---------------------------------------+ |
Bram Moolenaar | 130cbfc | 2021-04-07 21:07:20 +0200 | [diff] [blame] | 46 | ('#' is the cursor position.) |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 47 | |
| 48 | The tilde (~) lines indicate lines not in the file. In other words, when Vim |
| 49 | runs out of file to display, it displays tilde lines. At the bottom of the |
| 50 | screen, a message line indicates the file is named file.txt and shows that you |
| 51 | are creating a new file. The message information is temporary and other |
| 52 | information overwrites it. |
| 53 | |
| 54 | |
| 55 | THE VIM COMMAND |
| 56 | |
| 57 | The gvim command causes the editor to create a new window for editing. If you |
| 58 | use this command: > |
| 59 | |
| 60 | vim file.txt |
| 61 | |
| 62 | the editing occurs inside your command window. In other words, if you are |
| 63 | running inside an xterm, the editor uses your xterm window. If you are using |
Bram Moolenaar | 5666fcd | 2019-12-26 14:35:26 +0100 | [diff] [blame] | 64 | an MS-Windows command prompt window, the editing occurs inside this window. |
| 65 | The text in the window will look the same for both versions, but with gvim you |
| 66 | have extra features, like a menu bar. More about that later. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 67 | |
| 68 | ============================================================================== |
| 69 | *02.2* Inserting text |
| 70 | |
| 71 | The Vim editor is a modal editor. That means that the editor behaves |
| 72 | differently, depending on which mode you are in. The two basic modes are |
| 73 | called Normal mode and Insert mode. In Normal mode the characters you type |
| 74 | are commands. In Insert mode the characters are inserted as text. |
| 75 | Since you have just started Vim it will be in Normal mode. To start Insert |
| 76 | mode you type the "i" command (i for Insert). Then you can enter |
| 77 | the text. It will be inserted into the file. Do not worry if you make |
| 78 | mistakes; you can correct them later. To enter the following programmer's |
| 79 | limerick, this is what you type: > |
| 80 | |
| 81 | iA very intelligent turtle |
| 82 | Found programming UNIX a hurdle |
| 83 | |
| 84 | After typing "turtle" you press the <Enter> key to start a new line. Finally |
| 85 | you press the <Esc> key to stop Insert mode and go back to Normal mode. You |
| 86 | now have two lines of text in your Vim window: |
| 87 | |
| 88 | +---------------------------------------+ |
| 89 | |A very intelligent turtle | |
| 90 | |Found programming UNIX a hurdle | |
| 91 | |~ | |
| 92 | |~ | |
| 93 | | | |
| 94 | +---------------------------------------+ |
| 95 | |
| 96 | |
| 97 | WHAT IS THE MODE? |
| 98 | |
| 99 | To be able to see what mode you are in, type this command: > |
| 100 | |
| 101 | :set showmode |
| 102 | |
| 103 | You will notice that when typing the colon Vim moves the cursor to the last |
| 104 | line of the window. That's where you type colon commands (commands that start |
| 105 | with a colon). Finish this command by pressing the <Enter> key (all commands |
| 106 | that start with a colon are finished this way). |
| 107 | Now, if you type the "i" command Vim will display --INSERT-- at the bottom |
| 108 | of the window. This indicates you are in Insert mode. |
| 109 | |
| 110 | +---------------------------------------+ |
| 111 | |A very intelligent turtle | |
| 112 | |Found programming UNIX a hurdle | |
| 113 | |~ | |
| 114 | |~ | |
| 115 | |-- INSERT -- | |
| 116 | +---------------------------------------+ |
| 117 | |
| 118 | If you press <Esc> to go back to Normal mode the last line will be made blank. |
| 119 | |
| 120 | |
| 121 | GETTING OUT OF TROUBLE |
| 122 | |
| 123 | One of the problems for Vim novices is mode confusion, which is caused by |
| 124 | forgetting which mode you are in or by accidentally typing a command that |
| 125 | switches modes. To get back to Normal mode, no matter what mode you are in, |
| 126 | press the <Esc> key. Sometimes you have to press it twice. If Vim beeps back |
| 127 | at you, you already are in Normal mode. |
| 128 | |
| 129 | ============================================================================== |
| 130 | *02.3* Moving around |
| 131 | |
| 132 | After you return to Normal mode, you can move around by using these keys: |
| 133 | |
| 134 | h left *hjkl* |
| 135 | j down |
| 136 | k up |
| 137 | l right |
| 138 | |
| 139 | At first, it may appear that these commands were chosen at random. After all, |
| 140 | who ever heard of using l for right? But actually, there is a very good |
| 141 | reason for these choices: Moving the cursor is the most common thing you do in |
| 142 | an editor, and these keys are on the home row of your right hand. In other |
| 143 | words, these commands are placed where you can type them the fastest |
| 144 | (especially when you type with ten fingers). |
| 145 | |
| 146 | Note: |
| 147 | You can also move the cursor by using the arrow keys. If you do, |
| 148 | however, you greatly slow down your editing because to press the arrow |
| 149 | keys, you must move your hand from the text keys to the arrow keys. |
| 150 | Considering that you might be doing it hundreds of times an hour, this |
| 151 | can take a significant amount of time. |
| 152 | Also, there are keyboards which do not have arrow keys, or which |
| 153 | locate them in unusual places; therefore, knowing the use of the hjkl |
| 154 | keys helps in those situations. |
| 155 | |
| 156 | One way to remember these commands is that h is on the left, l is on the |
| 157 | right and j points down. In a picture: > |
| 158 | |
| 159 | k |
| 160 | h l |
| 161 | j |
| 162 | |
| 163 | The best way to learn these commands is by using them. Use the "i" command to |
| 164 | insert some more lines of text. Then use the hjkl keys to move around and |
| 165 | insert a word somewhere. Don't forget to press <Esc> to go back to Normal |
| 166 | mode. The |vimtutor| is also a nice way to learn by doing. |
| 167 | |
| 168 | For Japanese users, Hiroshi Iwatani suggested using this: |
| 169 | |
| 170 | Komsomolsk |
| 171 | ^ |
| 172 | | |
| 173 | Huan Ho <--- ---> Los Angeles |
| 174 | (Yellow river) | |
| 175 | v |
| 176 | Java (the island, not the programming language) |
| 177 | |
| 178 | ============================================================================== |
| 179 | *02.4* Deleting characters |
| 180 | |
| 181 | To delete a character, move the cursor over it and type "x". (This is a |
| 182 | throwback to the old days of the typewriter, when you deleted things by typing |
| 183 | xxxx over them.) Move the cursor to the beginning of the first line, for |
| 184 | example, and type xxxxxxx (seven x's) to delete "A very ". The result should |
| 185 | look like this: |
| 186 | |
| 187 | +---------------------------------------+ |
| 188 | |intelligent turtle | |
| 189 | |Found programming UNIX a hurdle | |
| 190 | |~ | |
| 191 | |~ | |
| 192 | | | |
| 193 | +---------------------------------------+ |
| 194 | |
| 195 | Now you can insert new text, for example by typing: > |
| 196 | |
| 197 | iA young <Esc> |
| 198 | |
| 199 | This begins an insert (the i), inserts the words "A young", and then exits |
| 200 | insert mode (the final <Esc>). The result: |
| 201 | |
| 202 | +---------------------------------------+ |
| 203 | |A young intelligent turtle | |
| 204 | |Found programming UNIX a hurdle | |
| 205 | |~ | |
| 206 | |~ | |
| 207 | | | |
| 208 | +---------------------------------------+ |
| 209 | |
| 210 | |
| 211 | DELETING A LINE |
| 212 | |
| 213 | To delete a whole line use the "dd" command. The following line will |
| 214 | then move up to fill the gap: |
| 215 | |
| 216 | +---------------------------------------+ |
| 217 | |Found programming UNIX a hurdle | |
| 218 | |~ | |
| 219 | |~ | |
| 220 | |~ | |
| 221 | | | |
| 222 | +---------------------------------------+ |
| 223 | |
| 224 | |
| 225 | DELETING A LINE BREAK |
| 226 | |
| 227 | In Vim you can join two lines together, which means that the line break |
| 228 | between them is deleted. The "J" command does this. |
| 229 | Take these two lines: |
| 230 | |
| 231 | A young intelligent ~ |
| 232 | turtle ~ |
| 233 | |
| 234 | Move the cursor to the first line and press "J": |
| 235 | |
| 236 | A young intelligent turtle ~ |
| 237 | |
| 238 | ============================================================================== |
| 239 | *02.5* Undo and Redo |
| 240 | |
| 241 | Suppose you delete too much. Well, you can type it in again, but an easier |
| 242 | way exists. The "u" command undoes the last edit. Take a look at this in |
| 243 | action: After using "dd" to delete the first line, "u" brings it back. |
| 244 | Another one: Move the cursor to the A in the first line: |
| 245 | |
| 246 | A young intelligent turtle ~ |
| 247 | |
| 248 | Now type xxxxxxx to delete "A young". The result is as follows: |
| 249 | |
| 250 | intelligent turtle ~ |
| 251 | |
| 252 | Type "u" to undo the last delete. That delete removed the g, so the undo |
| 253 | restores the character. |
| 254 | |
| 255 | g intelligent turtle ~ |
| 256 | |
Bram Moolenaar | 0c0734d | 2019-11-26 21:44:46 +0100 | [diff] [blame] | 257 | The next "u" command restores the next-to-last character deleted: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 258 | |
| 259 | ng intelligent turtle ~ |
| 260 | |
Bram Moolenaar | 0c0734d | 2019-11-26 21:44:46 +0100 | [diff] [blame] | 261 | The next "u" command gives you the u, and so on: |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 262 | |
| 263 | ung intelligent turtle ~ |
| 264 | oung intelligent turtle ~ |
| 265 | young intelligent turtle ~ |
| 266 | young intelligent turtle ~ |
| 267 | A young intelligent turtle ~ |
| 268 | |
| 269 | Note: |
| 270 | If you type "u" twice, and the result is that you get the same text |
| 271 | back, you have Vim configured to work Vi compatible. Look here to fix |
| 272 | this: |not-compatible|. |
| 273 | This text assumes you work "The Vim Way". You might prefer to use |
| 274 | the good old Vi way, but you will have to watch out for small |
| 275 | differences in the text then. |
| 276 | |
| 277 | |
| 278 | REDO |
| 279 | |
| 280 | If you undo too many times, you can press CTRL-R (redo) to reverse the |
| 281 | preceding command. In other words, it undoes the undo. To see this in |
| 282 | action, press CTRL-R twice. The character A and the space after it disappear: |
| 283 | |
| 284 | young intelligent turtle ~ |
| 285 | |
| 286 | There's a special version of the undo command, the "U" (undo line) command. |
| 287 | The undo line command undoes all the changes made on the last line that was |
| 288 | edited. Typing this command twice cancels the preceding "U". |
| 289 | |
| 290 | A very intelligent turtle ~ |
| 291 | xxxx Delete very |
| 292 | |
| 293 | A intelligent turtle ~ |
| 294 | xxxxxx Delete turtle |
| 295 | |
| 296 | A intelligent ~ |
| 297 | Restore line with "U" |
| 298 | A very intelligent turtle ~ |
| 299 | Undo "U" with "u" |
| 300 | A intelligent ~ |
| 301 | |
| 302 | The "U" command is a change by itself, which the "u" command undoes and CTRL-R |
| 303 | redoes. This might be a bit confusing. Don't worry, with "u" and CTRL-R you |
Bram Moolenaar | 730cde9 | 2010-06-27 05:18:54 +0200 | [diff] [blame] | 304 | can go to any of the situations you had. More about that in section |32.2|. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 305 | |
| 306 | ============================================================================== |
| 307 | *02.6* Other editing commands |
| 308 | |
| 309 | Vim has a large number of commands to change the text. See |Q_in| and below. |
| 310 | Here are a few often used ones. |
| 311 | |
| 312 | |
| 313 | APPENDING |
| 314 | |
| 315 | The "i" command inserts a character before the character under the cursor. |
| 316 | That works fine; but what happens if you want to add stuff to the end of the |
| 317 | line? For that you need to insert text after the cursor. This is done with |
| 318 | the "a" (append) command. |
| 319 | For example, to change the line |
| 320 | |
| 321 | and that's not saying much for the turtle. ~ |
| 322 | to |
| 323 | and that's not saying much for the turtle!!! ~ |
| 324 | |
h-east | 8ee0e0b | 2024-10-05 16:44:27 +0200 | [diff] [blame] | 325 | move the cursor over to the dot at the end of the line. Then type "x" to |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 326 | delete the period. The cursor is now positioned at the end of the line on the |
| 327 | e in turtle. Now type > |
| 328 | |
| 329 | a!!!<Esc> |
| 330 | |
| 331 | to append three exclamation points after the e in turtle: |
| 332 | |
| 333 | and that's not saying much for the turtle!!! ~ |
| 334 | |
| 335 | |
| 336 | OPENING UP A NEW LINE |
| 337 | |
| 338 | The "o" command creates a new, empty line below the cursor and puts Vim in |
| 339 | Insert mode. Then you can type the text for the new line. |
| 340 | Suppose the cursor is somewhere in the first of these two lines: |
| 341 | |
| 342 | A very intelligent turtle ~ |
| 343 | Found programming UNIX a hurdle ~ |
| 344 | |
| 345 | If you now use the "o" command and type new text: > |
| 346 | |
| 347 | oThat liked using Vim<Esc> |
| 348 | |
| 349 | The result is: |
| 350 | |
| 351 | A very intelligent turtle ~ |
| 352 | That liked using Vim ~ |
| 353 | Found programming UNIX a hurdle ~ |
| 354 | |
| 355 | The "O" command (uppercase) opens a line above the cursor. |
| 356 | |
| 357 | |
| 358 | USING A COUNT |
| 359 | |
| 360 | Suppose you want to move up nine lines. You can type "kkkkkkkkk" or you can |
| 361 | enter the command "9k". In fact, you can precede many commands with a number. |
| 362 | Earlier in this chapter, for instance, you added three exclamation points to |
| 363 | the end of a line by typing "a!!!<Esc>". Another way to do this is to use the |
| 364 | command "3a!<Esc>". The count of 3 tells the command that follows to triple |
| 365 | its effect. Similarly, to delete three characters, use the command "3x". The |
| 366 | count always comes before the command it applies to. |
| 367 | |
| 368 | ============================================================================== |
| 369 | *02.7* Getting out |
| 370 | |
| 371 | To exit, use the "ZZ" command. This command writes the file and exits. |
| 372 | |
| 373 | Note: |
| 374 | Unlike many other editors, Vim does not automatically make a backup |
| 375 | file. If you type "ZZ", your changes are committed and there's no |
| 376 | turning back. You can configure the Vim editor to produce backup |
Bram Moolenaar | 0c0734d | 2019-11-26 21:44:46 +0100 | [diff] [blame] | 377 | files; see |07.4|. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 378 | |
| 379 | |
| 380 | DISCARDING CHANGES |
| 381 | |
| 382 | Sometimes you will make a sequence of changes and suddenly realize you were |
| 383 | better off before you started. Not to worry; Vim has a |
| 384 | quit-and-throw-things-away command. It is: > |
| 385 | |
| 386 | :q! |
| 387 | |
| 388 | Don't forget to press <Enter> to finish the command. |
| 389 | |
| 390 | For those of you interested in the details, the three parts of this command |
| 391 | are the colon (:), which enters Command-line mode; the q command, which tells |
| 392 | the editor to quit; and the override command modifier (!). |
| 393 | The override command modifier is needed because Vim is reluctant to throw |
| 394 | away changes. If you were to just type ":q", Vim would display an error |
| 395 | message and refuse to exit: |
| 396 | |
| 397 | E37: No write since last change (use ! to override) ~ |
| 398 | |
| 399 | By specifying the override, you are in effect telling Vim, "I know that what |
Bram Moolenaar | 0c0734d | 2019-11-26 21:44:46 +0100 | [diff] [blame] | 400 | I'm doing looks stupid, but I really want to do this." |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 401 | |
| 402 | If you want to continue editing with Vim: The ":e!" command reloads the |
| 403 | original version of the file. |
| 404 | |
| 405 | ============================================================================== |
| 406 | *02.8* Finding help |
| 407 | |
| 408 | Everything you always wanted to know can be found in the Vim help files. |
| 409 | Don't be afraid to ask! |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 410 | |
| 411 | If you know what you are looking for, it is usually easier to search for it |
| 412 | using the help system, instead of using Google. Because the subjects follow |
| 413 | a certain style guide. |
| 414 | |
| 415 | Also the help has the advantage of belonging to your particular Vim version. |
| 416 | You won't see help for commands added later. These would not work for you. |
| 417 | |
| 418 | To get generic help use this command: > |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 419 | |
| 420 | :help |
| 421 | |
| 422 | You could also use the first function key <F1>. If your keyboard has a <Help> |
| 423 | key it might work as well. |
| 424 | If you don't supply a subject, ":help" displays the general help window. |
| 425 | The creators of Vim did something very clever (or very lazy) with the help |
| 426 | system: They made the help window a normal editing window. You can use all |
| 427 | the normal Vim commands to move through the help information. Therefore h, j, |
| 428 | k, and l move left, down, up and right. |
| 429 | To get out of the help window, use the same command you use to get out of |
| 430 | the editor: "ZZ". This will only close the help window, not exit Vim. |
| 431 | |
| 432 | As you read the help text, you will notice some text enclosed in vertical bars |
| 433 | (for example, |help|). This indicates a hyperlink. If you position the |
| 434 | cursor anywhere between the bars and press CTRL-] (jump to tag), the help |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 435 | system takes you to the indicated subject. (For reasons not discussed here, |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 436 | the Vim terminology for a hyperlink is tag. So CTRL-] jumps to the location |
| 437 | of the tag given by the word under the cursor.) |
| 438 | After a few jumps, you might want to go back. CTRL-T (pop tag) takes you |
| 439 | back to the preceding position. CTRL-O (jump to older position) also works |
| 440 | nicely here. |
Yochem van Rosmalen | 2090405 | 2025-06-03 20:54:33 +0200 | [diff] [blame] | 441 | At the top of the help screen, there is the notation "*help.txt*". This |
| 442 | name between "*" characters is used by the help system to define a tag |
| 443 | (hyperlink destination). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 444 | See |29.1| for details about using tags. |
| 445 | |
| 446 | To get help on a given subject, use the following command: > |
| 447 | |
| 448 | :help {subject} |
| 449 | |
| 450 | To get help on the "x" command, for example, enter the following: > |
| 451 | |
| 452 | :help x |
| 453 | |
| 454 | To find out how to delete text, use this command: > |
| 455 | |
| 456 | :help deleting |
| 457 | |
| 458 | To get a complete index of all Vim commands, use the following command: > |
| 459 | |
| 460 | :help index |
| 461 | |
| 462 | When you need to get help for a control character command (for example, |
| 463 | CTRL-A), you need to spell it with the prefix "CTRL-". > |
| 464 | |
| 465 | :help CTRL-A |
| 466 | |
| 467 | The Vim editor has many different modes. By default, the help system displays |
| 468 | the normal-mode commands. For example, the following command displays help |
| 469 | for the normal-mode CTRL-H command: > |
| 470 | |
| 471 | :help CTRL-H |
| 472 | |
| 473 | To identify other modes, use a mode prefix. If you want the help for the |
| 474 | insert-mode version of a command, use "i_". For CTRL-H this gives you the |
| 475 | following command: > |
| 476 | |
| 477 | :help i_CTRL-H |
| 478 | |
| 479 | When you start the Vim editor, you can use several command-line arguments. |
| 480 | These all begin with a dash (-). To find what the -t argument does, for |
| 481 | example, use the command: > |
| 482 | |
| 483 | :help -t |
| 484 | |
| 485 | The Vim editor has a number of options that enable you to configure and |
| 486 | customize the editor. If you want help for an option, you need to enclose it |
| 487 | in single quotation marks. To find out what the 'number' option does, for |
| 488 | example, use the following command: > |
| 489 | |
| 490 | :help 'number' |
| 491 | |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 492 | The table with all mode prefixes can be found below: |help-summary|. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 493 | |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 494 | Special keys are enclosed in angle brackets. To find help on the up-arrow key |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 495 | in Insert mode, for instance, use this command: > |
| 496 | |
| 497 | :help i_<Up> |
| 498 | |
| 499 | If you see an error message that you don't understand, for example: |
| 500 | |
| 501 | E37: No write since last change (use ! to override) ~ |
| 502 | |
| 503 | You can use the error ID at the start to find help about it: > |
| 504 | |
| 505 | :help E37 |
| 506 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 507 | |
Bram Moolenaar | 938ae28 | 2023-02-20 20:44:55 +0000 | [diff] [blame] | 508 | Summary: *help-summary* > |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 509 | |
| 510 | 1) Use Ctrl-D after typing a topic and let Vim show all available topics. |
| 511 | Or press Tab to complete: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 512 | :help some<Tab> |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 513 | < More information on how to use the help: > |
| 514 | :help helphelp |
| 515 | |
| 516 | 2) Follow the links in bars to related help. You can go from the detailed |
| 517 | help to the user documentation, which describes certain commands more from |
| 518 | a user perspective and less detailed. E.g. after: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 519 | :help pattern.txt |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 520 | < You can see the user guide topics |03.9| and |usr_27.txt| in the |
| 521 | introduction. |
| 522 | |
| 523 | 3) Options are enclosed in single apostrophes. To go to the help topic for the |
| 524 | list option: > |
| 525 | :help 'list' |
| 526 | < If you only know you are looking for a certain option, you can also do: > |
| 527 | :help options.txt |
| 528 | < to open the help page which describes all option handling and then search |
| 529 | using regular expressions, e.g. textwidth. |
| 530 | Certain options have their own namespace, e.g.: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 531 | :help cpo-<letter> |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 532 | < for the corresponding flag of the 'cpoptions' settings, substitute <letter> |
| 533 | by a specific flag, e.g.: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 534 | :help cpo-; |
Bram Moolenaar | 4c29502 | 2021-05-02 17:19:11 +0200 | [diff] [blame] | 535 | < And for the 'guioptions' flags: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 536 | :help go-<letter> |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 537 | |
h-east | 8ee0e0b | 2024-10-05 16:44:27 +0200 | [diff] [blame] | 538 | 4) Normal mode commands do not have a prefix. To go to the help page for the |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 539 | "gt" command: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 540 | :help gt |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 541 | |
| 542 | 5) Insert mode commands start with i_. Help for deleting a word: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 543 | :help i_CTRL-W |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 544 | |
| 545 | 6) Visual mode commands start with v_. Help for jumping to the other side of |
| 546 | the Visual area: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 547 | :help v_o |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 548 | |
| 549 | 7) Command line editing and arguments start with c_. Help for using the |
| 550 | command argument %: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 551 | :help c_% |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 552 | |
Bram Moolenaar | 0c0734d | 2019-11-26 21:44:46 +0100 | [diff] [blame] | 553 | 8) Ex-commands always start with ":", so to go to the ":s" command help: > |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 554 | :help :s |
| 555 | |
Bram Moolenaar | 036986f | 2017-03-16 17:41:02 +0100 | [diff] [blame] | 556 | 9) Commands specifically for debugging start with ">". To go to the help |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 557 | for the "cont" debug command: > |
| 558 | :help >cont |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 559 | |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 560 | 10) Key combinations. They usually start with a single letter indicating |
| 561 | the mode for which they can be used. E.g.: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 562 | :help i_CTRL-X |
Bram Moolenaar | 0c0734d | 2019-11-26 21:44:46 +0100 | [diff] [blame] | 563 | < takes you to the family of CTRL-X commands for insert mode which can be |
| 564 | used to auto-complete different things. Note, that certain keys will |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 565 | always be written the same, e.g. Control will always be CTRL. |
| 566 | For normal mode commands there is no prefix and the topic is available at |
| 567 | :h CTRL-<Letter>. E.g. > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 568 | :help CTRL-W |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 569 | < In contrast > |
| 570 | :help c_CTRL-R |
Bram Moolenaar | 0c0734d | 2019-11-26 21:44:46 +0100 | [diff] [blame] | 571 | < will describe what the CTRL-R does when entering commands in the Command |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 572 | line and > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 573 | :help v_CTRL-A |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 574 | < talks about incrementing numbers in visual mode and > |
| 575 | :help g_CTRL-A |
Bram Moolenaar | 0c0734d | 2019-11-26 21:44:46 +0100 | [diff] [blame] | 576 | < talks about the "g<C-A>" command (e.g. you have to press "g" then |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 577 | <CTRL-A>). Here the "g" stands for the normal command "g" which always |
Bram Moolenaar | 0c0734d | 2019-11-26 21:44:46 +0100 | [diff] [blame] | 578 | expects a second key before doing something similar to the commands |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 579 | starting with "z". |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 580 | |
| 581 | 11) Regexp items always start with /. So to get help for the "\+" quantifier |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 582 | in Vim regexes: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 583 | :help /\+ |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 584 | < If you need to know everything about regular expressions, start reading |
| 585 | at: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 586 | :help pattern.txt |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 587 | |
h-east | 8ee0e0b | 2024-10-05 16:44:27 +0200 | [diff] [blame] | 588 | 12) Registers always start with "quote". To find out about the special ":" |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 589 | register: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 590 | :help quote: |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 591 | |
Bram Moolenaar | b544f3c | 2017-02-23 19:03:28 +0100 | [diff] [blame] | 592 | 13) Vim script is available at > |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 593 | :help eval.txt |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 594 | < Certain aspects of the language are available at :h expr-X where "X" is a |
| 595 | single letter. E.g. > |
| 596 | :help expr-! |
| 597 | < will take you to the topic describing the "!" (Not) operator for Vim |
| 598 | script. |
| 599 | Also important is > |
| 600 | :help function-list |
| 601 | < to find a short description of all functions available. Help topics for |
| 602 | Vim script functions always include the "()", so: > |
| 603 | :help append() |
| 604 | < talks about the append Vim script function rather than how to append text |
| 605 | in the current buffer. |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 606 | |
h-east | 8ee0e0b | 2024-10-05 16:44:27 +0200 | [diff] [blame] | 607 | 14) Mappings are talked about in the help page :h |map.txt|. Use > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 608 | :help mapmode-i |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 609 | < to find out about the |:imap| command. Also use :map-topic |
| 610 | to find out about certain subtopics particular for mappings. e.g: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 611 | :help :map-local |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 612 | < for buffer-local mappings or > |
| 613 | :help map-bar |
| 614 | < for how the '|' is handled in mappings. |
| 615 | |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 616 | 15) Command definitions are talked about :h command-topic, so use > |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 617 | :help command-bar |
| 618 | < to find out about the '!' argument for custom commands. |
| 619 | |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 620 | 16) Window management commands always start with CTRL-W, so you find the |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 621 | corresponding help at :h CTRL-W_letter. E.g. > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 622 | :help CTRL-W_p |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 623 | < for moving the previous accessed window. You can also access > |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 624 | :help windows.txt |
| 625 | < and read your way through if you are looking for window handling |
| 626 | commands. |
| 627 | |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 628 | 17) Use |:helpgrep| to search in all help pages (and also of any installed |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 629 | plugins). See |:helpgrep| for how to use it. |
| 630 | To search for a topic: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 631 | :helpgrep topic |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 632 | < This takes you to the first match. To go to the next one: > |
| 633 | :cnext |
| 634 | < All matches are available in the quickfix window which can be opened |
| 635 | with: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 636 | :copen |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 637 | < Move around to the match you like and press Enter to jump to that help. |
| 638 | |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 639 | 18) The user manual. This describes help topics for beginners in a rather |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 640 | friendly way. Start at |usr_toc.txt| to find the table of content (as you |
| 641 | might have guessed): > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 642 | :help usr_toc.txt |
h-east | 8ee0e0b | 2024-10-05 16:44:27 +0200 | [diff] [blame] | 643 | < Skim over the contents to find interesting topics. The "Digraphs" and |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 644 | "Entering special characters" items are in chapter 24, so to go to that |
| 645 | particular help page: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 646 | :help usr_24.txt |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 647 | < Also if you want to access a certain chapter in the help, the chapter |
| 648 | number can be accessed directly like this: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 649 | :help 10.1 |
Bram Moolenaar | 0c0734d | 2019-11-26 21:44:46 +0100 | [diff] [blame] | 650 | < which goes to chapter 10.1 in |usr_10.txt| and talks about recording |
| 651 | macros. |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 652 | |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 653 | 19) Highlighting groups. Always start with hl-groupname. E.g. > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 654 | :help hl-WarningMsg |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 655 | < talks about the WarningMsg highlighting group. |
| 656 | |
Bram Moolenaar | 0c0734d | 2019-11-26 21:44:46 +0100 | [diff] [blame] | 657 | 20) Syntax highlighting is namespaced to :syn-topic. E.g. > |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 658 | :help :syn-conceal |
Bram Moolenaar | 0c0734d | 2019-11-26 21:44:46 +0100 | [diff] [blame] | 659 | < talks about the conceal argument for the ":syn" command. |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 660 | |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 661 | 21) Quickfix commands usually start with :c while location list commands |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 662 | usually start with :l |
| 663 | |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 664 | 22) Autocommand events can be found by their name: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 665 | :help BufWinLeave |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 666 | < To see all possible events: > |
Bram Moolenaar | 214641f | 2017-03-05 17:04:09 +0100 | [diff] [blame] | 667 | :help autocommand-events |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 668 | |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 669 | 23) Command-line switches always start with "-". So for the help of the -f |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 670 | command switch of Vim use: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 671 | :help -f |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 672 | |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 673 | 24) Optional features always start with "+". To find out about the |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 674 | conceal feature use: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 675 | :help +conceal |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 676 | |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 677 | 25) Documentation for included filetype specific functionality is usually |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 678 | available in the form ft-<filetype>-<functionality>. So > |
| 679 | :help ft-c-syntax |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 680 | < talks about the C syntax file and the option it provides. Sometimes, |
| 681 | additional sections for omni completion > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 682 | :help ft-php-omni |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 683 | < or filetype plugins > |
| 684 | :help ft-tex-plugin |
| 685 | < are available. |
| 686 | |
Bram Moolenaar | 85084ef | 2016-01-17 22:26:33 +0100 | [diff] [blame] | 687 | 26) Error and Warning codes can be looked up directly in the help. So > |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 688 | :help E297 |
| 689 | < takes you exactly to the description of the swap error message and > |
| 690 | :help W10 |
| 691 | < talks about the warning "Changing a readonly file". |
Bram Moolenaar | 0c0734d | 2019-11-26 21:44:46 +0100 | [diff] [blame] | 692 | Sometimes, however, those error codes are not described, but rather are |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 693 | listed at the Vim command that usually causes this. So: > |
Bram Moolenaar | 1d9215b | 2020-01-25 13:27:42 +0100 | [diff] [blame] | 694 | :help E128 |
Bram Moolenaar | 345efa0 | 2016-01-15 20:57:49 +0100 | [diff] [blame] | 695 | < takes you to the |:function| command |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 696 | |
Christian Brabandt | a234a46 | 2025-01-16 19:12:48 +0100 | [diff] [blame] | 697 | 27) Documentation for packages distributed with Vim have the form |
| 698 | package-<name>. So > |
Christian Brabandt | 9598a63 | 2025-01-11 10:14:24 +0100 | [diff] [blame] | 699 | :help package-comment |
| 700 | < |
Hirohito Higashi | 195fcc9 | 2025-02-01 10:26:58 +0100 | [diff] [blame] | 701 | will bring you to the help section for the included comment plugin and how |
| 702 | to enable it. |
Christian Brabandt | 9598a63 | 2025-01-11 10:14:24 +0100 | [diff] [blame] | 703 | |
Bram Moolenaar | 9964e46 | 2007-05-05 17:54:07 +0000 | [diff] [blame] | 704 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 705 | ============================================================================== |
| 706 | |
| 707 | Next chapter: |usr_03.txt| Moving around |
| 708 | |
Bram Moolenaar | d473c8c | 2018-08-11 18:00:22 +0200 | [diff] [blame] | 709 | Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl: |