Difference between revisions of "Tutorials and How-tos/Edit Text Files with nano"

From BubbaWiki
Jump to navigation Jump to search
(Created page with 'For simple editing of text files you could use the editor called nano. To edit the Debian sources file, type: <pre>nano /etc/apt/sources.list</pre> The file then opens in the na...')
 
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
For simple editing of text files you could use the editor called nano.
Bubba comes with a simple yet powerful text editor called nano. To launch the editor, run the <code>nano</code> command. This launches the editor and creates a blank text file. All actions in nano are done using keyboard shortcuts, and you can see the most important ones at the bottom of the screen. You can periodically save the file during editing using the '''Ctrl+O''' shortcut. To exit nano, press '''Ctrl+X'''. If you exit nano from a modified file, it will prompt you to save it first. Like any text editor worth its salt, nano supports the cut and paste actions. The C'''trl+K''' shortcut cuts a single line. To paste the line, place the cursor where you want to insert the line and press '''Ctrl+U'''. To move multiple lines, cut them using the '''Ctrl+K''' shortcut, then paste them all together by pressing '''Ctrl+U'''. If you need to cut a single word or a text fragment, press '''Ctrl+6''' or '''Alt+A''', select the text you want, then press '''Ctrl+K''' to cut it. You can then paste the snippet using the '''Ctrl+U''' shortcut.  


To edit the Debian sources file, type:
[[Image:Nano.png|375px|Nano.png]]
<pre>nano /etc/apt/sources.list</pre>
The file then opens in the nano editor.


When done editing, press Ctrl + X on your keboard. You will be asked if you whant to save the changed. Press Y to do so.
Performing a text search in nano is also easy: hit '''Ctrl+W''', enter the search string, and press '''Enter'''. To find the same string again, press '''Ctrl+W''' again and hit '''Enter'''. To perform the search and replace action, press '''Ctrl+\''', specify a search string and its replacement, and press '''Enter'''. You can then choose whether you want to replace only the first found match or all occurrences of the search string.  


All done!
Although nano is not designed to replace a dedicated word processor, it has both word count and spell checking features which make it a perfect tool for drafting articles or taking notes. To view the current word count, press the '''Meta''' key followed by '''D'''. Which key is defined as '''Meta''' depends on your system; in most cases it's either the '''Esc''' or '''Windows''' key. To run a spell check, press '''Ctrl+T'''. By default, nano uses its own interactive spell checker that requires the ''spell'' program to be installed on your system. Alternatively, you can force nano to use the ''aspell'' program instead. To do this, open the ''nanorc'' file for editing as root using the <code>nano /etc/nanorc</code> command and uncomment the following line:


<br>
  set speller "aspell -x -c"
 
While you're at it, you might want to tweak other settings, too. For example, if you want to enable the mouse in nano, uncomment the ''set mouse'' option. This allows you to use the mouse to place the cursor, set the mark, and execute shortcuts.

Latest revision as of 13:43, 4 September 2010

Bubba comes with a simple yet powerful text editor called nano. To launch the editor, run the nano command. This launches the editor and creates a blank text file. All actions in nano are done using keyboard shortcuts, and you can see the most important ones at the bottom of the screen. You can periodically save the file during editing using the Ctrl+O shortcut. To exit nano, press Ctrl+X. If you exit nano from a modified file, it will prompt you to save it first. Like any text editor worth its salt, nano supports the cut and paste actions. The Ctrl+K shortcut cuts a single line. To paste the line, place the cursor where you want to insert the line and press Ctrl+U. To move multiple lines, cut them using the Ctrl+K shortcut, then paste them all together by pressing Ctrl+U. If you need to cut a single word or a text fragment, press Ctrl+6 or Alt+A, select the text you want, then press Ctrl+K to cut it. You can then paste the snippet using the Ctrl+U shortcut.

Nano.png

Performing a text search in nano is also easy: hit Ctrl+W, enter the search string, and press Enter. To find the same string again, press Ctrl+W again and hit Enter. To perform the search and replace action, press Ctrl+\, specify a search string and its replacement, and press Enter. You can then choose whether you want to replace only the first found match or all occurrences of the search string.

Although nano is not designed to replace a dedicated word processor, it has both word count and spell checking features which make it a perfect tool for drafting articles or taking notes. To view the current word count, press the Meta key followed by D. Which key is defined as Meta depends on your system; in most cases it's either the Esc or Windows key. To run a spell check, press Ctrl+T. By default, nano uses its own interactive spell checker that requires the spell program to be installed on your system. Alternatively, you can force nano to use the aspell program instead. To do this, open the nanorc file for editing as root using the nano /etc/nanorc command and uncomment the following line:

 set speller "aspell -x -c"

While you're at it, you might want to tweak other settings, too. For example, if you want to enable the mouse in nano, uncomment the set mouse option. This allows you to use the mouse to place the cursor, set the mark, and execute shortcuts.