Editing files on an ESXi host using vi
search cancel

Editing files on an ESXi host using vi

book

Article ID: 345284

calendar_today

Updated On:

Products

VMware vSphere ESXi

Issue/Introduction

This article provides steps for editing files on an ESXi host by using vi.

Environment

VMware vSphere ESXi 6.x

VMware vSphere ESXi 7.x

VMware vSphere ESXi 8.x

Resolution

 

Editing using vi

To add an entry for another ESXi host at IP <IPaddress> and FQDN into the /etc/hosts file using vi:
  1. Login to SSH session for the ESXi host
  2. Type vi /etc/hosts and press Enter. Now you are in the vi text editor. You can move around using page up, page down, and the arrow keys.
  3. Move down to the last line in the file.
  4. Enter insert mode.

    You can press i to start editing where the cursor is, you can also press shift+o to start editing on a new line above the cursor, or o to start editing on a new line below the cursor.

    You see -- INSERT -- at the bottom of the vi window while you are in insert mode within vi.
     
  5. Add your entry.

    Note: The number pad on the keyboard does not work within vi by default. Use the numbers above the letters on your keyboard. You can use the arrow, backspace, and delete keys as well as enter text while in edit mode.
     
  6. To quit and save changes press Esc, :, w, q, then press Enter.

    If you decide you are not comfortable with the changes and want to quit without saving, press Esc, :, q, then press Enter. You do not have to press Esc, :, and q at the same time.
To edit an entry using vi:
  1. Type vi /etc/hosts and press Enter.
  2. Without entering insert mode move to the character you want to change, press R, then press the key for the character you want to change to.
  3. To save and quit press Esc, :, w, q.

    Note: You may receive a warning indicating that the file is read only when you try to save and quit. To get around this, add an ! character to the end of the Esc, :, w, q sequence and press Enter.
    Note: If you are using putty and you are in insert mode, you can paste clipboard items into vi by left-clicking copied text.
To delete the entries using vi:
  1. Type vi /etc/hosts and press Enter to edit the file.
  2. Arrow down to the line to delete.
  3. Press d twice to delete the whole line. You can also press x to delete only one character at a time when you are not in insert mode.

Additional Information

 

Notes:
  • The editors available in the shell (vi) is meant for troubleshooting purposes only and must be used only when directed by VMware. The vSphere Client, ESXCLI, and PowerCLI should be the primary method of propagating changes to your ESXi host.
  • Notepad saves documents as ANSI text which may not be the same file format as the files downloaded from a VMware ESXi host.