Using vi to edit a file in terminal

vi
99,803

Solution 1

vi = too hard to use for a new user
nano = text editor that is run from the terminal like vi, only it's much easier to use for 2 reasons:

  1. The instructions for using nano editor are always found at the bottom of every page.
  2. The only two nano keyboard shortcuts that you need to know are for WriteOut and Exit. Press the keyboard combination Ctrl+O and after that press Enter to save the file being edited. Press the keyboard combination Ctrl+X to exit nano.

nano is installed by default in Ubuntu.
Tip - Make the terminal easier to read. In the terminal select Edit -> Profile Preferences -> Colors tab and change the Background color to black and the Text color to white.

Solution 2

vi or vim is an advanced editor. So I will suggest you to get familiar with it before using it.

For now:

  • If you want to edit a file using terminal, press i to go into insert mode.

  • Edit your file and press ESC and then :w to save changes and :q to quit.

However, you can combine these two like :wq to write and quit the vim editor.


If you want to learn how to use vim editor, use vimtutor command, which starts the Vim tutor.

Solution 3

You can also use gksu gedit /etc/icinga/objects/localhost.cfg to open it in gedit and work from there, if you are having trouble using vi.

But G_P is right, type man vi in the terminal and it should give you all the instructions.

Share:
99,803

Related videos on Youtube

Jaap Grinwis
Author by

Jaap Grinwis

Updated on September 18, 2022

Comments

  • Jaap Grinwis
    Jaap Grinwis over 1 year

    I have a question, I have installed Ubuntu 14.04 and on this machine is icinga software. when I opened the terminal and typed:

    sudo vi /etc/icinga/objects/localhost.cfg
    

    then the terminal opened the file, but I can't type in this file. When I type "d" then the terminal delete everything in the file.

    • P.-H. Lin
      P.-H. Lin over 9 years
      If you're not familiar with vi, please take a look here How to edit a file in vi editor, or install vim instead.
    • P.-H. Lin
      P.-H. Lin over 9 years
      @EliahKagan nah, the default package is vim.tiny, not vim, you have to do some tweak to make it work like vim.
    • Eliah Kagan
      Eliah Kagan over 9 years
      @P.-H.Lin The advice in ps_cool's answer to How to edit a file in vi editor (arrow keys prints letters)? applies equally to both. Both Ubuntu's default vi (as vim.tiny) and fuller vim installations operate based on the same modal editing concept and have the same basic usage. At the level of answering the question of why typing D deletes a line instead of writing D at the current cursor position, the same answers apply to vi and vim.
    • Elder Geek
      Elder Geek almost 7 years
      You may find this answer informative. You might also find this useful.