Difference between revisions of "Editing a File"

From wiki.emacinc.com
Jump to: navigation, search
m (Added additional tips.)
 
(8 intermediate revisions by 4 users not shown)
Line 1: Line 1:
{{todo|Review (11.25.13-16:10->KY+)|Klint Youngmeyer|project=oe 4,oe 5,ky,review,md}}
+
{{todo|SEOKWREV (11.25.13-16:10->KY+);(11.26.13-19:55->MD+);(12.17.13-12:45->MG+);(03.06.14-14:40->BS-);(04.10.14-14:35->BS+)|Klint Youngmeyer|project=oe 4,oe 5,ky,md,mg,bs,SEOKWREV}}
  
 +
{{#seo:
 +
|title=Editing a File
 +
|titlemode=append
 +
|keywords=Linux Vi,Linux Nano,Linux Vim
 +
|description=EMAC OE provides simple text editing capabilities for making changes to configuration files and scripts.
 +
}}
 
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__
 
__TOC__
Line 29: Line 35:
 
|}
 
|}
  
 +
{{mbox | type = notice | text = Note that the version of <code>vi</code> supplied with the standard EMAC OE build is part of busybox and does not have all of the same functionality as a full <code>vi</code> implementation. Some commands are not implemented in this version. }}
  
{{mbox | type = notice | text = Note that the version of <code>vi</code> supplied with the standard EMAC OE build is part of busybox and does not have all of the same functionality as a full <code>vi</code> implementation. You will find some commands that are not implemented in this version. }}
 
  
 
+
To open a file using <code>vi</code> simply type the command <code>vi</code> followed by the file name. For example, to edit the network interfaces configuration:
To open a file using <code>vi</code> simply type the command <code>vi</code> followed by the file name. For example, to edit the network interfaces configuration, you would run the command:
 
 
<syntaxhighlight lang=console>
 
<syntaxhighlight lang=console>
 
root@emac-oe:~# vi /etc/network/interfaces
 
root@emac-oe:~# vi /etc/network/interfaces
 
</syntaxhighlight>
 
</syntaxhighlight>
For more information about the busybox version of <code>vi</code>, see the following links: [http://en.wikibooks.org/wiki/Learning_the_vi_Editor/BusyBox_vi Learning the vi editor], [http://k.japko.eu/busybox-vi-tutorial.html Busybox vi tutorial]
+
 
 +
For more information about the busybox version of <code>vi</code>, see the following links:  
 +
*[http://en.wikibooks.org/wiki/Learning_the_vi_Editor/BusyBox_vi Learning the vi editor]
 +
 
 +
*[http://k.japko.eu/busybox-vi-tutorial.html Busybox vi tutorial]
  
 
On desktop Linux, the <code>vimtutor</code> program is usually installed with the full <code>vim</code> package.  This program is a great way to learn the basics of <code>vim</code> (which stands for VI iMproved) quickly.  The <code>vimtutor</code> program is designed to take about a half an hour to work through.  The unusual user interface of <code>vi</code> makes it a very powerful editor, once learned.  Keys used in the command mode of <code>vi</code> can be found in many other places, as well, such as the gmail web interface (when enabled).
 
On desktop Linux, the <code>vimtutor</code> program is usually installed with the full <code>vim</code> package.  This program is a great way to learn the basics of <code>vim</code> (which stands for VI iMproved) quickly.  The <code>vimtutor</code> program is designed to take about a half an hour to work through.  The unusual user interface of <code>vi</code> makes it a very powerful editor, once learned.  Keys used in the command mode of <code>vi</code> can be found in many other places, as well, such as the gmail web interface (when enabled).
  
 
== Using Nano ==
 
== Using Nano ==
<code>nano</code> has a smaller learning curve than <code>vi</code>, but is much less powerful.  People looking to edit files quickly, without much learning curve, may wish to start with <code>nano</code>.
+
<code>nano</code> is easier to use than <code>vi</code>, but is much less powerful.  
  
 
After opening a file with <code>nano</code>, the available commands for working with the file will be displayed at the bottom of the screen as shown below:
 
After opening a file with <code>nano</code>, the available commands for working with the file will be displayed at the bottom of the screen as shown below:
Line 48: Line 57:
 
  ^X Exit        ^J Justify      ^W Where Is    ^V Next Page    ^U UnCut Text  ^T To Spell  
 
  ^X Exit        ^J Justify      ^W Where Is    ^V Next Page    ^U UnCut Text  ^T To Spell  
  
For example, to save the file, press Ctrl-O. To exit, press Ctrl-X. The <code>nano</code> 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 command mode, as is required with <code>vi</code>. To edit a file with <code>nano</code>, pass the name of the file as an argument to the <code>nano</code> command. For example:
+
For example, to save the file, press Ctrl-O. To exit, press Ctrl-X. The <code>nano</code> 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. There is no need to press any escape code to switch between entering text and command mode, as is required with <code>vi</code>. To edit a file with <code>nano</code>, pass the name of the file as an argument to the <code>nano</code> command. For example:
 +
 
 
<syntaxhighlight lang=console>
 
<syntaxhighlight lang=console>
 
root@emac-oe:~# nano /etc/network/interfaces
 
root@emac-oe:~# nano /etc/network/interfaces
 
</syntaxhighlight>
 
</syntaxhighlight>
[[Category:Linux]]
+
 
[[Category:OpenEmbedded]]
+
<!--[[Category:Linux]]
 +
[[Category:OpenEmbedded]]-->

Latest revision as of 13:37, 10 April 2014

TODO: {{#todo:SEOKWREV (11.25.13-16:10->KY+);(11.26.13-19:55->MD+);(12.17.13-12:45->MG+);(03.06.14-14:40->BS-);(04.10.14-14:35->BS+)|Klint Youngmeyer|oe 4,oe 5,ky,md,mg,bs,SEOKWREV}}

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.

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 (write) and exit
:q! Discard changes (if any since last write) and exit
:q Exit only if no unsaved changes
x Delete character under cursor
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"


To open a file using vi simply type the command vi followed by the file name. For example, to edit the network interfaces configuration:

root@emac-oe:~# vi /etc/network/interfaces

For more information about the busybox version of vi, see the following links:

On desktop Linux, the vimtutor program is usually installed with the full vim package. This program is a great way to learn the basics of vim (which stands for VI iMproved) quickly. The vimtutor program is designed to take about a half an hour to work through. The unusual user interface of vi makes it a very powerful editor, once learned. Keys used in the command mode of vi can be found in many other places, as well, such as the gmail web interface (when enabled).

Using Nano

nano is easier to use than vi, but is much less powerful.

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, press Ctrl-O. To exit, press 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. There is no need to press any escape code to switch between entering text and command mode, 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