Plesk

How to edit a file using the vi utility on Linux

Question

How to edit a file using the vi utility on Linux?

Answer

  1. Connect to a Plesk server via SSH.

  2. Install the improved vi text editor:

    • for CentOS/RHEL-based distributions

      # yum install vim -y

    • for Debian/Ubuntu-based distributions

      # apt-get install vim -y

  3. Start editing a required file by typing:

    Note: If there is no such file, 'vi' will create a new one.

    # vi /some_directory/file_name

  4. In the text editor, press computer's i key to edit the file. 
    Doing so will place a document in the "Insert" mode, wherein it is possible to enter text as needed.
    You should see -- INSERT -- popup notification at the bottom of the window after pressing the i key.

    This is a new file▐
    ~
    ~
    ~
    ~
    -- INSERT --

  5. After editing the required string or pasting the text, press the Esc button.
    This key will place Vim in the "Command" mode. To save the file, type :w and to exit - :q

    This is a new file
    ~
    ~
    ~
    ~
    :w

    This is a new file
    ~
    ~
    ~
    ~
    :q

    Also, it is possible to save and exit by typing :wq

  6. To discard the changes, type :q!

    This is a new file
    ~
    ~
    ~
    ~
    :q!

Exit mobile version