How to edit files using VI or VIM editor?

  • 48

1. First make a login on centOS as a root user.

2. Then type “vi” or “vim” command add give address of file i.e.
    vi /path/file

3. Now you will see the contents of the file. If file do not exist, then first create it then edit it.

Most important or commonly used commands in vi are given below.

  • i = (Insert Mode) to insert data in file.
  • Esc = (To leave Mode) leave the mode (any mode i.e. insert, delete or any other).
  • x = (Delete Mode) to delete character which is currently under the cursor.
  • :x = to save changes.
  • Shift+z+z = to save changes and close file and return to root directory.
  • :q! = to leave file without saving.  

Note: You must leave any mode first, then use another mode. Use only one mode at a time. During all these operations you can use your keyboard's arrow keys to navigate the cursor through the text.



Was this answer helpful?