Christian Brabandt | a9b95c3 | 2025-06-22 20:32:15 +0200 | [diff] [blame] | 1 | *usr_24.txt* For Vim version 9.1. Last change: 2025 Jun 22 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 2 | |
| 3 | VIM USER MANUAL - by Bram Moolenaar |
| 4 | |
| 5 | Inserting quickly |
| 6 | |
| 7 | |
| 8 | When entering text, Vim offers various ways to reduce the number of keystrokes |
| 9 | and avoid typing mistakes. Use Insert mode completion to repeat previously |
| 10 | typed words. Abbreviate long words to short ones. Type characters that |
| 11 | aren't on your keyboard. |
| 12 | |
| 13 | |24.1| Making corrections |
| 14 | |24.2| Showing matches |
| 15 | |24.3| Completion |
| 16 | |24.4| Repeating an insert |
| 17 | |24.5| Copying from another line |
| 18 | |24.6| Inserting a register |
| 19 | |24.7| Abbreviations |
| 20 | |24.8| Entering special characters |
| 21 | |24.9| Digraphs |
| 22 | |24.10| Normal mode commands |
| 23 | |
| 24 | Next chapter: |usr_25.txt| Editing formatted text |
| 25 | Previous chapter: |usr_23.txt| Editing other files |
| 26 | Table of contents: |usr_toc.txt| |
| 27 | |
| 28 | ============================================================================== |
| 29 | *24.1* Making corrections |
| 30 | |
| 31 | The <BS> key was already mentioned. It deletes the character just before the |
| 32 | cursor. The <Del> key does the same for the character under (after) the |
| 33 | cursor. |
| 34 | When you typed a whole word wrong, use CTRL-W: |
| 35 | |
| 36 | The horse had fallen to the sky ~ |
| 37 | CTRL-W |
| 38 | The horse had fallen to the ~ |
| 39 | |
| 40 | If you really messed up a line and want to start over, use CTRL-U to delete |
| 41 | it. This keeps the text after the cursor and the indent. Only the text from |
| 42 | the first non-blank to the cursor is deleted. With the cursor on the "f" of |
| 43 | "fallen" in the next line pressing CTRL-U does this: |
| 44 | |
| 45 | The horse had fallen to the ~ |
| 46 | CTRL-U |
| 47 | fallen to the ~ |
| 48 | |
| 49 | When you spot a mistake a few words back, you need to move the cursor there to |
| 50 | correct it. For example, you typed this: |
| 51 | |
| 52 | The horse had follen to the ground ~ |
| 53 | |
| 54 | You need to change "follen" to "fallen". With the cursor at the end, you |
| 55 | would type this to correct it: > |
| 56 | |
| 57 | <Esc>4blraA |
| 58 | |
| 59 | < get out of Insert mode <Esc> |
| 60 | four words back 4b |
| 61 | move on top of the "o" l |
| 62 | replace with "a" ra |
| 63 | restart Insert mode A |
| 64 | |
| 65 | Another way to do this: > |
| 66 | |
| 67 | <C-Left><C-Left><C-Left><C-Left><Right><Del>a<End> |
| 68 | |
| 69 | < four words back <C-Left><C-Left><C-Left><C-Left> |
| 70 | move on top of the "o" <Right> |
| 71 | delete the "o" <Del> |
| 72 | insert an "a" a |
| 73 | go to end of the line <End> |
| 74 | |
| 75 | This uses special keys to move around, while remaining in Insert mode. This |
| 76 | resembles what you would do in a modeless editor. It's easier to remember, |
| 77 | but takes more time (you have to move your hand from the letters to the cursor |
| 78 | keys, and the <End> key is hard to press without looking at the keyboard). |
| 79 | These special keys are most useful when writing a mapping that doesn't |
| 80 | leave Insert mode. The extra typing doesn't matter then. |
| 81 | An overview of the keys you can use in Insert mode: |
| 82 | |
| 83 | <C-Home> to start of the file |
| 84 | <PageUp> a whole screenful up |
| 85 | <Home> to start of line |
| 86 | <S-Left> one word left |
| 87 | <C-Left> one word left |
| 88 | <S-Right> one word right |
| 89 | <C-Right> one word right |
| 90 | <End> to end of the line |
| 91 | <PageDown> a whole screenful down |
| 92 | <C-End> to end of the file |
| 93 | |
| 94 | There are a few more, see |ins-special-special|. |
| 95 | |
| 96 | ============================================================================== |
| 97 | *24.2* Showing matches |
| 98 | |
| 99 | When you type a ) it would be nice to see with which ( it matches. To make |
| 100 | Vim do that use this command: > |
| 101 | |
| 102 | :set showmatch |
| 103 | |
| 104 | When you now type a text like "(example)", as soon as you type the ) Vim will |
| 105 | briefly move the cursor to the matching (, keep it there for half a second, |
| 106 | and move back to where you were typing. |
Bram Moolenaar | 402d2fe | 2005-04-15 21:00:38 +0000 | [diff] [blame] | 107 | In case there is no matching (, Vim will beep. Then you know that you |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 108 | might have forgotten the ( somewhere, or typed a ) too many. |
| 109 | The match will also be shown for [] and {} pairs. You don't have to wait |
| 110 | with typing the next character, as soon as Vim sees it the cursor will move |
| 111 | back and inserting continues as before. |
| 112 | You can change the time Vim waits with the 'matchtime' option. For |
| 113 | example, to make Vim wait one and a half second: > |
| 114 | |
| 115 | :set matchtime=15 |
| 116 | |
| 117 | The time is specified in tenths of a second. |
| 118 | |
| 119 | ============================================================================== |
| 120 | *24.3* Completion |
| 121 | |
| 122 | Vim can automatically complete words on insertion. You type the first part of |
| 123 | a word, press CTRL-P, and Vim guesses the rest. |
| 124 | Suppose, for example, that you are creating a C program and want to type in |
| 125 | the following: |
| 126 | |
| 127 | total = ch_array[0] + ch_array[1] + ch_array[2]; ~ |
| 128 | |
| 129 | You start by entering the following: |
| 130 | |
| 131 | total = ch_array[0] + ch_ ~ |
| 132 | |
| 133 | At this point, you tell Vim to complete the word using the command CTRL-P. |
| 134 | Vim searches for a word that starts with what's in front of the cursor. In |
| 135 | this case, it is "ch_", which matches with the word ch_array. So typing |
| 136 | CTRL-P gives you the following: |
| 137 | |
| 138 | total = ch_array[0] + ch_array ~ |
| 139 | |
| 140 | After a little more typing, you get this (ending in a space): |
| 141 | |
| 142 | total = ch_array[0] + ch_array[1] + ~ |
| 143 | |
| 144 | If you now type CTRL-P Vim will search again for a word that completes the |
| 145 | word before the cursor. Since there is nothing in front of the cursor, it |
| 146 | finds the first word backwards, which is "ch_array". Typing CTRL-P again |
| 147 | gives you the next word that matches, in this case "total". A third CTRL-P |
| 148 | searches further back. If there is nothing else, it causes the editor to run |
| 149 | out of words, so it returns to the original text, which is nothing. A fourth |
| 150 | CTRL-P causes the editor to start over again with "ch_array". |
| 151 | |
| 152 | To search forward, use CTRL-N. Since the search wraps around the end of the |
| 153 | file, CTRL-N and CTRL-P will find the same matches, but in a different |
| 154 | sequence. Hint: CTRL-N is Next-match and CTRL-P is Previous-match. |
| 155 | |
| 156 | The Vim editor goes through a lot of effort to find words to complete. By |
| 157 | default, it searches the following places: |
| 158 | |
| 159 | 1. Current file |
| 160 | 2. Files in other windows |
| 161 | 3. Other loaded files (hidden buffers) |
| 162 | 4. Files which are not loaded (inactive buffers) |
| 163 | 5. Tag files |
| 164 | 6. All files #included by the current file |
| 165 | |
| 166 | |
| 167 | OPTIONS |
| 168 | |
| 169 | You can customize the search order with the 'complete' option. |
| 170 | |
| 171 | The 'ignorecase' option is used. When it is set, case differences are ignored |
| 172 | when searching for matches. |
| 173 | |
| 174 | A special option for completion is 'infercase'. This is useful to find |
| 175 | matches while ignoring case ('ignorecase' must be set) but still using the |
| 176 | case of the word typed so far. Thus if you type "For" and Vim finds a match |
| 177 | "fortunately", it will result in "Fortunately". |
| 178 | |
| 179 | |
| 180 | COMPLETING SPECIFIC ITEMS |
| 181 | |
| 182 | If you know what you are looking for, you can use these commands to complete |
| 183 | with a certain type of item: |
| 184 | |
| 185 | CTRL-X CTRL-F file names |
| 186 | CTRL-X CTRL-L whole lines |
| 187 | CTRL-X CTRL-D macro definitions (also in included files) |
| 188 | CTRL-X CTRL-I current and included files |
| 189 | CTRL-X CTRL-K words from a dictionary |
glepnir | d5fdfa5 | 2025-06-02 19:45:41 +0200 | [diff] [blame] | 190 | CTRL-X CTRL-R contents from registers |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 191 | CTRL-X CTRL-T words from a thesaurus |
| 192 | CTRL-X CTRL-] tags |
| 193 | CTRL-X CTRL-V Vim command line |
| 194 | |
| 195 | After each of them CTRL-N can be used to find the next match, CTRL-P to find |
| 196 | the previous match. |
| 197 | More information for each of these commands here: |ins-completion|. |
| 198 | |
| 199 | |
| 200 | COMPLETING FILE NAMES |
| 201 | |
| 202 | Let's take CTRL-X CTRL-F as an example. This will find file names. It scans |
| 203 | the current directory for files and displays each one that matches the word in |
| 204 | front of the cursor. |
| 205 | Suppose, for example, that you have the following files in the current |
| 206 | directory: |
| 207 | |
| 208 | main.c sub_count.c sub_done.c sub_exit.c |
| 209 | |
| 210 | Now enter Insert mode and start typing: |
| 211 | |
| 212 | The exit code is in the file sub ~ |
| 213 | |
| 214 | At this point, you enter the command CTRL-X CTRL-F. Vim now completes the |
| 215 | current word "sub" by looking at the files in the current directory. The |
| 216 | first match is sub_count.c. This is not the one you want, so you match the |
| 217 | next file by typing CTRL-N. This match is sub_done.c. Typing CTRL-N again |
| 218 | takes you to sub_exit.c. The results: |
| 219 | |
| 220 | The exit code is in the file sub_exit.c ~ |
| 221 | |
| 222 | If the file name starts with / (Unix) or C:\ (MS-Windows) you can find all |
| 223 | files in the file system. For example, type "/u" and CTRL-X CTRL-F. This |
| 224 | will match "/usr" (this is on Unix): |
| 225 | |
| 226 | the file is found in /usr/ ~ |
| 227 | |
| 228 | If you now press CTRL-N you go back to "/u". Instead, to accept the "/usr/" |
| 229 | and go one directory level deeper, use CTRL-X CTRL-F again: |
| 230 | |
| 231 | the file is found in /usr/X11R6/ ~ |
| 232 | |
| 233 | The results depend on what is found in your file system, of course. The |
| 234 | matches are sorted alphabetically. |
| 235 | |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 236 | |
| 237 | COMPLETING IN SOURCE CODE |
| 238 | |
| 239 | Source code files are well structured. That makes it possible to do |
| 240 | completion in an intelligent way. In Vim this is called Omni completion. In |
| 241 | some other editors it's called intellisense, but that is a trademark. |
| 242 | |
| 243 | The key to Omni completion is CTRL-X CTRL-O. Obviously the O stands for Omni |
| 244 | here, so that you can remember it easier. Let's use an example for editing C |
| 245 | source: |
| 246 | |
| 247 | { ~ |
| 248 | struct foo *p; ~ |
| 249 | p-> ~ |
| 250 | |
| 251 | The cursor is after "p->". Now type CTRL-X CTRL-O. Vim will offer you a list |
| 252 | of alternatives, which are the items that "struct foo" contains. That is |
| 253 | quite different from using CTRL-P, which would complete any word, while only |
| 254 | members of "struct foo" are valid here. |
| 255 | |
Bram Moolenaar | 313b723 | 2007-05-05 17:56:55 +0000 | [diff] [blame] | 256 | For Omni completion to work you may need to do some setup. At least make sure |
| 257 | filetype plugins are enabled. Your vimrc file should contain a line like |
| 258 | this: > |
| 259 | filetype plugin on |
| 260 | Or: > |
| 261 | filetype plugin indent on |
| 262 | |
| 263 | For C code you need to create a tags file and set the 'tags' option. That is |
| 264 | explained |ft-c-omni|. For other filetypes you may need to do something |
| 265 | similar, look below |compl-omni-filetypes|. It only works for specific |
| 266 | filetypes. Check the value of the 'omnifunc' option to find out if it would |
| 267 | work. |
Bram Moolenaar | 910f66f | 2006-04-05 20:41:53 +0000 | [diff] [blame] | 268 | |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 269 | ============================================================================== |
| 270 | *24.4* Repeating an insert |
| 271 | |
| 272 | If you press CTRL-A, the editor inserts the text you typed the last time you |
| 273 | were in Insert mode. |
| 274 | Assume, for example, that you have a file that begins with the following: |
| 275 | |
| 276 | "file.h" ~ |
| 277 | /* Main program begins */ ~ |
| 278 | |
| 279 | You edit this file by inserting "#include " at the beginning of the first |
| 280 | line: |
| 281 | |
| 282 | #include "file.h" ~ |
| 283 | /* Main program begins */ ~ |
| 284 | |
| 285 | You go down to the beginning of the next line using the commands "j^". You |
| 286 | now start to insert a new "#include" line. So you type: > |
| 287 | |
| 288 | i CTRL-A |
| 289 | |
| 290 | The result is as follows: |
| 291 | |
| 292 | #include "file.h" ~ |
| 293 | #include /* Main program begins */ ~ |
| 294 | |
| 295 | The "#include " was inserted because CTRL-A inserts the text of the previous |
| 296 | insert. Now you type "main.h"<Enter> to finish the line: |
| 297 | |
| 298 | |
| 299 | #include "file.h" ~ |
| 300 | #include "main.h" ~ |
| 301 | /* Main program begins */ ~ |
| 302 | |
| 303 | The CTRL-@ command does a CTRL-A and then exits Insert mode. That's a quick |
| 304 | way of doing exactly the same insertion again. |
| 305 | |
| 306 | ============================================================================== |
| 307 | *24.5* Copying from another line |
| 308 | |
| 309 | The CTRL-Y command inserts the character above the cursor. This is useful |
| 310 | when you are duplicating a previous line. For example, you have this line of |
| 311 | C code: |
| 312 | |
| 313 | b_array[i]->s_next = a_array[i]->s_next; ~ |
| 314 | |
| 315 | Now you need to type the same line, but with "s_prev" instead of "s_next". |
| 316 | Start the new line, and press CTRL-Y 14 times, until you are at the "n" of |
| 317 | "next": |
| 318 | |
| 319 | b_array[i]->s_next = a_array[i]->s_next; ~ |
| 320 | b_array[i]->s_ ~ |
| 321 | |
| 322 | Now you type "prev": |
| 323 | |
| 324 | b_array[i]->s_next = a_array[i]->s_next; ~ |
| 325 | b_array[i]->s_prev ~ |
| 326 | |
| 327 | Continue pressing CTRL-Y until the following "next": |
| 328 | |
| 329 | b_array[i]->s_next = a_array[i]->s_next; ~ |
| 330 | b_array[i]->s_prev = a_array[i]->s_ ~ |
| 331 | |
| 332 | Now type "prev;" to finish it off. |
| 333 | |
| 334 | The CTRL-E command acts like CTRL-Y except it inserts the character below the |
| 335 | cursor. |
| 336 | |
| 337 | ============================================================================== |
| 338 | *24.6* Inserting a register |
| 339 | |
| 340 | The command CTRL-R {register} inserts the contents of the register. This is |
| 341 | useful to avoid having to type a long word. For example, you need to type |
| 342 | this: |
| 343 | |
| 344 | r = VeryLongFunction(a) + VeryLongFunction(b) + VeryLongFunction(c) ~ |
| 345 | |
| 346 | The function name is defined in a different file. Edit that file and move the |
| 347 | cursor on top of the function name there, and yank it into register v: > |
| 348 | |
| 349 | "vyiw |
| 350 | |
| 351 | "v is the register specification, "yiw" is yank-inner-word. Now edit the file |
| 352 | where the new line is to be inserted, and type the first letters: |
| 353 | |
| 354 | r = ~ |
| 355 | |
| 356 | Now use CTRL-R v to insert the function name: |
| 357 | |
| 358 | r = VeryLongFunction ~ |
| 359 | |
| 360 | You continue to type the characters in between the function name, and use |
| 361 | CTRL-R v two times more. |
| 362 | You could have done the same with completion. Using a register is useful |
| 363 | when there are many words that start with the same characters. |
| 364 | |
| 365 | If the register contains characters such as <BS> or other special characters, |
| 366 | they are interpreted as if they had been typed from the keyboard. If you do |
| 367 | not want this to happen (you really want the <BS> to be inserted in the text), |
| 368 | use the command CTRL-R CTRL-R {register}. |
| 369 | |
| 370 | ============================================================================== |
| 371 | *24.7* Abbreviations |
| 372 | |
| 373 | An abbreviation is a short word that takes the place of a long one. For |
| 374 | example, "ad" stands for "advertisement". Vim enables you to type an |
| 375 | abbreviation and then will automatically expand it for you. |
| 376 | To tell Vim to expand "ad" into "advertisement" every time you insert it, |
| 377 | use the following command: > |
| 378 | |
| 379 | :iabbrev ad advertisement |
| 380 | |
| 381 | Now, when you type "ad", the whole word "advertisement" will be inserted into |
| 382 | the text. This is triggered by typing a character that can't be part of a |
| 383 | word, for example a space: |
| 384 | |
| 385 | What Is Entered What You See |
| 386 | I saw the a I saw the a ~ |
| 387 | I saw the ad I saw the ad ~ |
| 388 | I saw the ad<Space> I saw the advertisement<Space> ~ |
| 389 | |
| 390 | The expansion doesn't happen when typing just "ad". That allows you to type a |
| 391 | word like "add", which will not get expanded. Only whole words are checked |
| 392 | for abbreviations. |
| 393 | |
| 394 | |
| 395 | ABBREVIATING SEVERAL WORDS |
| 396 | |
| 397 | It is possible to define an abbreviation that results in multiple words. For |
| 398 | example, to define "JB" as "Jack Benny", use the following command: > |
| 399 | |
| 400 | :iabbrev JB Jack Benny |
| 401 | |
| 402 | As a programmer, I use two rather unusual abbreviations: > |
| 403 | |
| 404 | :iabbrev #b /**************************************** |
| 405 | :iabbrev #e <Space>****************************************/ |
| 406 | |
| 407 | These are used for creating boxed comments. The comment starts with #b, which |
| 408 | draws the top line. I then type the comment text and use #e to draw the |
| 409 | bottom line. |
| 410 | Notice that the #e abbreviation begins with a space. In other words, the |
| 411 | first two characters are space-star. Usually Vim ignores spaces between the |
| 412 | abbreviation and the expansion. To avoid that problem, I spell space as seven |
| 413 | characters: <, S, p, a, c, e, >. |
| 414 | |
| 415 | Note: |
| 416 | ":iabbrev" is a long word to type. ":iab" works just as well. |
| 417 | That's abbreviating the abbreviate command! |
| 418 | |
| 419 | |
| 420 | FIXING TYPING MISTAKES |
| 421 | |
| 422 | It's very common to make the same typing mistake every time. For example, |
| 423 | typing "teh" instead of "the". You can fix this with an abbreviation: > |
| 424 | |
| 425 | :abbreviate teh the |
| 426 | |
| 427 | You can add a whole list of these. Add one each time you discover a common |
| 428 | mistake. |
| 429 | |
| 430 | |
| 431 | LISTING ABBREVIATIONS |
| 432 | |
| 433 | The ":abbreviate" command lists the abbreviations: |
| 434 | |
| 435 | :abbreviate |
| 436 | i #e ****************************************/ |
| 437 | i #b /**************************************** |
| 438 | i JB Jack Benny |
| 439 | i ad advertisement |
| 440 | ! teh the |
| 441 | |
| 442 | The "i" in the first column indicates Insert mode. These abbreviations are |
| 443 | only active in Insert mode. Other possible characters are: |
| 444 | |
| 445 | c Command-line mode :cabbrev |
| 446 | ! both Insert and Command-line mode :abbreviate |
| 447 | |
| 448 | Since abbreviations are not often useful in Command-line mode, you will mostly |
| 449 | use the ":iabbrev" command. That avoids, for example, that "ad" gets expanded |
| 450 | when typing a command like: > |
| 451 | |
| 452 | :edit ad |
| 453 | |
| 454 | |
| 455 | DELETING ABBREVIATIONS |
| 456 | |
| 457 | To get rid of an abbreviation, use the ":unabbreviate" command. Suppose you |
| 458 | have the following abbreviation: > |
| 459 | |
| 460 | :abbreviate @f fresh |
| 461 | |
| 462 | You can remove it with this command: > |
| 463 | |
| 464 | :unabbreviate @f |
| 465 | |
| 466 | While you type this, you will notice that @f is expanded to "fresh". Don't |
| 467 | worry about this, Vim understands it anyway (except when you have an |
| 468 | abbreviation for "fresh", but that's very unlikely). |
| 469 | To remove all the abbreviations: > |
| 470 | |
| 471 | :abclear |
| 472 | |
| 473 | ":unabbreviate" and ":abclear" also come in the variants for Insert mode |
| 474 | (":iunabbreviate and ":iabclear") and Command-line mode (":cunabbreviate" and |
| 475 | ":cabclear"). |
| 476 | |
| 477 | |
| 478 | REMAPPING ABBREVIATIONS |
| 479 | |
| 480 | There is one thing to watch out for when defining an abbreviation: The |
| 481 | resulting string should not be mapped. For example: > |
| 482 | |
| 483 | :abbreviate @a adder |
| 484 | :imap dd disk-door |
| 485 | |
| 486 | When you now type @a, you will get "adisk-doorer". That's not what you want. |
| 487 | To avoid this, use the ":noreabbrev" command. It does the same as |
| 488 | ":abbreviate", but avoids that the resulting string is used for mappings: > |
| 489 | |
| 490 | :noreabbrev @a adder |
| 491 | |
| 492 | Fortunately, it's unlikely that the result of an abbreviation is mapped. |
| 493 | |
| 494 | ============================================================================== |
| 495 | *24.8* Entering special characters |
| 496 | |
| 497 | The CTRL-V command is used to insert the next character literally. In other |
| 498 | words, any special meaning the character has, it will be ignored. For |
| 499 | example: > |
| 500 | |
| 501 | CTRL-V <Esc> |
| 502 | |
| 503 | Inserts an escape character. Thus you don't leave Insert mode. (Don't type |
| 504 | the space after CTRL-V, it's only to make this easier to read). |
| 505 | |
| 506 | Note: |
| 507 | On MS-Windows CTRL-V is used to paste text. Use CTRL-Q instead of |
| 508 | CTRL-V. On Unix, on the other hand, CTRL-Q does not work on some |
| 509 | terminals, because it has a special meaning. |
| 510 | |
| 511 | You can also use the command CTRL-V {digits} to insert a character with the |
| 512 | decimal number {digits}. For example, the character number 127 is the <Del> |
| 513 | character (but not necessarily the <Del> key!). To insert <Del> type: > |
| 514 | |
| 515 | CTRL-V 127 |
| 516 | |
| 517 | You can enter characters up to 255 this way. When you type fewer than two |
| 518 | digits, a non-digit will terminate the command. To avoid the need of typing a |
| 519 | non-digit, prepend one or two zeros to make three digits. |
| 520 | All the next commands insert a <Tab> and then a dot: |
| 521 | |
| 522 | CTRL-V 9. |
| 523 | CTRL-V 09. |
| 524 | CTRL-V 009. |
| 525 | |
| 526 | To enter a character in hexadecimal, use an "x" after the CTRL-V: > |
| 527 | |
| 528 | CTRL-V x7f |
| 529 | |
| 530 | This also goes up to character 255 (CTRL-V xff). You can use "o" to type a |
| 531 | character as an octal number and two more methods allow you to type up to |
| 532 | a 16 bit and a 32 bit number (e.g., for a Unicode character): > |
| 533 | |
| 534 | CTRL-V o123 |
| 535 | CTRL-V u1234 |
| 536 | CTRL-V U12345678 |
| 537 | |
| 538 | ============================================================================== |
| 539 | *24.9* Digraphs |
| 540 | |
| 541 | Some characters are not on the keyboard. For example, the copyright character |
Bram Moolenaar | 98ef233 | 2018-03-18 14:44:37 +0100 | [diff] [blame] | 542 | (©). To type these characters in Vim, you use digraphs, where two characters |
| 543 | represent one. To enter a ©, for example, you press three keys: > |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 544 | |
| 545 | CTRL-K Co |
| 546 | |
| 547 | To find out what digraphs are available, use the following command: > |
| 548 | |
| 549 | :digraphs |
| 550 | |
| 551 | Vim will display the digraph table. Here are three lines of it: |
| 552 | |
Bram Moolenaar | 98ef233 | 2018-03-18 14:44:37 +0100 | [diff] [blame] | 553 | AC ~_ 159 NS | 160 !I ¡ 161 Ct ¢ 162 Pd £ 163 Cu ¤ 164 Ye ¥ 165 ~ |
| 554 | BB ¦ 166 SE § 167 ': ¨ 168 Co © 169 -a ª 170 << « 171 NO ¬ 172 ~ |
| 555 | -- 173 Rg ® 174 'm ¯ 175 DG ° 176 +- ± 177 2S ² 178 3S ³ 179 ~ |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 556 | |
| 557 | This shows, for example, that the digraph you get by typing CTRL-K Pd is the |
Bram Moolenaar | 98ef233 | 2018-03-18 14:44:37 +0100 | [diff] [blame] | 558 | character (£). This is character number 163 (decimal). |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 559 | Pd is short for Pound. Most digraphs are selected to give you a hint about |
| 560 | the character they will produce. If you look through the list you will |
| 561 | understand the logic. |
| 562 | You can exchange the first and second character, if there is no digraph for |
| 563 | that combination. Thus CTRL-K dP also works. Since there is no digraph for |
| 564 | "dP" Vim will also search for a "Pd" digraph. |
| 565 | |
| 566 | Note: |
| 567 | The digraphs depend on the character set that Vim assumes you are |
Bram Moolenaar | 5666fcd | 2019-12-26 14:35:26 +0100 | [diff] [blame] | 568 | using. Always use ":digraphs" to find out which digraphs are currently |
| 569 | available. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 570 | |
Christian Brabandt | a9b95c3 | 2025-06-22 20:32:15 +0200 | [diff] [blame] | 571 | You can define your own digraphs by specifying the target character with a |
| 572 | decimal number. Example: > |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 573 | |
Christian Brabandt | a9b95c3 | 2025-06-22 20:32:15 +0200 | [diff] [blame] | 574 | :digraph a\" 228 |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 575 | |
Christian Brabandt | a9b95c3 | 2025-06-22 20:32:15 +0200 | [diff] [blame] | 576 | This defines that CTRL-K a" inserts an ä character. Note: we had to escape |
| 577 | the " character since otherwise it would act as a comment character. |
Bram Moolenaar | 071d427 | 2004-06-13 20:20:40 +0000 | [diff] [blame] | 578 | |
| 579 | More information about digraphs here: |digraphs| |
| 580 | Another way to insert special characters is with a keymap. More about that |
| 581 | here: |45.5| |
| 582 | |
| 583 | ============================================================================== |
| 584 | *24.10* Normal mode commands |
| 585 | |
| 586 | Insert mode offers a limited number of commands. In Normal mode you have many |
| 587 | more. When you want to use one, you usually leave Insert mode with <Esc>, |
| 588 | execute the Normal mode command, and re-enter Insert mode with "i" or "a". |
| 589 | There is a quicker way. With CTRL-O {command} you can execute any Normal |
| 590 | mode command from Insert mode. For example, to delete from the cursor to the |
| 591 | end of the line: > |
| 592 | |
| 593 | CTRL-O D |
| 594 | |
| 595 | You can execute only one Normal mode command this way. But you can specify a |
| 596 | register or a count. A more complicated example: > |
| 597 | |
| 598 | CTRL-O "g3dw |
| 599 | |
| 600 | This deletes up to the third word into register g. |
| 601 | |
| 602 | ============================================================================== |
| 603 | |
| 604 | Next chapter: |usr_25.txt| Editing formatted text |
| 605 | |
Bram Moolenaar | d473c8c | 2018-08-11 18:00:22 +0200 | [diff] [blame] | 606 | Copyright: see |manual-copyright| vim:tw=78:ts=8:noet:ft=help:norl: |