how to write into file after doing sudo vi /dir to file

1

i have ubuntu 10.10 installed on a box. and i ssh to it from another computer.

when i do sudo vi /var/www/page.php

i enter a text editor. when when i try to type i hear that ding noise as in i cant type. what do i press to allow me to start typing? when i type :q that works and it quits it. but what allows me to start typing? thanks

Sarmen B.

Posted 2011-04-08T07:54:24.147

Reputation: 599

2Matt Jenkin's list is a good primer but if things work out too difficult, use 'nano' instead. Its probably a lot closer to the text editors your used to. Instead of writing 'vi file', write 'nano file'. – Pricey – 2011-04-08T08:28:37.890

Answers

2

Vi is what is known as a modal editor - that means it has a number of modes in which it operates.

When you first start vi it is in command mode. Some common command mode key sequences:

  • :q - Quit
  • :q! - Force quit
  • :w - Write file
  • :wq! - Forced write file and exit
  • :w /path/to/my/new/file - Write to a new file
  • :r /path/to/file - read file and insert into buffer

To switch into one of the editing modes:

  • i - Enter insert mode infront of the current character
  • r - Replace single character
  • R - Enter replace mode
  • a - Enter insert mode after the current character
  • A - Enter insert mode at the end of the current line
  • o - Open a new line below cursor and enter insert mode
  • O - Open a new line above cursor and enter insert mode

To return to command mode just press Esc

There are a huge number of other keypresses in command mode - this list is pretty useful.

Majenko

Posted 2011-04-08T07:54:24.147

Reputation: 29 007

1

type a to append or i to insert
Refer this document for more commands

Shekhar

Posted 2011-04-08T07:54:24.147

Reputation: 4 815