If you can see this check that

next section prev section up prev page next page

vi example

  1.  % vi text_file
    
    You should see the following screen with the cursor at the top left.
    _                                                                
    ~                                
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    "test_file" [New file]
    The "~" character in the window indicates that that line currently does not exist. As the file is new no line exists, so this image gives you an idea what an empty file looks like in vi.
  2. Press i (insert before the cursor) to start entering text. This places you in text input mode. The screen does not change and you do not press return after pressing i.
  3. Type the following sample text. include the mistakes; you will correct them later. If you type a mistake that is not in the sample, use the backspace key to move back over the incorrect text, and then retype it.
    
    As you add text,
    the lines wit the tilde characters
    will scroll down towards
    the botom of the screeen.
    
    
  4. Press ESC (escape key). Pressing ESC enters you into command mode, which means you can no longer enter text; instead you can command the cursor to move within the file.
  5. Type :wq followed by return. Typing a colon while in command mode opens a command line at the bottom of your screen. When you type the wq command the w writes test_file to the disk, and the q tells vi to quit.
  6. Re-enter test_file to correct the mistakes as follows:
    
    % vi test_file
    
    
    The command is the same as before, but instead of opening a new test file, vi finds the existing file test_file. The screen clears and you should see the following:
    As you add text,                                                                
    the lines wit the tilde characters
    will scroll down towards
    the botom of the screeen.
    ~
    ~
    ~
    ~
    ~
    ~
    ~
    "test_file" 4 lines, 103 characters

To correct the two mistakes in the fourth line ("botom" and "screeen"), execute the following:

  1. Press j three times to move the cursor down to the first character in the forth line.
  2. Press l (lowercase L) several times to move the cursor right until the cursor is at the 't' in botom. If you pass 't', press h to move the cursor left.
  3. Press i to insert text before the cursor, and type 't' to spell bottom correctly.
  4. Press ESC to end the text input mode and return you to the command mode.

Next, correct "screeen" which is also in the fourth line:

  1. Press l until the cursor is at the first e in screen.
  2. Press x to delete the extra e. If you make a mistake, such as deleting more than one character, press U (uppercase U) to undo the changes you made. After deleting text you do not have to press ESC as you have not left the command mode.

Now, correct the mistake 'wit' in the second line:

  1. Press k twice to move the cursor up to the second line. Press h to move the cursor left. Position the cursor at the 't' in wit. If you pass the 't', press l to move the cursor right.
  2. Press a to append text. Pressing a exists command mode, so whatever you type is added to the text.
  3. Type h to spell 'with' correctly.
  4. Press ESC to return to the command mode.
  5. You now have corrected the mistakes in text_file and can now exit vi in one of two ways:
    :wq
    To exit vi and save the corrections
    :q!
    To exit vi without saving the corrections

Centos 7 intro: Paths | BasicShell | Search
Linux tutorials: intro1 intro2 wildcard permission pipe vi essential admin net SELinux1 SELinux2 fwall DNS diag Apache1 Apache2 log Mail
Caine 10.0: Essentials | Basic | Search | Acquisition | SysIntro | grep | MBR | GPT | FAT | NTFS | FRMeta | FRTools | Browser | Mock Exam |
CPD: Cygwin | Paths | Files and head/tail | Find and regex | Sort | Log Analysis
Kali: 1a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7a | 8a | 8b | 9 | 10 |
Kali 2020-4: 1a | 1b | 1c | 2 | 3 | 4a | 4b | 5 | 6 | 7 | 8a | 8b | 9 | 10 |
Useful: Quiz | Forums | Privacy Policy | Terms and Conditions

Linuxzoo created by Gordon Russell.
@ Copyright 2004-2023 Edinburgh Napier University