Difference between revisions of "Editing a File"
Kyoungmeyer (talk | contribs) (Created page with "EMAC OE provides simple text editing capabilities for making changes to configuration files and scripts. Major editing tasks should be performed on a desktop system first, cop...") |
Kyoungmeyer (talk | contribs) |
||
Line 1: | Line 1: | ||
EMAC OE provides simple text editing capabilities for making changes to configuration files and scripts. Major editing tasks should be performed on a desktop system first, copying the desired files back to the target board. There are two text editors available on standard EMAC OE builds: <code>vi</code> and <code>nano</code>. <code>vi</code> is a very common text editor available on almost every Unix-like OS. <code>nano</code> is a more conventional text editor that can be easier to use for those not familiar with <code>vi</code>. | EMAC OE provides simple text editing capabilities for making changes to configuration files and scripts. Major editing tasks should be performed on a desktop system first, copying the desired files back to the target board. There are two text editors available on standard EMAC OE builds: <code>vi</code> and <code>nano</code>. <code>vi</code> is a very common text editor available on almost every Unix-like OS. <code>nano</code> is a more conventional text editor that can be easier to use for those not familiar with <code>vi</code>. | ||
− | + | __TOC__ | |
== Using Vi == | == Using Vi == | ||
The key to using <code>vi</code> is understanding the two modes of operation: command mode and insert mode. Command mode is used for navigating the text, search and replace, pasting, saving, and running other commands. Insert mode is used for simply inserting text into the document. The editor will start in command mode. To switch from command mode to insert mode, type "i". To switch from insert mode to command mode, press ESC. Any keys pressed after switching to command mode will be interpreted as <code>vi</code> commands. Some of the most important commands are those for saving and exiting, such as <code>:wq</code> to save and exit. See Table 5 below for a description of some common vi commands. | The key to using <code>vi</code> is understanding the two modes of operation: command mode and insert mode. Command mode is used for navigating the text, search and replace, pasting, saving, and running other commands. Insert mode is used for simply inserting text into the document. The editor will start in command mode. To switch from command mode to insert mode, type "i". To switch from insert mode to command mode, press ESC. Any keys pressed after switching to command mode will be interpreted as <code>vi</code> commands. Some of the most important commands are those for saving and exiting, such as <code>:wq</code> to save and exit. See Table 5 below for a description of some common vi commands. |
Revision as of 16:11, 21 November 2013
EMAC OE provides simple text editing capabilities for making changes to configuration files and scripts. Major editing tasks should be performed on a desktop system first, copying the desired files back to the target board. There are two text editors available on standard EMAC OE builds: vi
and nano
. vi
is a very common text editor available on almost every Unix-like OS. nano
is a more conventional text editor that can be easier to use for those not familiar with vi
.
Contents
Using Vi
The key to using vi
is understanding the two modes of operation: command mode and insert mode. Command mode is used for navigating the text, search and replace, pasting, saving, and running other commands. Insert mode is used for simply inserting text into the document. The editor will start in command mode. To switch from command mode to insert mode, type "i". To switch from insert mode to command mode, press ESC. Any keys pressed after switching to command mode will be interpreted as vi
commands. Some of the most important commands are those for saving and exiting, such as :wq
to save and exit. See Table 5 below for a description of some common vi commands.
Table 5: Common Vi Commands | |
---|---|
Command | Description |
:wq |
Save changes and exit |
:q! |
Discard changes and exit |
:q |
Exit only if no unsaved changes |
x |
Delete character |
dd |
Delete current line |
yy |
Yank (copy) current line |
p |
Put (paste) after position |
:%s/string/replace/g |
Replace all occurrences of "string" with "replace" |
Note that the version of vi supplied with the standard EMAC OE build is part of busybox and does not have all of the same functionality as a full vi implementation. You will find some commands that are not implemented in this version. |
To open a file using vi
simply type the command vi
followed by the file name. For example, to edit the network interfaces configuration, you would run the command:
root@emac-oe:~# vi /etc/network/interfaces
Using Nano
Using nano
can be easier to get used to for someone who is not accustomed to using vi
. After opening a file with nano
, the available commands for working with the file will be displayed at the bottom of the screen as shown below:
^G Get Help ^O WriteOut ^R Read File ^Y Prev Page ^K Cut Text ^C Cur Pos ^X Exit ^J Justify ^W Where Is ^V Next Page ^U UnCut Text ^T To Spell
For example, to save the file, enter Ctrl+O. To exit, type Ctrl+X. The nano
editor is always in insertion mode so any keys typed that are not part of a control sequence will be placed in the file as text. You do not need to press any escape code to switch between entering text and commands as is required with vi
. To edit a file with nano
, pass the name of the file as an argument to the nano
command. For example:
root@emac-oe:~# nano /etc/network/interfaces