1 VI(1HAS) User Commands VI(1HAS) 2 3 4 5 NAME 6 vi, view, vedit - screen-oriented (visual) display editor based on ex 7 8 SYNOPSIS 9 /usr/bin/vi [-| -s] [-l] [-L] [-R] [-r [filename]] [-S] 10 [-t tag] [-v] [-V] [-x] [-wn] [-C] 11 [+command | -c command] filename... 12 13 14 /usr/bin/view [-| -s] [-l] [-L] [-R] [-r [filename]] [-S] 15 [-t tag] [-v] [-V] [-x] [-wn] [-C] 16 [+command | -c command] filename... 17 18 19 /usr/bin/vedit [-| -s] [-l] [-L] [-R] [-r [filename]] [-S] 20 [-t tag] [-v] [-V] [-x] [-wn] [-C] 21 [+command | -c command] filename... 22 23 24 /usr/xpg4/bin/vi [-| -s] [-l] [-L] [-R] [-r [filename]] 25 [-S] [-t tag] [-v] [-V] [-x] [-wn] [-C] 26 [+command | -c command] filename... 27 28 29 /usr/xpg4/bin/view [-| -s] [-l] [-L] [-R] [-r [filename]] 30 [-S] [-t tag] [-v] [-V] [-x] [-wn] [-C] 31 [+command | -c command] filename... 32 33 34 /usr/xpg4/bin/vedit [-| -s] [-l] [-L] [-R] [-r [filename]] 35 [-S] [-t tag] [-v] [-V] [-x] [-wn] [-C] 36 [+command | -c command] filename... 37 38 39 /usr/xpg6/bin/vi [-| -s] [-l] [-L] [-R] [-r [filename]] 40 [-S] [-t tag] [-v] [-V] [-x] [-wn] [-C] 41 [+command | -c command] filename... 42 43 44 /usr/xpg6/bin/view [-| -s] [-l] [-L] [-R] [-r [filename]] 45 [-S] [-t tag] [-v] [-V] [-x] [-wn] [-C] 46 [+command | -c command] filename... 47 48 49 /usr/xpg6/bin/vedit [-| -s] [-l] [-L] [-R] [-r [filename]] 50 [-S] [-t tag] [-v] [-V] [-x] [-wn] [-C] 51 [+command | -c command] filename... 52 53 54 DESCRIPTION 55 The vi (visual) utility is a display-oriented text editor based on an 56 underlying line editor ex. It is possible to use the command mode of ex 57 from within vi and to use the command mode of vi from within ex. The 58 visual commands are described on this manual page; how to set options 59 (like automatically numbering lines and automatically starting a new 60 output line when you type carriage return) and all ex line editor 61 commands are described on the ex(1) manual page. 62 63 64 When using vi, changes you make to the file are reflected in what you 65 see on your terminal screen. The position of the cursor on the screen 66 indicates the position within the file. 67 68 69 The view invocation is the same as vi except that the readonly flag is 70 set. 71 72 73 The vedit invocation is intended for beginners. It is the same as vi 74 except that the report flag is set to 1, the showmode and novice flags 75 are set, and magic is turned off. These defaults make it easier to 76 learn how to use vi. 77 78 OPTIONS 79 The following options are supported: 80 81 Invocation Options 82 The following invocation options are interpreted by vi (previously 83 documented options are discussed under NOTES): 84 85 - | -s 86 Suppresses all interactive user feedback. This 87 is useful when processing editor scripts. 88 89 90 -C 91 Encryption option. Same as the -x option, 92 except that vi simulates the C command of ex. 93 The C command is like the X command of ex, 94 except that all text read in is assumed to 95 have been encrypted. 96 97 98 -l 99 Sets up for editing LISP programs. 100 101 102 -L 103 Lists the name of all files saved as the 104 result of an editor or system crash. 105 106 107 -r filename 108 Edits filename after an editor or system 109 crash. (Recovers the version of filename that 110 was in the buffer when the crash occurred.) 111 112 113 -R 114 Readonly mode. The readonly flag is set, 115 preventing accidental overwriting of the file. 116 117 118 -S 119 This option is used in conjunction with the -t 120 tag option to tell vi that the tags file can 121 not be sorted and that, if the binary search 122 (which relies on a sorted tags file) for tag 123 fails to find it, the much slower linear 124 search should also be done. Since the linear 125 search is slow, users of large tags files 126 should ensure that the tags files are sorted 127 rather than use this flag. Creation of tags 128 files normally produces sorted tags files. 129 See ctags(1) for more information on tags 130 files. 131 132 133 -t tag 134 Edits the file containing tag and position the 135 editor at its definition. It is an error to 136 specify more than one -t option. 137 138 139 -v 140 Starts up in display editing state, using vi. 141 You can achieve the same effect by typing the 142 vi command itself. 143 144 145 -V 146 Verbose. When ex commands are read by means of 147 standard input, the input is echoed to 148 standard error. This can be useful when 149 processing ex commands within shell scripts. 150 151 152 -wn 153 Sets the default window size to n. This is 154 useful when using the editor over a slow speed 155 line. 156 157 158 -x 159 Encryption option. When used, vi simulates the 160 X command of ex and prompts the user for a 161 key. This key is used to encrypt and decrypt 162 text using the algorithm of the crypt command. 163 The X command makes an educated guess to 164 determine whether text read in is encrypted or 165 not. The temporary buffer file is encrypted 166 also, using a transformed version of the key 167 typed in for the -x option. If an empty 168 encryption key is entered (that is, if the 169 return key is pressed right after the prompt), 170 the file is not encrypted. This is a good way 171 to decrypt a file erroneously encrypted with a 172 mistyped encryption key, such as a backspace 173 or undo key. 174 175 176 -command | -c command 177 Begins editing by executing the specified 178 editor command (usually a search or 179 positioning command). 180 181 182 /usr/xpg4/bin/vi and /usr/xpg6/bin/vi 183 If both the -t tag and the -c command options are given, the -t tag 184 option is processed first. That is, the file containing tag is selected 185 by -t and then the command is executed. 186 187 OPERANDS 188 The following operands are supported: 189 190 filename 191 A file to be edited. 192 193 194 COMMAND SUMMARY 195 The vi command modes are summarized in this section. 196 197 vi Modes 198 Command 199 Normal and initial mode. Other modes return to command 200 mode upon completion. ESC (escape) is used to cancel a 201 partial command. 202 203 204 Input 205 Entered by setting any of the following options: 206 207 a A i I o O c C s S R 208 209 210 Arbitrary text can then be entered. Input mode is normally 211 terminated with the ESC character, or, abnormally, with an 212 interrupt. 213 214 215 Last line 216 Reading input for : / ? or !. Terminate by typing a 217 carriage return. An interrupt cancels termination. 218 219 220 Sample Commands 221 In the descriptions, CR stands for carriage return and ESC stands for 222 the escape key. 223 224 <-, -> 225 down-arrow 226 up-arrow 227 arrow keys move the cursor 228 229 230 h j k l 231 same as arrow keys 232 233 234 itextESC 235 insert text 236 237 238 cwnewESC 239 change word to new 240 241 242 easESC 243 pluralize word (end of word; append s; escape from input 244 state) 245 246 247 x 248 delete a character 249 250 251 dw 252 delete a word 253 254 255 dd 256 delete a line 257 258 259 3dd 260 delete 3 lines 261 262 263 u 264 undo previous change 265 266 267 ZZ 268 exit vi, saving changes 269 270 271 :q!CR 272 quit, discarding changes 273 274 275 /textCR 276 search for text 277 278 279 ^U ^D 280 scroll up or down 281 282 283 :cmdCR 284 any ex or ed command 285 286 287 Counts Before vi Commands 288 Numbers can be typed as a prefix to some commands. They are interpreted 289 in one of these ways: 290 291 line/column number 292 z G | 293 294 295 scroll amount 296 ^D ^U 297 298 299 repeat effect 300 most of the rest 301 302 303 Interrupting, Canceling 304 ESC 305 end insert or incomplete command 306 307 308 DEL 309 (delete or rubout) interrupts 310 311 312 File Manipulation 313 ZZ 314 if file modified, write and exit; otherwise, exit 315 316 317 :wCR 318 write back changes 319 320 321 :w!CR 322 forced write, if permission originally not valid 323 324 325 :qCR 326 quit 327 328 329 :q!CR 330 quit, discard changes 331 332 333 :e nameCR 334 edit file name 335 336 337 :e!CR 338 reedit, discard changes 339 340 341 :e + nameCR 342 edit, starting at end 343 344 345 :e +nCR 346 edit, starting at line n 347 348 349 :e #CR 350 edit alternate file 351 352 353 :e! #CR 354 edit alternate file, discard changes 355 356 357 :w nameCR 358 write file name 359 360 361 :w! nameCR 362 overwrite file name 363 364 365 :shCR 366 run shell, then return 367 368 369 :!cmdCR 370 run cmd, then return 371 372 373 :nCR 374 edit next file in arglist 375 376 377 :n argsCR 378 specify new arglist 379 380 381 ^G 382 show current file and line 383 384 385 :ta tagCR 386 position cursor to tag 387 388 389 390 In general, any ex or ed command (such as substitute or global) can be 391 typed, preceded by a colon and followed by a carriage return. 392 393 Positioning Within a File 394 F 395 forward screen 396 397 398 ^B 399 backward screen 400 401 402 ^D 403 scroll down half screen 404 405 406 ^U 407 scroll up half screen 408 409 410 nG 411 go to the beginning of the specified line (end default), 412 where n is a line number 413 414 415 /pat 416 next line matching pat 417 418 419 ?pat 420 previous line matching pat 421 422 423 n 424 repeat last / or ? command 425 426 427 N 428 reverse last / or ? command 429 430 431 /pat/+n 432 nth line after pat 433 434 435 ?pat?-n 436 nth line before pat 437 438 439 ]] 440 next section/function 441 442 443 [[ 444 previous section/function 445 446 447 ( 448 beginning of sentence 449 450 451 ) 452 end of sentence 453 454 455 { 456 beginning of paragraph 457 458 459 } 460 end of paragraph 461 462 463 % 464 find matching ( ) or { } 465 466 467 Adjusting the Screen 468 ^L 469 clear and redraw window 470 471 472 ^R 473 clear and redraw window if ^L is -> key 474 475 476 zCR 477 redraw screen with current line at top of window 478 479 480 z-CR 481 redraw screen with current line at bottom of window 482 483 484 z.CR 485 redraw screen with current line at center of window 486 487 488 /pat/z-CR 489 move pat line to bottom of window 490 491 492 zn.CR 493 use n-line window 494 495 496 ^E 497 scroll window down one line 498 499 500 ^Y 501 scroll window up one line 502 503 504 Marking and Returning 505 `` 506 move cursor to previous context 507 508 509 a'a' 510 move cursor to first non-white space in line 511 512 513 mx 514 mark current position with the ASCII lower-case letter x 515 516 517 `x 518 move cursor to mark x 519 520 521 a'x 522 move cursor to first non-white space in line marked by x 523 524 525 Line Positioning 526 H 527 top line on screen 528 529 530 L 531 last line on screen 532 533 534 M 535 middle line on screen 536 537 538 + 539 next line, at first non-white space character 540 541 542 - 543 previous line, at first non-white space character 544 545 546 CR 547 return, same as + 548 549 550 down-arrow 551 or j 552 next line, same column 553 554 555 up-arrow 556 or k 557 previous line, same column 558 559 560 Character Positioning 561 ^ 562 first non-white space character 563 564 565 0 566 beginning of line 567 568 569 $ 570 end of line 571 572 573 l or -> 574 forward 575 576 577 h or <- 578 backward 579 580 581 ^H 582 same as <- (backspace) 583 584 585 space 586 same as -> (space bar) 587 588 589 fx 590 find next x 591 592 593 Fx 594 find previous x 595 596 597 tx 598 move to character following the next x 599 600 601 Tx 602 move to character following the previous x 603 604 605 ; 606 repeat last f, F, t, or T 607 608 609 , 610 repeat inverse of last f, F, t, or T 611 612 613 n| 614 move to column n 615 616 617 % 618 find matching ( ) or { } 619 620 621 Words, Sentences, Paragraphs 622 w 623 forward a word 624 625 626 b 627 back a word 628 629 630 e 631 end of word 632 633 634 ) 635 to next sentence 636 637 638 } 639 to next paragraph 640 641 642 ( 643 back a sentence 644 645 646 { 647 back a paragraph 648 649 650 W 651 forward a blank-delimited word 652 653 654 B 655 back a blank-delimited word 656 657 658 E 659 end of a blank-delimited word 660 661 662 Corrections During Insert 663 ^H 664 erase last character (backspace) 665 666 667 ^W 668 erase last word 669 670 671 erase 672 your erase character, same as ^H (backspace) 673 674 675 kill 676 your kill character, erase this line of input 677 678 679 \ 680 quotes your erase and kill characters 681 682 683 ESC 684 ends insertion, back to command mode 685 686 687 Control-C 688 interrupt, suspends insert mode 689 690 691 ^D 692 backtab one character; reset left margin of autoindent 693 694 695 ^^D 696 caret (^) followed by control-d (^D); backtab to 697 beginning of line; do not reset left margin of 698 autoindent 699 700 701 0^D 702 backtab to beginning of line; reset left margin of 703 autoindent 704 705 706 ^V 707 quote non-printable character 708 709 710 Insert and Replace 711 a 712 append after cursor 713 714 715 A 716 append at end of line 717 718 719 i 720 insert before cursor 721 722 723 I 724 insert before first non-blank 725 726 727 o 728 open line below 729 730 731 O 732 open line above 733 734 735 rx 736 replace single character with x 737 738 739 RtextESC 740 replace characters 741 742 743 Operators 744 Operators are followed by a cursor motion and affect all text that 745 would have been moved over. For example, since w moves over a word, dw 746 deletes the word that would be moved over. Double the operator, for 747 example dd, to affect whole lines. 748 749 d 750 delete 751 752 753 c 754 change 755 756 757 y 758 yank lines to buffer 759 760 761 < 762 left shift 763 764 765 > 766 right shift 767 768 769 ! 770 filter through command 771 772 773 Miscellaneous Operations 774 C 775 change rest of line (c$) 776 777 778 D 779 delete rest of line (d$) 780 781 782 s 783 substitute characters (cl) 784 785 786 S 787 substitute lines (cc) 788 789 790 J 791 join lines 792 793 794 x 795 delete characters (dl) 796 797 798 X 799 delete characters before cursor dh) 800 801 802 Y 803 yank lines (yy) 804 805 806 Yank and Put 807 Put inserts the text most recently deleted or yanked; however, if a 808 buffer is named (using the ASCII lower-case letters a - z), the text in 809 that buffer is put instead. 810 811 3yy 812 yank 3 lines 813 814 815 3yl 816 yank 3 characters 817 818 819 p 820 put back text after cursor 821 822 823 P 824 put back text before cursor 825 826 827 "xp 828 put from buffer x 829 830 831 "xy 832 yank to buffer x 833 834 835 "xd 836 delete into buffer x 837 838 839 Undo, Redo, Retrieve 840 u 841 undo last change 842 843 844 U 845 restore current line 846 847 848 . 849 repeat last change 850 851 852 "dp 853 retrieve d'th last delete 854 855 856 USAGE 857 See largefile(5) for the description of the behavior of vi and view 858 when encountering files greater than or equal to 2 Gbyte ( 2^31 bytes). 859 860 ENVIRONMENT VARIABLES 861 See environ(5) for descriptions of the following environment variables 862 that affect the execution of vi: LANG, LC_ALL, LC_COLLATE, LC_CTYPE, 863 LC_TIME, LC_MESSAGES, NLSPATH, PATH, SHELL, and TERM. 864 865 COLUMNS 866 Override the system-selected horizontal screen size. 867 868 869 EXINIT 870 Determine a list of ex commands that are executed on editor 871 start-up, before reading the first file. The list can 872 contain multiple commands by separating them using a 873 vertical-line (|) character. 874 875 876 LINES 877 Override the system-selected vertical screen size, used as 878 the number of lines in a screenful and the vertical screen 879 size in visual mode. 880 881 882 FILES 883 /var/tmp 884 885 default directory where temporary work files are placed; it can be 886 changed using the directory option (see the ex(1) command) 887 888 889 /usr/share/lib/terminfo/?/* 890 891 compiled terminal description database 892 893 894 /usr/lib/.COREterm/?/* 895 896 subset of compiled terminal description database 897 898 899 ATTRIBUTES 900 See attributes(5) for descriptions of the following attributes: 901 902 /usr/bin/vi, /usr/bin/view, /usr/bin/vedit 903 904 +---------------+-----------------+ 905 |ATTRIBUTE TYPE | ATTRIBUTE VALUE | 906 +---------------+-----------------+ 907 |CSI | Not enabled | 908 +---------------+-----------------+ 909 910 /usr/xpg4/bin/vi, /usr/xpg4/bin/view, /usr/xpg4/bin/vedit 911 912 +--------------------+-----------------+ 913 | ATTRIBUTE TYPE | ATTRIBUTE VALUE | 914 +--------------------+-----------------+ 915 |CSI | Enabled | 916 +--------------------+-----------------+ 917 |Interface Stability | Standard | 918 +--------------------+-----------------+ 919 920 /usr/xpg6/bin/vi, /usr/xpg6/bin/view, /usr/xpg6/bin/vedit 921 922 +--------------------+-----------------+ 923 | ATTRIBUTE TYPE | ATTRIBUTE VALUE | 924 +--------------------+-----------------+ 925 |CSI | Enabled | 926 +--------------------+-----------------+ 927 |Interface Stability | Standard | 928 +--------------------+-----------------+ 929 930 SEE ALSO 931 Intro(1), ctags(1), ed(1), edit(1), ex(1), attributes(5), environ(5), 932 largefile(5), standards(5) 933 934 935 Solaris Advanced User's Guide 936 937 AUTHOR 938 vi and ex were developed by The University of California, Berkeley 939 California, Computer Science Division, Department of Electrical 940 Engineering and Computer Science. 941 942 NOTES 943 Two options, although they continue to be supported, have been replaced 944 in the documentation by options that follow the Command Syntax Standard 945 (see Intro(1)). An -r option that is not followed with an option- 946 argument has been replaced by -L and +command has been replaced by -c 947 command. 948 949 950 The message file too large to recover with -r option, which is seen 951 when a file is loaded, indicates that the file can be edited and saved 952 successfully, but if the editing session is lost, recovery of the file 953 with the -r option is not possible. 954 955 956 The editing environment defaults to certain configuration options. When 957 an editing session is initiated, vi attempts to read the EXINIT 958 environment variable. If it exists, the editor uses the values defined 959 in EXINIT; otherwise the values set in $HOME/.exrc are used. If 960 $HOME/.exrc does not exist, the default values are used. 961 962 963 To use a copy of .exrc located in the current directory other than 964 $HOME, set the exrc option in EXINIT or $HOME/.exrc. Options set in 965 EXINIT can be turned off in a local .exrc only if exrc is set in EXINIT 966 or $HOME/.exrc. In order to be used, .exrc in $HOME or the current 967 directory must fulfill these conditions: 968 969 o It must exist. 970 971 o It must be owned by the same userid as the real userid of 972 the process, or the process has appropriate privileges. 973 974 o It is not writable by anyone other than the owner. 975 976 977 Tampering with entries in /usr/share/lib/terminfo/?/* or 978 /usr/share/lib/terminfo/?/* (for example, changing or removing an 979 entry) can affect programs such as vi that expect the entry to be 980 present and correct. In particular, removing the "dumb" terminal can 981 cause unexpected problems. 982 983 984 Software tabs using ^T work only immediately after the autoindent. 985 986 987 Left and right shifts on intelligent terminals do not make use of 988 insert and delete character operations in the terminal. 989 990 991 Loading an alternate malloc() library using the environment variable 992 LD_PRELOAD can cause problems for /usr/bin/vi. 993 994 995 The vi utility currently has the following limitations: 996 997 1. Lines, including the trailing NEWLINE character, can contain 998 no more than 4096 bytes. 999 1000 If a longer line is found, Line too long is displayed in the 1001 status line. 1002 1003 2. The editor's temporary work file can be no larger than 1004 128Mb. 1005 1006 If a larger temporary file is needed, Tmp file too large is 1007 displayed in the status line. 1008 1009 1010 1011 May 16, 2007 VI(1HAS)