8

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.

Zanna
  • 69,223
  • 56
  • 216
  • 327
Jaap Grinwis
  • 81
  • 1
  • 1
  • 2
  • If you're not familiar with vi, please take a look here [How to edit a file in vi editor](http://askubuntu.com/questions/220065/how-to-edit-a-file-in-vi-editor-arrow-keys-prints-letters), or install vim instead. – P.-H. Lin Sep 16 '14 at 14:15
  • @P.-H.Lin `vim` and `vi` are used the same way. Do you mean to suggest using `nano` instead? – Eliah Kagan Sep 16 '14 at 14:36
  • @EliahKagan nah, the default package is vim.tiny, not vim, you have to do some tweak to make it work like vim. – P.-H. Lin Sep 17 '14 at 14:37
  • 1
    @P.-H.Lin The advice in [ps_cool's answer](http://askubuntu.com/a/220067/22949) to [How to edit a file in vi editor (arrow keys prints letters)?](http://askubuntu.com/questions/220065/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`. – Eliah Kagan Sep 17 '14 at 14:50
  • 1
    You may find [this answer](https://askubuntu.com/a/353940/225694) informative. You might also find [this](https://www.cs.colostate.edu/helpdocs/vi.html) useful. – Elder Geek May 11 '17 at 12:39

3 Answers3

12

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.

karel
  • 110,292
  • 102
  • 269
  • 299
10

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.
Melebius
  • 11,121
  • 8
  • 50
  • 77
g_p
  • 18,154
  • 6
  • 56
  • 69
2

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.

afontanm
  • 21
  • 5