1.\" $OpenBSD: vi.1,v 1.85 2024/04/24 15:15:40 job Exp $ 2.\" 3.\" Copyright (c) 1994 4.\" The Regents of the University of California. All rights reserved. 5.\" Copyright (c) 1994, 1995, 1996 6.\" Keith Bostic. All rights reserved. 7.\" 8.\" The vi program is freely redistributable. 9.\" You are welcome to copy, modify and share it with others 10.\" under the conditions listed in the LICENSE file. 11.\" If any company (not individual!) finds vi sufficiently useful 12.\" that you would have purchased it, or if any company wishes to 13.\" redistribute it, contributions to the authors would be appreciated. 14.\" 15.\" @(#)vi.1 8.51 (Berkeley) 10/10/96 16.\" 17.Dd $Mdocdate: April 24 2024 $ 18.Dt VI 1 19.Os 20.Sh NAME 21.Nm ex , vi , view 22.Nd text editors 23.Sh SYNOPSIS 24.Nm ex 25.Op Fl FRrSsv 26.Op Fl c Ar cmd 27.Op Fl t Ar tag 28.Op Fl w Ar size 29.Op Ar 30.Nm vi\ \& 31.Op Fl eFRrS 32.Op Fl c Ar cmd 33.Op Fl t Ar tag 34.Op Fl w Ar size 35.Op Ar 36.Nm view 37.Op Fl eFrS 38.Op Fl c Ar cmd 39.Op Fl t Ar tag 40.Op Fl w Ar size 41.Op Ar 42.Sh DESCRIPTION 43.Nm ex 44is a line-oriented text editor; 45.Nm vi 46is a screen-oriented text editor. 47.Nm ex 48and 49.Nm vi 50are different interfaces to the same program, 51and it is possible to switch back and forth during an edit session. 52.Nm view 53is the equivalent of using the 54.Fl R 55.Pq read-only 56option of 57.Nm vi . 58.Pp 59This manual page is the one provided with the 60.Nm nex Ns / Ns Nm nvi 61versions of the 62.Nm ex Ns / Ns Nm vi 63text editors. 64.Nm nex Ns / Ns Nm nvi 65are intended as bug-for-bug compatible replacements for the original 66Fourth Berkeley Software Distribution 67.Pq 4BSD 68.Nm ex 69and 70.Nm vi 71programs. 72For the rest of this manual page, 73.Nm nex Ns / Ns Nm nvi 74is used only when it's necessary to distinguish it from the historic 75implementations of 76.Nm ex Ns / Ns Nm vi . 77.Pp 78This manual page is intended for users already familiar with 79.Nm ex Ns / Ns Nm vi . 80Anyone else should almost certainly read a good tutorial on the 81editor before this manual page. 82If you're in an unfamiliar environment, 83and you absolutely have to get work done immediately, 84read the section after the options description, entitled 85.Sx FAST STARTUP . 86It's probably enough to get you going. 87.Pp 88The following options are available: 89.Bl -tag -width "-w size " 90.It Fl c Ar cmd 91Execute 92.Ar cmd 93on the first file loaded. 94Particularly useful for initial positioning in the file, although 95.Ar cmd 96is not limited to positioning commands. 97This is the POSIX 1003.2 interface for the historic 98.Dq +cmd 99syntax. 100.Nm nex Ns / Ns Nm nvi 101supports both the old and new syntax. 102.It Fl e 103Start editing in ex mode, as if the command name were 104.Nm ex . 105.It Fl F 106Don't copy the entire file when first starting to edit. 107(The default is to make a copy in case someone else modifies 108the file during your edit session.) 109.It Fl R 110Start editing in read-only mode, as if the command name was 111.Nm view , 112or the 113.Cm readonly 114option was set. 115.It Fl r 116Recover the specified files or, if no files are specified, 117list the files that could be recovered. 118If no recoverable files by the specified name exist, 119the file is edited as if the 120.Fl r 121option had not been specified. 122.It Fl S 123Run with the 124.Cm secure 125edit option set, disallowing all access to external programs. 126.It Fl s 127Enter batch mode; applicable only to 128.Nm ex 129edit sessions. 130Batch mode is useful when running 131.Nm ex 132scripts. 133Prompts, informative messages and other user oriented messages are turned off, 134and no startup files or environment variables are read. 135This is the POSIX 1003.2 interface for the historic 136.Dq - 137argument. 138.Nm nex Ns / Ns Nm nvi 139supports both the old and new syntax. 140.It Fl t Ar tag 141Start editing at the specified 142.Ar tag 143(see 144.Xr ctags 1 ) . 145.It Fl v 146Start editing in vi mode, as if the command name was 147.Nm vi . 148.It Fl w Ar size 149Set the initial window size to the specified number of lines. 150.El 151.Pp 152Command input for 153.Nm ex Ns / Ns Nm vi 154is read from the standard input. 155In the 156.Nm vi 157interface, it is an error if standard input is not a terminal. 158In the 159.Nm ex 160interface, if standard input is not a terminal, 161.Nm ex 162will read commands from it regardless; however, the session will be a 163batch mode session, exactly as if the 164.Fl s 165option had been specified. 166.Sh FAST STARTUP 167This section will tell you the minimum amount that you need to 168do simple editing tasks using 169.Nm vi . 170If you've never used any screen editor before, 171you're likely to have problems even with this simple introduction. 172In that case you should find someone that already knows 173.Nm vi 174and have them walk you through this section. 175.Pp 176.Nm vi 177is a screen editor. 178This means that it takes up almost the entire screen, 179displaying part of the file on each screen line, 180except for the last line of the screen. 181The last line of the screen is used for you to give commands to 182.Nm vi , 183and for 184.Nm vi 185to give information to you. 186.Pp 187The other fact that you need to understand is that 188.Nm vi 189is a modeful editor, 190i.e. you are either entering text or you are executing commands, 191and you have to be in the right mode to do one or the other. 192You will be in command mode when you first start editing a file. 193There are commands that switch you into input mode. 194There is only one key that takes you out of input mode, 195and that is the 196.Aq escape 197key. 198.Pp 199Key names are written using angle brackets, e.g.\& 200.Aq escape 201means the 202.Dq escape 203key, usually labeled 204.Dq Esc 205on your 206terminal's keyboard. 207If you're ever confused as to which mode you're in, 208keep entering the 209.Aq escape 210key until 211.Nm vi 212beeps at you. 213Generally, 214.Nm vi 215will beep at you if you try and do something that's not allowed. 216It will also display error messages. 217.Pp 218To start editing a file, enter the following command: 219.Pp 220.Dl $ vi file 221.Pp 222The command you should enter as soon as you start editing is: 223.Pp 224.Dl :set verbose showmode 225.Pp 226This will make the editor give you verbose error messages and display 227the current mode at the bottom of the screen. 228.Pp 229The commands to move around the file are: 230.Bl -tag -width Ds 231.It Cm h 232Move the cursor left one character. 233.It Cm j 234Move the cursor down one line. 235.It Cm k 236Move the cursor up one line. 237.It Cm l 238Move the cursor right one character. 239.It Aq Cm cursor-arrows 240The cursor arrow keys should work, too. 241.It Cm / Ns text 242Search for the string 243.Dq text 244in the file, 245and move the cursor to its first character. 246.El 247.Pp 248The commands to enter new text are: 249.Bl -tag -width "<escape>" 250.It Cm a 251Append new text, after the cursor. 252.It Cm i 253Insert new text, before the cursor. 254.It Cm O 255Open a new line above the line the cursor is on, and start entering text. 256.It Cm o 257Open a new line below the line the cursor is on, and start entering text. 258.It Aq Cm escape 259Once you've entered input mode using one of the 260.Cm a , 261.Cm i , 262.Cm O 263or 264.Cm o 265commands, use 266.Aq Cm escape 267to quit entering text and return to command mode. 268.El 269.Pp 270The commands to copy text are: 271.Bl -tag -width Ds 272.It Cm p 273Append the copied line after the line the cursor is on. 274.It Cm yy 275Copy the line the cursor is on. 276.El 277.Pp 278The commands to delete text are: 279.Bl -tag -width Ds 280.It Cm dd 281Delete the line the cursor is on. 282.It Cm x 283Delete the character the cursor is on. 284.El 285.Pp 286The commands to write the file are: 287.Bl -tag -width Ds 288.It Cm :w 289Write the file back to the file with the name that you originally used 290as an argument on the 291.Nm vi 292command line. 293.It Cm :w Ar file_name 294Write the file back to the file with the name 295.Ar file_name . 296.El 297.Pp 298The commands to quit editing and exit the editor are: 299.Bl -tag -width Ds 300.It Cm :q 301Quit editing and leave 302.Nm vi 303(if you've modified the file, but not saved your changes, 304.Nm vi 305will refuse to quit). 306.It Cm :q! 307Quit, discarding any modifications that you may have made. 308.El 309.Pp 310One final caution: 311Unusual characters can take up more than one column on the screen, 312and long lines can take up more than a single screen line. 313The above commands work on 314.Dq physical 315characters and lines, 316i.e. they affect the entire line no matter how many screen lines it takes up 317and the entire character no matter how many screen columns it takes up. 318.Sh REGULAR EXPRESSIONS 319.Nm ex Ns / Ns Nm vi 320supports regular expressions 321.Pq REs , 322as documented in 323.Xr re_format 7 , 324for line addresses, as the first part of the 325.Nm ex Cm substitute , 326.Cm global 327and 328.Cm v 329commands, and in search patterns. 330Basic regular expressions 331.Pq BREs 332are enabled by default; 333extended regular expressions 334.Pq EREs 335are used if the 336.Cm extended 337option is enabled. 338The use of regular expressions can be largely disabled using the 339.Cm magic 340option. 341.Pp 342The following strings have special meanings in the 343.Nm ex Ns / Ns Nm vi 344version of regular expressions: 345.Bl -bullet -offset 6u 346.It 347An empty regular expression is equivalent to the last regular expression used. 348.It 349.Sq \e< 350matches the beginning of the word. 351.It 352.Sq \e> 353matches the end of the word. 354.It 355.Sq ~ 356matches the replacement part of the last 357.Cm s 358command. 359.El 360.Sh BUFFERS 361A buffer is an area where commands can save changed or deleted text 362for later use. 363.Nm vi 364buffers are named with a single character preceded by a double quote, 365for example 366.Pf \&" Aq c ; 367.Nm ex 368buffers are the same, 369but without the double quote. 370.Nm nex Ns / Ns Nm nvi 371permits the use of any character without another meaning in the position where 372a buffer name is expected. 373.Pp 374All buffers are either in 375.Em line mode 376or 377.Em character mode . 378Inserting a buffer in line mode into the text creates new lines for each of the 379lines it contains, while a buffer in character mode creates new lines for any 380lines 381.Em other 382than the first and last lines it contains. 383The first and last lines are inserted at the current cursor position, becoming 384part of the current line. 385If there is more than one line in the buffer, 386the current line itself will be split. 387All 388.Nm ex 389commands which store text into buffers do so in line mode. 390The behaviour of 391.Nm vi 392commands depend on their associated motion command: 393.Bl -bullet -offset 6u 394.It 395.Aq Cm control-A , 396.Cm h , 397.Cm l , 398.Cm ,\& , 399.Cm 0 , 400.Cm B , 401.Cm E , 402.Cm F , 403.Cm T , 404.Cm W , 405.Cm ^ , 406.Cm b , 407.Cm e , 408.Cm f 409and 410.Cm t 411make the destination buffer character-oriented. 412.It 413.Cm j , 414.Aq Cm control-M , 415.Cm k , 416.Cm ' , 417.Cm - , 418.Cm G , 419.Cm H , 420.Cm L , 421.Cm M , 422.Cm _ 423and 424.Cm |\& 425make the destination buffer line-oriented. 426.It 427.Cm $ , 428.Cm % , 429.Cm ` , 430.Cm (\& , 431.Cm )\& , 432.Cm / , 433.Cm ?\& , 434.Cm [[ , 435.Cm ]] , 436.Cm { 437and 438.Cm } 439make the destination buffer character-oriented, unless the starting and 440end positions are the first and last characters on a line. 441In that case, the buffer is line-oriented. 442.El 443.Pp 444The 445.Nm ex 446command 447.Cm display buffers 448displays the current mode for each buffer. 449.Pp 450Buffers named 451.Sq a 452through 453.Sq z 454may be referred to using their uppercase equivalent, in which case new content 455will be appended to the buffer, instead of replacing it. 456.Pp 457Buffers named 458.Sq 1 459through 460.Sq 9 461are special. 462A region of text modified using the 463.Cm c 464.Pq change 465or 466.Cm d 467.Pq delete 468commands is placed into the numeric buffer 469.Sq 1 470if no other buffer is specified and if it meets one of the following conditions: 471.Bl -bullet -offset 6u 472.It 473It includes characters from more than one line. 474.It 475It is specified using a line-oriented motion. 476.It 477It is specified using one of the following motion commands: 478.Aq Cm control-A , 479.Cm ` Ns Aq Cm character , 480.Cm n , 481.Cm N , 482.Cm % , 483.Cm / , 484.Cm { , 485.Cm } , 486.Cm \&( , 487.Cm \&) , 488and 489.Cm \&? . 490.El 491.Pp 492Before this copy is done, the previous contents of buffer 493.Sq 1 494are moved into buffer 495.Sq 2 , 496.Sq 2 497into buffer 498.Sq 3 , 499and so on. 500The contents of buffer 501.Sq 9 502are discarded. 503Note that this rotation occurs 504.Em regardless 505of the user specifying another buffer. 506In 507.Nm vi , 508text may be explicitly stored into the numeric buffers. 509In this case, the buffer rotation occurs before the replacement of the buffer's 510contents. 511The numeric buffers are only available in 512.Nm vi 513mode. 514.Sh VI COMMANDS 515The following section describes the commands available in the command 516mode of the 517.Nm vi 518editor. 519The following words have a special meaning in the commands 520description: 521.Pp 522.Bl -tag -width bigword -compact -offset 3u 523.It Ar bigword 524A set of non-whitespace characters. 525.It Ar buffer 526Temporary area where commands may place text. 527If not specified, the default buffer is used. 528See also 529.Sx BUFFERS , 530above. 531.It Ar count 532A positive number used to specify the desired number of iterations 533of a command. 534It defaults to 1 if not specified. 535.It Ar motion 536A cursor movement command which indicates the other end of the affected region 537of text, the first being the current cursor position. 538Repeating the command character makes it affect the whole 539current line. 540.It Ar word 541A sequence of letters, digits or underscores. 542.El 543.Pp 544.Ar buffer 545and 546.Ar count , 547if both present, may be specified in any order. 548.Ar motion 549and 550.Ar count , 551if both present, are effectively multiplied together 552and considered part of the motion. 553.Pp 554.Bl -tag -width Ds -compact 555.It Xo 556.Aq Cm control-A 557.Xc 558Search forward 559for the word starting at the cursor position. 560.Pp 561.It Xo 562.Op Ar count 563.Aq Cm control-B 564.Xc 565Page backwards 566.Ar count 567screens. 568Two lines of overlap are maintained, if possible. 569.Pp 570.It Xo 571.Op Ar count 572.Aq Cm control-D 573.Xc 574Scroll forward 575.Ar count 576lines. 577If 578.Ar count 579is not given, scroll forward the number of lines specified by the last 580.Aq Cm control-D 581or 582.Aq Cm control-U 583command. 584If this is the first 585.Aq Cm control-D 586command, scroll half the number of lines in the current screen. 587.Pp 588.It Xo 589.Op Ar count 590.Aq Cm control-E 591.Xc 592Scroll forward 593.Ar count 594lines, leaving the current line and column as is, if possible. 595.Pp 596.It Xo 597.Op Ar count 598.Aq Cm control-F 599.Xc 600Page forward 601.Ar count 602screens. 603Two lines of overlap are maintained, if possible. 604.Pp 605.It Aq Cm control-G 606Display the following file information: 607the file name (as given to 608.Nm vi ) ; 609whether the file has been modified since it was last written; 610if the file is readonly; 611the current line number; 612the total number of lines in the file; 613and the current line number as a percentage of the total lines in the file. 614.Pp 615.It Xo 616.Op Ar count 617.Aq Cm control-H 618.Xc 619.It Xo 620.Op Ar count 621.Cm h 622.Xc 623Move the cursor back 624.Ar count 625characters in the current line. 626.Pp 627.It Xo 628.Op Ar count 629.Aq Cm control-J 630.Xc 631.It Xo 632.Op Ar count 633.Aq Cm control-N 634.Xc 635.It Xo 636.Op Ar count 637.Cm j 638.Xc 639Move the cursor down 640.Ar count 641lines without changing the current column. 642.Pp 643.It Aq Cm control-L 644.It Aq Cm control-R 645Repaint the screen. 646.Pp 647.It Xo 648.Op Ar count 649.Aq Cm control-M 650.Xc 651.It Xo 652.Op Ar count 653.Cm + 654.Xc 655Move the cursor down 656.Ar count 657lines to the first non-blank character of that line. 658.Pp 659.It Xo 660.Op Ar count 661.Aq Cm control-P 662.Xc 663.It Xo 664.Op Ar count 665.Cm k 666.Xc 667Move the cursor up 668.Ar count 669lines, without changing the current column. 670.Pp 671.It Aq Cm control-T 672Return to the most recent tag context. 673.Pp 674.It Xo 675.Op Ar count 676.Aq Cm control-U 677.Xc 678Scroll backwards 679.Ar count 680lines. 681If 682.Ar count 683is not given, scroll backwards the number of lines specified by the last 684.Aq Cm control-D 685or 686.Aq Cm control-U 687command. 688If this is the first 689.Aq Cm control-U 690command, scroll half the number of lines in the current screen. 691.Pp 692.It Aq Cm control-W 693Switch to the next lower screen in the window, 694or to the first screen if there are no lower screens in the window. 695.Pp 696.It Xo 697.Op Ar count 698.Aq Cm control-Y 699.Xc 700Scroll backwards 701.Ar count 702lines, leaving the current line and column as is, if possible. 703.Pp 704.It Aq Cm control-Z 705Suspend the current editor session. 706.Pp 707.It Aq Cm escape 708Execute the 709.Nm ex 710command being entered, or cancel it if it is only partial. 711.Pp 712.It Aq Cm control-] 713Push a tag reference onto the tag stack. 714.Pp 715.It Aq Cm control-^ 716Switch to the most recently edited file. 717.Pp 718.It Xo 719.Op Ar count 720.Aq Cm space 721.Xc 722.It Xo 723.Op Ar count 724.Cm l 725.Xc 726Move the cursor forward 727.Ar count 728characters without changing the current line. 729.Pp 730.It Xo 731.Op Ar count 732.Cm !\& 733.Ar motion shell-argument(s) 734.Aq Li carriage-return 735.Xc 736Replace the lines spanned by 737.Ar count 738and 739.Ar motion 740with the output 741.Pq standard output and standard error 742of the program named by the 743.Cm shell 744option, called with a 745.Fl c 746flag followed by the 747.Ar shell-argument(s) 748.Pq bundled into a single argument . 749Within 750.Ar shell-argument(s) , 751the 752.Sq % , 753.Sq # 754and 755.Sq !\& 756characters are expanded to the current file name, 757the previous current file name, 758and the command text of the previous 759.Cm !\& 760or 761.Cm :! 762commands, respectively. 763The special meaning of 764.Sq % , 765.Sq # 766and 767.Sq !\& 768can be overridden by escaping them with a backslash. 769.Pp 770.It Xo 771.Op Ar count 772.Cm # 773.Sm off 774.Cm # | + | - 775.Sm on 776.Xc 777Increment 778.Pq trailing So # Sc or So + Sc 779or decrement 780.Pq trailing Sq - 781the number under the cursor by 782.Ar count , 783starting at the cursor position or at the first non-blank 784character following it. 785Numbers with a leading 786.Sq 0x 787or 788.Sq 0X 789are interpreted as hexadecimal numbers. 790Numbers with a leading 791.Sq 0 792are interpreted as octal numbers unless they contain a non-octal digit. 793Other numbers may be prefixed with a 794.Sq + 795or 796.Sq - 797sign. 798.Pp 799.It Xo 800.Op Ar count 801.Cm $ 802.Xc 803Move the cursor to the end of a line. 804If 805.Ar count 806is specified, additionally move the cursor down 807.Ar count 808\- 1 lines. 809.Pp 810.It Cm % 811Move to the parenthesis, square bracket or curly brace matching 812the one found at the cursor position or the closest to the right of it. 813.Pp 814.It Cm & 815Repeat the previous substitution command on the current line. 816.Pp 817.It Xo 818.Cm ' Ns Aq Ar character 819.Xc 820.It Xo 821.Cm ` Ns Aq Ar character 822.Xc 823Return to the cursor position marked by the character 824.Ar character , 825or, if 826.Ar character 827is 828.Sq ' 829or 830.Sq ` , 831to the position of the cursor before the last of the following commands: 832.Aq Cm control-A , 833.Aq Cm control-T , 834.Aq Cm control-] , 835.Cm % , 836.Cm ' , 837.Cm ` , 838.Cm (\& , 839.Cm )\& , 840.Cm / , 841.Cm ?\& , 842.Cm G , 843.Cm H , 844.Cm L , 845.Cm [[ , 846.Cm ]] , 847.Cm { , 848.Cm } . 849The first form returns to the first non-blank character of the line marked by 850.Ar character . 851The second form returns to the line and column marked by 852.Ar character . 853.Pp 854.It Xo 855.Op Ar count 856.Cm \&( 857.Xc 858.It Xo 859.Op Ar count 860.Cm \&) 861.Xc 862Move 863.Ar count 864sentences backward or forward, respectively. 865A sentence is an area of text that begins with the first nonblank character 866following the previous sentence, paragraph, or section 867boundary and continues until the next period, exclamation mark, 868or question mark character, followed by any number of closing parentheses, 869brackets, double or single quote characters, followed by 870either an end-of-line or two whitespace characters. 871Groups of empty lines 872.Pq or lines containing only whitespace characters 873are treated as a single sentence. 874.Pp 875.It Xo 876.Op Ar count 877.Cm ,\& 878.Xc 879Reverse find character 880(i.e. the last 881.Cm F , 882.Cm f , 883.Cm T 884or 885.Cm t 886command) 887.Ar count 888times. 889.Pp 890.It Xo 891.Op Ar count 892.Cm - 893.Xc 894Move to the first non-blank character of the previous line, 895.Ar count 896times. 897.Pp 898.It Xo 899.Op Ar count 900.Cm .\& 901.Xc 902Repeat the last 903.Nm vi 904command that modified text. 905.Ar count 906replaces both the 907.Ar count 908argument of the repeated command and that of the associated 909.Ar motion . 910If the 911.Cm .\& 912command repeats the 913.Cm u 914command, the change log is rolled forward or backward, depending on the action 915of the 916.Cm u 917command. 918.Pp 919.It Xo 920.Pf / Ar RE 921.Aq Li carriage-return 922.Xc 923.It Xo 924.Pf / Ar RE Ns / 925.Op Ar offset 926.Op Cm z 927.Aq Li carriage-return 928.Xc 929.It Xo 930.Pf ? Ar RE 931.Aq Li carriage-return 932.Xc 933.It Xo 934.Pf ? Ar RE ? Op Ar offset 935.Op Cm z 936.Aq Li carriage-return 937.Xc 938.It Cm N 939.It Cm n 940Search forward 941.Pq Sq / 942or backward 943.Pq Sq ?\& 944for a regular expression. 945.Cm n 946and 947.Cm N 948repeat the last search in the same or opposite directions, respectively. 949If 950.Ar RE 951is empty, the last search regular expression is used. 952If 953.Ar offset 954is specified, the cursor is placed 955.Ar offset 956lines before or after the matched regular expression. 957If either 958.Cm n 959or 960.Cm N 961commands are used as motion components for the 962.Cm !\& 963command, there will be no prompt for the text of the command and the previous 964.Cm !\& 965will be executed. 966Multiple search patterns may be grouped together by delimiting them with 967semicolons and zero or more whitespace characters. 968These patterns are evaluated from left to right with the final cursor position 969determined by the last search pattern. 970A 971.Cm z 972command may be appended to the closed search expressions to reposition the 973result line. 974.Pp 975.It Cm 0 976Move to the first character in the current line. 977.Pp 978.It Cm :\& 979Execute an 980.Nm ex 981command. 982.Pp 983.It Xo 984.Op Ar count 985.Cm ;\& 986.Xc 987Repeat the last character find 988(i.e. the last 989.Cm F , 990.Cm f , 991.Cm T 992or 993.Cm t 994command) 995.Ar count 996times. 997.Pp 998.It Xo 999.Op Ar count 1000.Cm < 1001.Ar motion 1002.Xc 1003.It Xo 1004.Op Ar count 1005.Cm > 1006.Ar motion 1007.Xc 1008Shift 1009.Ar count 1010lines left or right, respectively, by an amount of 1011.Cm shiftwidth . 1012.Pp 1013.It Cm @ Ar buffer 1014Execute a named 1015.Ar buffer 1016as 1017.Nm vi 1018commands. 1019The buffer may include 1020.Nm ex 1021commands too, but they must be expressed as a 1022.Cm \&: 1023command. 1024If 1025.Ar buffer 1026is 1027.Sq @ 1028or 1029.Sq * , 1030then the last buffer executed shall be used. 1031.Pp 1032.It Xo 1033.Op Ar count 1034.Cm A 1035.Xc 1036Enter input mode, appending the text after the end of the line. 1037If a 1038.Ar count 1039argument is given, 1040the characters input are repeated 1041.Ar count 1042\- 1 times after input mode is exited. 1043.Pp 1044.It Xo 1045.Op Ar count 1046.Cm B 1047.Xc 1048Move backwards 1049.Ar count 1050bigwords. 1051.Pp 1052.It Xo 1053.Op Ar buffer 1054.Cm C 1055.Xc 1056Change text from the current position to the end-of-line. 1057If 1058.Ar buffer 1059is specified, 1060.Dq yank 1061the deleted text into 1062.Ar buffer . 1063.Pp 1064.It Xo 1065.Op Ar buffer 1066.Cm D 1067.Xc 1068Delete text from the current position to the end-of-line. 1069If 1070.Ar buffer 1071is specified, 1072.Dq yank 1073the deleted text into 1074.Ar buffer . 1075.Pp 1076.It Xo 1077.Op Ar count 1078.Cm E 1079.Xc 1080Move forward 1081.Ar count 1082end-of-bigwords. 1083.Pp 1084.It Xo 1085.Op Ar count 1086.Cm F Aq Ar character 1087.Xc 1088Search 1089.Ar count 1090times backward through the current line for 1091.Ar character . 1092.Pp 1093.It Xo 1094.Op Ar count 1095.Cm G 1096.Xc 1097Move to line 1098.Ar count , 1099or the last line of the file if 1100.Ar count 1101is not specified. 1102.Pp 1103.It Xo 1104.Op Ar count 1105.Cm H 1106.Xc 1107Move to the screen line 1108.Ar count 1109\- 1 lines below the top of the screen. 1110.Pp 1111.It Xo 1112.Op Ar count 1113.Cm I 1114.Xc 1115Enter input mode, inserting the text at the beginning of the line. 1116If a 1117.Ar count 1118argument is given, 1119the characters input are repeated 1120.Ar count 1121\- 1 more times. 1122.Pp 1123.It Xo 1124.Op Ar count 1125.Cm J 1126.Xc 1127Join 1128.Ar count 1129lines with the current line. 1130The spacing between two joined lines is set to two whitespace characters if the 1131former ends with a question mark, a period or an exclamation mark. 1132It is set to one whitespace character otherwise. 1133.Pp 1134.It Xo 1135.Op Ar count 1136.Cm L 1137.Xc 1138Move to the screen line 1139.Ar count 1140\- 1 lines above the bottom of the screen. 1141.Pp 1142.It Cm M 1143Move to the screen line in the middle of the screen. 1144.Pp 1145.It Xo 1146.Op Ar count 1147.Cm O 1148.Xc 1149Enter input mode, appending text in a new line above the current line. 1150If a 1151.Ar count 1152argument is given, 1153the characters input are repeated 1154.Ar count 1155\- 1 more times. 1156.Pp 1157.It Xo 1158.Op Ar buffer 1159.Cm P 1160.Xc 1161Insert text from 1162.Ar buffer 1163before the current column if 1164.Ar buffer 1165is character-oriented or before the current line if it is line-oriented. 1166.Pp 1167.It Cm Q 1168Exit 1169.Nm vi 1170.Pq or visual 1171mode and switch to 1172.Nm ex 1173mode. 1174.Pp 1175.It Xo 1176.Op Ar count 1177.Cm R 1178.Xc 1179Enter input mode, replacing the characters in the current line. 1180If a 1181.Ar count 1182argument is given, 1183the characters input are repeated 1184.Ar count 1185\- 1 more times upon exit from insert mode. 1186.Pp 1187.It Xo 1188.Op Ar buffer 1189.Op Ar count 1190.Cm S 1191.Xc 1192Substitute 1193.Ar count 1194lines. 1195If 1196.Ar buffer 1197is specified, 1198.Dq yank 1199the deleted text into 1200.Ar buffer . 1201.Pp 1202.It Xo 1203.Op Ar count 1204.Cm T 1205.Aq Ar character 1206.Xc 1207Search backwards, 1208.Ar count 1209times, through the current line for the character after the specified 1210.Ar character . 1211.Pp 1212.It Cm U 1213Restore the current line to its state before the cursor last moved to it. 1214.Pp 1215.It Xo 1216.Op Ar count 1217.Cm W 1218.Xc 1219Move forward 1220.Ar count 1221bigwords. 1222.Pp 1223.It Xo 1224.Op Ar buffer 1225.Op Ar count 1226.Cm X 1227.Xc 1228Delete 1229.Ar count 1230characters before the cursor, on the current line. 1231If 1232.Ar buffer 1233is specified, 1234.Dq yank 1235the deleted text into 1236.Ar buffer . 1237.Pp 1238.It Xo 1239.Op Ar buffer 1240.Op Ar count 1241.Cm Y 1242.Xc 1243Copy (or 1244.Dq yank ) 1245.Ar count 1246lines into 1247.Ar buffer . 1248.Pp 1249.It Cm ZZ 1250Write the file and exit 1251.Nm vi 1252if there are no more files to edit. 1253Entering two 1254.Dq quit 1255commands in a row ignores any remaining file to edit. 1256.Pp 1257.It Xo 1258.Op Ar count 1259.Cm [[ 1260.Xc 1261Back up 1262.Ar count 1263section boundaries. 1264.Pp 1265.It Xo 1266.Op Ar count 1267.Cm ]] 1268.Xc 1269Move forward 1270.Ar count 1271section boundaries. 1272.Pp 1273.It Cm ^ 1274Move to the first non-blank character on the current line. 1275.Pp 1276.It Xo 1277.Op Ar count 1278.Cm _ 1279.Xc 1280Move down 1281.Ar count 1282\- 1 lines, to the first non-blank character. 1283.Pp 1284.It Xo 1285.Op Ar count 1286.Cm a 1287.Xc 1288Enter input mode, appending the text after the cursor. 1289If a 1290.Ar count 1291argument is given, 1292the characters input are repeated 1293.Ar count 1294\-1 more times. 1295.Pp 1296.It Xo 1297.Op Ar count 1298.Cm b 1299.Xc 1300Move backwards 1301.Ar count 1302words. 1303.Pp 1304.It Xo 1305.Op Ar buffer 1306.Op Ar count 1307.Cm c 1308.Ar motion 1309.Xc 1310Change the region of text described by 1311.Ar count 1312and 1313.Ar motion . 1314If 1315.Ar buffer 1316is specified, 1317.Dq yank 1318the changed text into 1319.Ar buffer . 1320.Pp 1321.It Xo 1322.Op Ar buffer 1323.Op Ar count 1324.Cm d 1325.Ar motion 1326.Xc 1327Delete the region of text described by 1328.Ar count 1329and 1330.Ar motion . 1331If 1332.Ar buffer 1333is specified, 1334.Dq yank 1335the deleted text into 1336.Ar buffer . 1337.Pp 1338.It Xo 1339.Op Ar count 1340.Cm e 1341.Xc 1342Move forward 1343.Ar count 1344end-of-words. 1345.Pp 1346.It Xo 1347.Op Ar count 1348.Cm f Aq Ar character 1349.Xc 1350Search forward, 1351.Ar count 1352times, through the rest of the current line for 1353.Aq Ar character . 1354.Pp 1355.It Xo 1356.Op Ar count 1357.Cm i 1358.Xc 1359Enter input mode, inserting the text before the cursor. 1360If a 1361.Ar count 1362argument is given, 1363the characters input are repeated 1364.Ar count 1365\-1 more times. 1366.Pp 1367.It Xo 1368.Cm m 1369.Aq Ar character 1370.Xc 1371Save the current context 1372.Pq line and column 1373as 1374.Aq Ar character . 1375.Pp 1376.It Xo 1377.Op Ar count 1378.Cm o 1379.Xc 1380Enter input mode, appending text in a new line under the current line. 1381If a 1382.Ar count 1383argument is given, 1384the characters input are repeated 1385.Ar count 1386\- 1 more times. 1387.Pp 1388.It Xo 1389.Op Ar buffer 1390.Cm p 1391.Xc 1392Append text from 1393.Ar buffer . 1394Text is appended after the current column if 1395.Ar buffer 1396is character oriented, or the after current line otherwise. 1397.Pp 1398.It Xo 1399.Op Ar count 1400.Cm r 1401.Aq Ar character 1402.Xc 1403Replace 1404.Ar count 1405characters by 1406.Ar character . 1407.Pp 1408.It Xo 1409.Op Ar buffer 1410.Op Ar count 1411.Cm s 1412.Xc 1413Substitute 1414.Ar count 1415characters in the current line starting with the current character. 1416If 1417.Ar buffer 1418is specified, 1419.Dq yank 1420the substituted text into 1421.Ar buffer . 1422.Pp 1423.It Xo 1424.Op Ar count 1425.Cm t 1426.Aq Ar character 1427.Xc 1428Search forward, 1429.Ar count 1430times, through the current line for the character immediately before 1431.Aq Ar character . 1432.Pp 1433.It Cm u 1434Undo the last change made to the file. 1435If repeated, the 1436.Cm u 1437command alternates between these two states. 1438The 1439.Cm .\& 1440command, when used immediately after 1441.Cm u , 1442causes the change log to be rolled forward or backward, depending on the action 1443of the 1444.Cm u 1445command. 1446.Pp 1447.It Xo 1448.Op Ar count 1449.Cm w 1450.Xc 1451Move forward 1452.Ar count 1453words. 1454.Pp 1455.It Xo 1456.Op Ar buffer 1457.Op Ar count 1458.Cm x 1459.Xc 1460Delete 1461.Ar count 1462characters at the current cursor position, but no more than there are till the 1463end of the line. 1464.Pp 1465.It Xo 1466.Op Ar buffer 1467.Op Ar count 1468.Cm y 1469.Ar motion 1470.Xc 1471Copy (or 1472.Dq yank ) 1473a text region specified by 1474.Ar count 1475and 1476.Ar motion 1477into a buffer. 1478.Pp 1479.It Xo 1480.Op Ar count1 1481.Cm z 1482.Op Ar count2 1483.Cm type 1484.Xc 1485Redraw, optionally repositioning and resizing the screen. 1486If 1487.Ar count2 1488is specified, limit the screen size to 1489.Ar count2 1490lines. 1491The following 1492.Cm type 1493characters may be used: 1494.Bl -tag -width Ds 1495.It Cm + 1496If 1497.Ar count1 1498is specified, place the line 1499.Ar count1 1500at the top of the screen. 1501Otherwise, display the screen after the current screen. 1502.It Aq Cm carriage-return 1503Place the line 1504.Ar count1 1505at the top of the screen. 1506.It Cm .\& 1507Place the line 1508.Ar count1 1509in the center of the screen. 1510.It Cm - 1511Place the line 1512.Ar count1 1513at the bottom of the screen. 1514.It Cm ^ 1515If 1516.Ar count1 1517is given, 1518display the screen before the screen before 1519.Ar count1 1520.Pq i.e. 2 screens before . 1521Otherwise, display the screen before the current screen. 1522.El 1523.Pp 1524.It Xo 1525.Op Ar count 1526.Cm {\& 1527.Xc 1528Move backward 1529.Ar count 1530paragraphs. 1531.Pp 1532.It Xo 1533.Op Ar column 1534.Cm |\& 1535.Xc 1536Move to a specific 1537.Ar column 1538position on the current line. 1539If 1540.Ar column 1541is omitted, 1542move to the start of the current line. 1543.Pp 1544.It Xo 1545.Op Ar count 1546.Cm }\& 1547.Xc 1548Move forward 1549.Ar count 1550paragraphs. 1551.Pp 1552.It Xo 1553.Op Ar count 1554.Cm ~ 1555.Ar motion 1556.Xc 1557If the 1558.Cm tildeop 1559option is not set, reverse the case of the next 1560.Ar count 1561character(s) and no 1562.Ar motion 1563can be specified. 1564Otherwise 1565.Ar motion 1566is mandatory and 1567.Cm ~ 1568reverses the case of the characters in a text region specified by the 1569.Ar count 1570and 1571.Ar motion . 1572.Pp 1573.It Aq Cm interrupt 1574Interrupt the current operation. 1575The 1576.Aq interrupt 1577character is usually 1578.Aq control-C . 1579.El 1580.Sh VI TEXT INPUT COMMANDS 1581The following section describes the commands available in the text input mode 1582of the 1583.Nm vi 1584editor. 1585.Pp 1586.Bl -tag -width Ds -compact 1587.It Aq Cm nul 1588Replay the previous input. 1589.Pp 1590.It Aq Cm control-D 1591Erase to the previous 1592.Ar shiftwidth 1593column boundary. 1594.Pp 1595.It Cm ^ Ns Aq Cm control-D 1596Erase all of the autoindent characters. 1597.Pp 1598.It Cm 0 Ns Aq Cm control-D 1599Erase all of the autoindent characters, and reset the autoindent level. 1600.Pp 1601.It Aq Cm control-T 1602Insert sufficient 1603.Aq tab 1604and 1605.Aq space 1606characters to move forward to the next 1607.Ar shiftwidth 1608column boundary. 1609If the 1610.Cm expandtab 1611option is set, only insert 1612.Aq space 1613characters. 1614.Pp 1615.It Aq Cm erase 1616.It Aq Cm control-H 1617Erase the last character. 1618.Pp 1619.It Aq Cm literal next 1620Escape the next character from any special meaning. 1621The 1622.Aq literal\ \&next 1623character is usually 1624.Aq control-V . 1625.Pp 1626.It Aq Cm escape 1627Resolve all text input into the file, and return to command mode. 1628.Pp 1629.It Aq Cm line erase 1630Erase the current line. 1631.Pp 1632.It Aq Cm control-W 1633.It Aq Cm word erase 1634Erase the last word. 1635The definition of word is dependent on the 1636.Cm altwerase 1637and 1638.Cm ttywerase 1639options. 1640.Pp 1641.Sm off 1642.It Xo 1643.Aq Cm control-X 1644.Bq Cm 0-9A-Fa-f 1645.Cm + 1646.Xc 1647.Sm on 1648Insert a character with the specified hexadecimal value into the text. 1649.Pp 1650.It Aq Cm interrupt 1651Interrupt text input mode, returning to command mode. 1652The 1653.Aq interrupt 1654character is usually 1655.Aq control-C . 1656.El 1657.Sh EX COMMANDS 1658The following section describes the commands available in the 1659.Nm ex 1660editor. 1661In each entry below, the tag line is a usage synopsis for the command. 1662.Pp 1663.Bl -tag -width Ds -compact 1664.It Aq Cm end-of-file 1665Scroll the screen. 1666.Pp 1667.It Cm !\& Ar argument(s) 1668.It Xo 1669.Op Ar range 1670.Cm !\& 1671.Ar argument(s) 1672.Xc 1673Execute a shell command, or filter lines through a shell command. 1674.Pp 1675.It Cm \&" 1676A comment. 1677.Pp 1678.It Xo 1679.Op Ar range 1680.Cm nu Ns Op Cm mber 1681.Op Ar count 1682.Op Ar flags 1683.Xc 1684.It Xo 1685.Op Ar range 1686.Cm # 1687.Op Ar count 1688.Op Ar flags 1689.Xc 1690Display the selected lines, each preceded with its line number. 1691.Pp 1692.It Cm @ Ar buffer 1693.It Cm * Ar buffer 1694Execute a buffer. 1695.Pp 1696.It Xo 1697.Op Ar range 1698.Cm < Ns Op Cm < ... 1699.Op Ar count 1700.Op Ar flags 1701.Xc 1702Shift lines left. 1703.Pp 1704.It Xo 1705.Op Ar line 1706.Cm = 1707.Op Ar flags 1708.Xc 1709Display the line number of 1710.Ar line . 1711If 1712.Ar line 1713is not specified, display the line number of the last line in the file. 1714.Pp 1715.It Xo 1716.Op Ar range 1717.Cm > Ns Op Cm > ... 1718.Op Ar count 1719.Op Ar flags 1720.Xc 1721Shift lines right. 1722.Pp 1723.It Xo 1724.Cm ab Ns Op Cm breviate 1725.Ar lhs rhs 1726.Xc 1727.Nm vi 1728only. 1729Add 1730.Ar lhs 1731as an abbreviation for 1732.Ar rhs 1733to the abbreviation list. 1734.Pp 1735.It Xo 1736.Op Ar line 1737.Cm a Ns Op Cm ppend Ns 1738.Op Cm !\& 1739.Xc 1740The input text is appended after the specified line. 1741.Pp 1742.It Cm ar Ns Op Cm gs 1743Display the argument list. 1744.Pp 1745.It Cm bg 1746.Nm vi 1747only. 1748Background the current screen. 1749.Pp 1750.It Xo 1751.Op Ar range 1752.Cm c Ns Op Cm hange Ns 1753.Op Cm !\& 1754.Op Ar count 1755.Xc 1756The input text replaces the specified range. 1757.Pp 1758.It Xo 1759.Cm chd Ns Op Cm ir Ns 1760.Op Cm !\& 1761.Op Ar directory 1762.Xc 1763.It Xo 1764.Cm cd Ns Op Cm !\& 1765.Op Ar directory 1766.Xc 1767Change the current working directory. 1768.Pp 1769.It Xo 1770.Op Ar range 1771.Cm co Ns Op Cm py 1772.Ar line 1773.Op Ar flags 1774.Xc 1775.It Xo 1776.Op Ar range 1777.Cm t 1778.Ar line 1779.Op Ar flags 1780.Xc 1781Copy the specified lines after the destination 1782.Ar line . 1783.Pp 1784.It Xo 1785.Op Ar range 1786.Cm d Ns Op Cm elete 1787.Op Ar buffer 1788.Op Ar count 1789.Op Ar flags 1790.Xc 1791Delete the lines from the file. 1792.Pp 1793.It Xo 1794.Cm di Ns Op Cm splay 1795.Cm b Ns Oo Cm uffers Oc | 1796.Cm s Ns Oo Cm creens Oc | 1797.Cm t Ns Op Cm ags 1798.Xc 1799Display buffers, screens or tags. 1800.Pp 1801.It Xo 1802.Cm e Ns Op Cm dit Ns | Ns Cm x Ns 1803.Op Cm !\& 1804.Op Ar +cmd 1805.Op Ar file 1806.Xc 1807Edit a different file. 1808.Pp 1809.It Xo 1810.Cm exu Ns Op Cm sage 1811.Op Ar command 1812.Xc 1813Display usage for an 1814.Nm ex 1815command. 1816.Pp 1817.It Xo 1818.Cm f Ns Op Cm ile 1819.Op Ar file 1820.Xc 1821Display and optionally change the file name. 1822.Pp 1823.It Cm fg Op Ar name 1824.Nm vi 1825only. 1826Foreground the specified screen. 1827.Pp 1828.It Xo 1829.Op Ar range 1830.Cm g Ns Op Cm lobal 1831.No / Ns Ar pattern Ns / 1832.Op Ar commands 1833.Xc 1834.It Xo 1835.Op Ar range 1836.Cm v 1837.No / Ns Ar pattern Ns / 1838.Op Ar commands 1839.Xc 1840Apply commands to lines matching 1841.Pq Sq global 1842or not matching 1843.Pq Sq v 1844a pattern. 1845.Pp 1846.It Cm he Ns Op Cm lp 1847Display a help message. 1848.Pp 1849.It Xo 1850.Op Ar line 1851.Cm i Ns Op Cm nsert Ns 1852.Op Cm !\& 1853.Xc 1854The input text is inserted before the specified line. 1855.Pp 1856.It Xo 1857.Op Ar range 1858.Cm j Ns Op Cm oin Ns 1859.Op Cm !\& 1860.Op Ar count 1861.Op Ar flags 1862.Xc 1863Join lines of text together. 1864.Pp 1865.It Xo 1866.Op Ar range 1867.Cm l Ns Op Cm ist 1868.Op Ar count 1869.Op Ar flags 1870.Xc 1871Display the lines unambiguously. 1872.Pp 1873.It Xo 1874.Cm map Ns Op Cm !\& 1875.Op Ar lhs rhs 1876.Xc 1877.Nm vi 1878only. 1879Define or display maps. 1880.Pp 1881.It Xo 1882.Op Ar line 1883.Cm ma Ns Op Cm rk 1884.Aq Ar character 1885.Xc 1886.It Xo 1887.Op Ar line 1888.Cm k Aq Ar character 1889.Xc 1890Mark the line with the mark 1891.Aq Ar character . 1892.Pp 1893.It Xo 1894.Op Ar range 1895.Cm m Ns Op Cm ove 1896.Ar line 1897.Xc 1898Move the specified lines after the target line. 1899.Pp 1900.It Xo 1901.Cm mk Ns Op Cm exrc Ns 1902.Op Cm !\& 1903.Ar file 1904.Xc 1905Write the abbreviations, editor options and maps to the specified 1906.Ar file . 1907.Pp 1908.It Xo 1909.Cm n Ns Op Cm ext Ns 1910.Op Cm !\& 1911.Op Ar file ... 1912.Xc 1913Edit the next file from the argument list. 1914.\" .Pp 1915.\" .It Xo 1916.\" .Op Ar line 1917.\" .Cm o Ns Op Cm pen 1918.\" .No / Ns Ar pattern Ns / 1919.\" .Op Ar flags 1920.\" .Xc 1921.\" Enter open mode. 1922.Pp 1923.It Cm pre Ns Op Cm serve 1924Save the file in a form that can later be recovered using the 1925.Nm ex 1926.Fl r 1927option. 1928.Pp 1929.It Cm prev Ns Oo Cm ious Oc Ns Op Cm !\& 1930Edit the previous file from the argument list. 1931.Pp 1932.It Xo 1933.Op Ar range 1934.Cm p Ns Op Cm rint 1935.Op Ar count 1936.Op Ar flags 1937.Xc 1938Display the specified lines. 1939.Pp 1940.It Xo 1941.Op Ar line 1942.Cm pu Ns Op Cm t 1943.Op Ar buffer 1944.Xc 1945Append buffer contents to the current line. 1946.Pp 1947.It Xo 1948.Cm q Ns Op Cm uit Ns 1949.Op Cm !\& 1950.Xc 1951End the editing session. 1952In split-screen mode, only close the current screen 1953and switch to the previous one. 1954.Pp 1955.It Xo 1956.Op Ar line 1957.Cm r Ns Op Cm ead Ns 1958.Op Cm !\& 1959.Op Ar file 1960.Xc 1961Read a file. 1962.Pp 1963.It Xo 1964.Cm rec Ns Op Cm over 1965.Ar file 1966.Xc 1967Recover 1968.Ar file 1969if it was previously saved. 1970.Pp 1971.It Xo 1972.Cm res Ns Op Cm ize 1973.Op Cm + Ns | Ns Cm - Ns 1974.Ar lines 1975.Xc 1976.Nm vi 1977mode only. 1978Grow or shrink the current screen. 1979.Pp 1980.It Xo 1981.Cm rew Ns Op Cm ind Ns 1982.Op Cm !\& 1983.Xc 1984Rewind the argument list. 1985.Pp 1986.It Xo 1987.Op Ar range 1988.Sm off 1989.Cm s 1990.Oo Cm / Ar pattern Cm / Ar replace Cm / 1991.Op Ar options 1992.Op Ar count 1993.Op Ar flags 1994.Oc 1995.Sm on 1996.Xc 1997.It Xo 1998.Op Ar range 1999.Sm off 2000.Cm & 2001.Op Ar options 2002.Op Ar count 2003.Op Ar flags 2004.Sm on 2005.Xc 2006.It Xo 2007.Op Ar range 2008.Sm off 2009.Cm ~ 2010.Op Ar options 2011.Op Ar count 2012.Op Ar flags 2013.Sm on 2014.Xc 2015Substitute the regular expression 2016.Ar pattern 2017with 2018.Ar replace . 2019When invoked as 2020.Cm & , 2021or if 2022.Cm / Ns Ar pattern Ns Cm / Ns Ar replace Ns Cm / 2023is omitted, 2024.Ar pattern 2025and 2026.Ar replace 2027from the most recent 2028.Cm s 2029command are used. 2030.Cm ~ 2031behaves like 2032.Cm & , 2033except the pattern used is the most recent regular expression used by any 2034command. 2035.Pp 2036The 2037.Ar replace 2038field may contain any of the following sequences: 2039.Bl -tag -width Ds 2040.It Sq & 2041The text matched by 2042.Ar pattern . 2043.It Sq \(a~ 2044The replacement part of the previous 2045.Cm s 2046command. 2047.It Sq % 2048If this is the entire 2049.Ar replace 2050pattern, the replacement part of the previous 2051.Cm s 2052command. 2053.It Sq \e# 2054Where 2055.Sq # 2056is an integer from 1 to 9, the text matched by the #'th subexpression in 2057.Ar pattern . 2058.It Sq \eL 2059Causes the characters up to the end of the line of the next occurrence of 2060.Sq \eE 2061or 2062.Sq \ee 2063to be converted to lowercase. 2064.It Sq \el 2065Causes the next character to be converted to lowercase. 2066.It Sq \eU 2067Causes the characters up to the end of the line of the next occurrence of 2068.Sq \eE 2069or 2070.Sq \ee 2071to be converted to uppercase. 2072.It Sq \eu 2073Causes the next character to be converted to uppercase. 2074.El 2075.Pp 2076The 2077.Ar options 2078field may contain any of the following characters: 2079.Bl -tag -width Ds 2080.It Sq c 2081Prompt for confirmation before each replacement is done. 2082.It Sq g 2083Replace all instances of 2084.Ar pattern 2085in a line, not just the first. 2086.El 2087.Pp 2088.It Xo 2089.Cm se Ns Op Cm t 2090.Sm off 2091.Op option Oo = Oo value Oc Oc \ \&... 2092.Sm on 2093.Pf \ \& Op nooption ... 2094.Op option? ... 2095.Op Ar all 2096.Xc 2097Display or set the editor options described in 2098.Sx SET OPTIONS . 2099.Pp 2100.It Cm sh Ns Op Cm ell 2101Run a shell program. 2102.Pp 2103.It Xo 2104.Cm so Ns Op Cm urce 2105.Ar file 2106.Xc 2107Read and execute 2108.Nm ex 2109commands from a file. 2110.Pp 2111.It Xo 2112.Cm su Ns Op Cm spend Ns 2113.Op Cm !\& 2114.Xc 2115.It Xo 2116.Cm st Ns Op Cm op Ns 2117.Op Cm !\& 2118.Xc 2119.It Aq Cm suspend 2120Suspend the edit session. 2121The 2122.Aq suspend 2123character is usually 2124.Aq control-Z . 2125.Pp 2126.It Xo 2127.Cm ta Ns Op Cm g Ns 2128.Op Cm !\& 2129.Ar tagstring 2130.Xc 2131Edit the file containing the specified tag. 2132.Pp 2133.It Xo 2134.Cm tagn Ns Op Cm ext Ns 2135.Op Cm !\& 2136.Xc 2137Edit the file containing the next context for the current tag. 2138.Pp 2139.It Xo 2140.Cm tagp Ns Op Cm op Ns 2141.Op Cm !\& 2142.Op Ar file | number 2143.Xc 2144Pop to the specified tag in the tags stack. 2145.Pp 2146.It Xo 2147.Cm tagpr Ns Op Cm ev Ns 2148.Op Cm !\& 2149.Xc 2150Edit the file containing the previous context for the current tag. 2151.Pp 2152.It Xo 2153.Cm tagt Ns Op Cm op Ns 2154.Op Cm !\& 2155.Xc 2156Pop to the least recent tag on the tags stack, clearing the stack. 2157.Pp 2158.It Xo 2159.Cm una Ns Op Cm bbreviate 2160.Ar lhs 2161.Xc 2162.Nm vi 2163only. 2164Delete an abbreviation. 2165.Pp 2166.It Cm u Ns Op Cm ndo 2167Undo the last change made to the file. 2168.Pp 2169.It Xo 2170.Cm unm Ns Op Cm ap Ns 2171.Op Cm !\& 2172.Ar lhs 2173.Xc 2174Unmap a mapped string. 2175.Pp 2176.It Cm ve Ns Op Cm rsion 2177Display the version of the 2178.Nm ex Ns / Ns Nm vi 2179editor. 2180.Pp 2181.It Xo 2182.Op Ar line 2183.Cm vi Ns Op Cm sual 2184.Op Ar type 2185.Op Ar count 2186.Op Ar flags 2187.Xc 2188.Nm ex 2189only. 2190Enter 2191.Nm vi . 2192.Pp 2193.It Xo 2194.Cm vi Ns Op Cm sual Ns 2195.Op Cm !\& 2196.Op Ar +cmd 2197.Op Ar file 2198.Xc 2199.Nm vi 2200only. 2201Edit a new file. 2202.Pp 2203.It Xo 2204.Cm viu Ns Op Cm sage 2205.Op Ar command 2206.Xc 2207Display usage for a 2208.Nm vi 2209command. 2210.Pp 2211.It Xo 2212.Op Ar range 2213.Cm w Ns Op Cm rite Ns 2214.Op Cm !\& 2215.Op >> 2216.Op Ar file 2217.Xc 2218Write the file. 2219.Pp 2220.It Xo 2221.Op Ar range 2222.Cm wn Ns Op Cm !\& 2223.Op >> 2224.Op Ar file 2225.Xc 2226Write the file and edit the next file from the argument list. 2227.Pp 2228.It Xo 2229.Op Ar range 2230.Cm wq Ns Op Cm !\& 2231.Op >> 2232.Op Ar file 2233.Xc 2234Write the file and exit the editor. 2235In split-screen mode, close the current screen 2236and switch to the previous one. 2237.Pp 2238.It Xo 2239.Op Ar range 2240.Cm x Ns Op Cm it Ns 2241.Op Cm !\& 2242.Op Ar file 2243.Xc 2244Exit the editor, 2245writing the file if it has been modified. 2246In split-screen mode, close the current screen 2247and switch to the previous one. 2248.Pp 2249.It Xo 2250.Op Ar range 2251.Cm ya Ns Op Cm nk 2252.Op Ar buffer 2253.Op Ar count 2254.Xc 2255Copy the specified lines to a buffer. 2256.Pp 2257.It Xo 2258.Op Ar line 2259.Cm z 2260.Op Ar type 2261.Op Ar count 2262.Op Ar flags 2263.Xc 2264Adjust the window. 2265.El 2266.Pp 2267For 2268.Cm e , 2269.Cm fg , 2270.Cm n , 2271.Cm prev , 2272.Cm ta , 2273and 2274.Cm vi , 2275if the first letter of the command is capitalized, the current screen is 2276split and the new file is displayed in addition to the current screen. 2277This feature is only available in 2278.Nm vi , 2279not in 2280.Nm ex . 2281.Sh SET OPTIONS 2282There are a large number of options that can 2283change the editor's behavior, 2284using the 2285.Cm set 2286command. 2287This section describes the options, their abbreviations and their 2288default values. 2289.Pp 2290In each entry below, the first part of the tag line is the full name 2291of the option, followed by any equivalent abbreviations. 2292The part in square brackets is the default value of the option. 2293Most of the options are boolean, i.e. they are either on or off, 2294and do not have an associated value. 2295.Pp 2296Options apply to both 2297.Nm ex 2298and 2299.Nm vi 2300modes, unless otherwise specified. 2301.Bl -tag -width Ds 2302.It Cm altwerase Bq off 2303.Nm vi 2304only. 2305Select an alternate word erase algorithm. 2306.It Cm autoindent , ai Bq off 2307Automatically indent new lines. 2308.It Cm autoprint , ap Bq on 2309.Nm ex 2310only. 2311Display the current line automatically. 2312.It Cm autowrite , aw Bq off 2313Write modified files automatically when changing files or suspending the editor 2314session. 2315.It Cm backup Bq \&"\&" 2316Back up files before they are overwritten. 2317.It Cm beautify , bf Bq off 2318Discard control characters. 2319.It Cm cdpath Bq "environment variable CDPATH, or current directory" 2320The directory paths used as path prefixes for the 2321.Cm cd 2322command. 2323.It Cm cedit Bq no default 2324Set the character to edit the colon command-line history. 2325.It Cm columns , co Bq 80 2326Set the number of columns in the screen. 2327.It Cm comment Bq off 2328.Nm vi 2329only. 2330Skip leading comments in shell, C and C++ language files. 2331.It Cm edcompatible , ed Bq off 2332Remember the values of the 2333.Sq c 2334and 2335.Sq g 2336suffixes to the 2337.Cm s , & 2338and 2339.Cm ~ 2340commands, instead of initializing them as unset for each new command. 2341.It Cm escapetime Bq 1 2342The tenths of a second 2343.Nm ex Ns / Ns Nm vi 2344waits for a subsequent key to complete an 2345.Aq escape 2346key mapping. 2347.It Cm errorbells , eb Bq off 2348.Nm ex 2349only. 2350Announce error messages with a bell. 2351.It Cm expandtab , et Bq off 2352Expand 2353.Aq tab 2354characters to 2355.Aq space 2356when inserting, replacing or shifting text, autoindenting, 2357indenting with 2358.Aq Ic control-T , 2359outdenting with 2360.Aq Ic control-D , 2361or 2362when filtering lines with the 2363.Cm !\& 2364command. 2365.It Cm exrc , ex Bq off 2366Read the startup files in the local directory. 2367.It Cm extended Bq off 2368Use extended regular expressions 2369.Pq EREs 2370rather than basic regular expressions 2371.Pq BREs . 2372See 2373.Xr re_format 7 2374for more information on regular expressions. 2375.It Cm filec Bq Aq tab 2376Set the character to perform file path completion on the colon command line. 2377.It Cm flash Bq off 2378Flash the screen instead of beeping the keyboard on error. 2379.It Cm hardtabs , ht Bq 0 2380Set the spacing between hardware tab settings. 2381This option currently has no effect. 2382.It Cm iclower Bq off 2383Makes all regular expressions case-insensitive, 2384as long as an upper-case letter does not appear in the search string. 2385.It Cm ignorecase , ic Bq off 2386Ignore case differences in regular expressions. 2387.It Cm keytime Bq 6 2388The tenths of a second 2389.Nm ex Ns / Ns Nm vi 2390waits for a subsequent key to complete a key mapping. 2391.It Cm leftright Bq off 2392.Nm vi 2393only. 2394Do left-right scrolling. 2395.It Cm lines , li Bq 24 2396.Nm vi 2397only. 2398Set the number of lines in the screen. 2399.It Cm list Bq off 2400Display lines in an unambiguous fashion. 2401.It Cm lock Bq on 2402Attempt to get an exclusive lock on any file being edited, read or written. 2403.It Cm magic Bq on 2404When turned off, all regular expression characters except for 2405.Sq ^ 2406and 2407.Sq $ 2408are treated as ordinary characters. 2409Preceding individual characters by 2410.Sq \e 2411re-enables them. 2412.It Cm matchtime Bq 7 2413.Nm vi 2414only. 2415The tenths of a second 2416.Nm ex Ns / Ns Nm vi 2417pauses on the matching character when the 2418.Cm showmatch 2419option is set. 2420.It Cm mesg Bq on 2421Permit messages from other users. 2422.It Cm noprint Bq \&"\&" 2423Characters that are never handled as printable characters. 2424.It Cm number , nu Bq off 2425Precede each line displayed with its current line number. 2426.It Cm octal Bq off 2427Display unknown characters as octal numbers, instead of the default 2428hexadecimal. 2429.It Cm open Bq on 2430.Nm ex 2431only. 2432If this option is not set, the 2433.Cm open 2434and 2435.Cm visual 2436commands are disallowed. 2437.It Cm paragraphs , para Bq "IPLPPPQPP LIpplpipbpBlBdPpLpIt" 2438.Nm vi 2439only. 2440Define additional paragraph boundaries for the 2441.Cm {\& 2442and 2443.Cm }\& 2444commands. 2445.It Cm path Bq \&"\&" 2446Define additional directories to search for files being edited. 2447.It Cm print Bq \&"\&" 2448Characters that are always handled as printable characters. 2449.It Cm prompt Bq on 2450.Nm ex 2451only. 2452Display a command prompt. 2453.It Cm readonly , ro Bq off 2454Mark the file and session as read-only. 2455.It Cm recdir Bq /tmp/vi.recover 2456The directory where recovery files are stored. 2457.It Cm remap Bq on 2458Remap keys until resolved. 2459.It Cm report Bq 5 2460Set the number of lines about which the editor reports changes or yanks. 2461.It Cm ruler Bq off 2462.Nm vi 2463only. 2464Display a row/column/percentage ruler on the colon command line. 2465.It Cm scroll , scr Bq "($LINES \- 1) / 2" 2466Set the number of lines scrolled. 2467.It Cm searchincr Bq off 2468Makes the 2469.Cm / 2470and 2471.Cm ?\& 2472commands incremental. 2473.It Cm sections , sect Bq "NHSHH HUnhshShSs" 2474.Nm vi 2475only. 2476Define additional section boundaries for the 2477.Cm [[ 2478and 2479.Cm ]] 2480commands. 2481.It Cm secure 2482Turns off all access to external programs. 2483Once set, this option can't be disabled. 2484.It Cm shell , sh Bq "environment variable SHELL, or /bin/sh" 2485Select the shell used by the editor. 2486.It Cm shellmeta Bq ~{[*?$`'\&"\e 2487Set the meta characters checked to determine if file name expansion 2488is necessary. 2489.It Cm shiftwidth , sw Bq 8 2490Set the autoindent and shift command indentation width. 2491.It Cm showfilename Bq off 2492.Nm vi 2493only. 2494Display the file name on the colon command line. 2495.It Cm showmatch , sm Bq off 2496.Nm vi 2497only. 2498Note matching 2499.Sq { 2500and 2501.Sq \&( 2502for 2503.Sq } 2504and 2505.Sq )\& 2506characters. 2507.It Cm showmode , smd Bq off 2508.Nm vi 2509only. 2510Display the current editor mode and a 2511.Dq modified 2512flag. 2513.It Cm sidescroll Bq 16 2514.Nm vi 2515only. 2516Set the amount a left-right scroll will shift. 2517.It Cm tabstop , ts Bq 8 2518This option sets tab widths for the editor display. 2519.It Cm taglength , tl Bq 0 2520Set the number of significant characters in tag names. 2521.It Cm tags , tag Bq tags 2522Set the list of tags files. 2523.It Xo 2524.Cm term , ttytype , tty 2525.Bq "environment variable TERM" 2526.Xc 2527Set the terminal type. 2528.It Cm terse Bq off 2529This option has historically made editor messages less verbose. 2530It has no effect in this implementation. 2531.It Cm tildeop Bq off 2532Modify the 2533.Cm ~ 2534command to take an associated motion. 2535.It Cm timeout , to Bq on 2536Time out on keys which may be mapped. 2537.It Cm ttywerase Bq off 2538.Nm vi 2539only. 2540Select an alternate erase algorithm. 2541.It Cm verbose Bq off 2542.Nm vi 2543only. 2544Display an error message for every error. 2545.It Cm w300 Bq no default 2546.Nm vi 2547only. 2548Set the window size if the baud rate is less than 1200 baud. 2549.It Cm w1200 Bq no default 2550.Nm vi 2551only. 2552Set the window size if the baud rate is equal to 1200 baud. 2553.It Cm w9600 Bq no default 2554.Nm vi 2555only. 2556Set the window size if the baud rate is greater than 1200 baud. 2557.It Cm warn Bq on 2558.Nm ex 2559only. 2560This option causes a warning message to be printed on the terminal 2561if the file has been modified since it was last written, before a 2562.Cm !\& 2563command. 2564.It Xo 2565.Cm window , w , wi 2566.Bq "environment variable LINES \- 1" 2567.Xc 2568Set the window size for the screen. 2569.It Cm windowname Bq off 2570Change the icon/window name to the current file name even if it can't 2571be restored on editor exit. 2572.It Cm wraplen , wl Bq 0 2573.Nm vi 2574only. 2575Break lines automatically, 2576the specified number of columns from the left-hand margin. 2577If both the 2578.Cm wraplen 2579and 2580.Cm wrapmargin 2581edit options are set, the 2582.Cm wrapmargin 2583value is used. 2584.It Cm wrapmargin , wm Bq 0 2585.Nm vi 2586only. 2587Break lines automatically, 2588the specified number of columns from the right-hand margin. 2589If both the 2590.Cm wraplen 2591and 2592.Cm wrapmargin 2593edit options are set, the 2594.Cm wrapmargin 2595value is used. 2596.It Cm wrapscan , ws Bq on 2597Set searches to wrap around the end or beginning of the file. 2598.It Cm writeany , wa Bq off 2599Turn off file-overwriting checks. 2600.El 2601.Sh ENVIRONMENT 2602.Bl -tag -width "COLUMNS" 2603.It Ev COLUMNS 2604The number of columns on the screen. 2605This value overrides any system or terminal specific values. 2606If the 2607.Ev COLUMNS 2608environment variable is not set when 2609.Nm ex Ns / Ns Nm vi 2610runs, or the 2611.Cm columns 2612option is explicitly reset by the user, 2613.Nm ex Ns / Ns Nm vi 2614enters the value into the environment. 2615.It Ev EXINIT 2616A list of 2617.Nm ex 2618startup commands, read after 2619.Pa /etc/vi.exrc 2620unless the variable 2621.Ev NEXINIT 2622is also set. 2623.It Ev HOME 2624The user's home directory, used as the initial directory path for the startup 2625.Pa $HOME/.nexrc 2626and 2627.Pa $HOME/.exrc 2628files. 2629This value is also used as the default directory for the 2630.Nm vi 2631.Cm cd 2632command. 2633.It Ev LINES 2634The number of rows on the screen. 2635This value overrides any system or terminal specific values. 2636If the 2637.Ev LINES 2638environment variable is not set when 2639.Nm ex Ns / Ns Nm vi 2640runs, or the 2641.Cm lines 2642option is explicitly reset by the user, 2643.Nm ex Ns / Ns Nm vi 2644enters the value into the environment. 2645.It Ev NEXINIT 2646A list of 2647.Nm ex 2648startup commands, read after 2649.Pa /etc/vi.exrc . 2650.It Ev SHELL 2651The user's shell of choice (see also the 2652.Cm shell 2653option). 2654.It Ev TERM 2655The user's terminal type. 2656The default is the type 2657.Dq unknown . 2658If the 2659.Ev TERM 2660environment variable is not set when 2661.Nm ex Ns / Ns Nm vi 2662runs, or the 2663.Cm term 2664option is explicitly reset by the user, 2665.Nm ex Ns / Ns Nm vi 2666enters the value into the environment. 2667.El 2668.Sh ASYNCHRONOUS EVENTS 2669.Bl -tag -width "SIGWINCH" -compact 2670.It Dv SIGALRM 2671.Nm vi Ns / Ns Nm ex 2672uses this signal for periodic backups of file modifications and to display 2673.Dq busy 2674messages when operations are likely to take a long time. 2675.Pp 2676.It Dv SIGHUP 2677.It Dv SIGTERM 2678If the current buffer has changed since it was last written in its entirety, 2679the editor attempts to save the modified file so it can be later recovered. 2680See the 2681.Nm vi Ns / Ns Nm ex 2682reference manual section 2683.Sx Recovery 2684for more information. 2685.Pp 2686.It Dv SIGINT 2687When an interrupt occurs, the current operation is halted 2688and the editor returns to the command level. 2689If interrupted during text input, 2690the text already input is resolved into the file as if the text 2691input had been normally terminated. 2692.Pp 2693.It Dv SIGWINCH 2694The screen is resized. 2695See the 2696.Nm vi Ns / Ns Nm ex 2697reference manual section 2698.Sx Sizing the Screen 2699for more information. 2700.\" .Pp 2701.\" .It Dv SIGCONT 2702.\" .It Dv SIGTSTP 2703.\" .Nm vi Ns / Ns Nm ex 2704.\" ignores these signals. 2705.El 2706.Sh FILES 2707.Bl -tag -width "/tmp/vi.recover" 2708.It Pa /bin/sh 2709The default user shell. 2710.It Pa /etc/vi.exrc 2711System-wide 2712.Nm vi 2713startup file. 2714It is read for 2715.Nm ex 2716commands first in the startup sequence. 2717Must be owned by root or the user, 2718and writable only by the owner. 2719.It Pa /tmp 2720Temporary file directory. 2721.It Pa /tmp/vi.recover 2722The default recovery file directory. 2723.It Pa $HOME/.nexrc 2724First choice for user's home directory startup file, read for 2725.Nm ex 2726commands right after 2727.Pa /etc/vi.exrc 2728unless either 2729.Ev NEXINIT 2730or 2731.Ev EXINIT 2732are set. 2733Must be owned by root or the user, 2734and writable only by the owner. 2735.It Pa $HOME/.exrc 2736Second choice for user's home directory startup file, read for 2737.Nm ex 2738commands under the same conditions as 2739.Pa $HOME/.nexrc . 2740.It Pa .nexrc 2741First choice for local directory startup file, read for 2742.Nm ex 2743commands at the end of the startup sequence if the 2744.Cm exrc 2745option was turned on earlier. 2746Must be owned by the user 2747and writable only by the owner. 2748.It Pa .exrc 2749Second choice for local directory startup file, read for 2750.Nm ex 2751commands under the same conditions as 2752.Pa .nexrc . 2753.El 2754.Sh EXIT STATUS 2755The 2756.Nm ex 2757and 2758.Nm vi 2759utilities exit 0 on success, 2760and >0 if an error occurs. 2761.Sh SEE ALSO 2762.Xr ctags 1 , 2763.Xr re_format 7 2764.Rs 2765.\" 4.4BSD USD:12 2766.%T \&An Introduction to Display Editing with Vi 2767.Re 2768.\".Rs 2769.\" 4.4BSD USD:13 2770.\".%T Ex Reference Manual 2771.\".Re 2772.Sh STANDARDS 2773.Nm nex Ns / Ns Nm nvi 2774is close to 2775.St -p1003.1-2008 . 2776It deviates in the following respects: 2777.Bl -bullet 2778.It 2779The 2780.Ic s 2781.Nm ex 2782command may not be called as 2783.Ic substitute . 2784.It 2785The 2786.Ic directory , redraw 2787and 2788.Ic slowopen 2789settings are not implemented. 2790.It 2791The 2792.Ic paragraphs 2793and 2794.Ic sections 2795settings default to values useful for editing 2796.Xr mdoc 7 2797manuals. 2798.It 2799The 2800.Ev TMPDIR 2801environment variable is ignored. 2802.It 2803In insert mode, entering 2804.Aq Ic control-H , 2805.Aq Ic erase , 2806or 2807.Aq Ic kill 2808following a backslash will not embed the control character in the text. 2809.El 2810.Sh HISTORY 2811The 2812.Nm ex 2813editor first appeared in 2814.Bx 1 . 2815The 2816.Nm nex Ns / Ns Nm nvi 2817replacements for the 2818.Nm ex Ns / Ns Nm vi 2819editor first appeared in 2820.Bx 4.4 . 2821.Sh AUTHORS 2822.An Bill Joy 2823wrote the original version of 2824.Nm ex 2825in 1977. 2826