Difference between revisions of "Training/Linux - Nano editor"

From HPC
Jump to: navigation , search
m
m (Navigation)
 
(16 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
== Introduction ==
 
== Introduction ==
  
'''Nano''' is a text editor for Viper and is invoked using the command line interface. It emulates the Pico text editor, part of the Pine email client, and also provides additional functionality. Nano is easier to use and learn than [[training/Linux_-_vi_editor|Vi]].  However Vi has the advantage of being installed almost universally on every Unix/Linux system by default and is quicker to edit with once its interface is learnt.
+
'''Nano''' is a text editor for Viper and is invoked using the command-line interface. It emulates the Pico text editor, part of the Pine email client, and also provides additional functionality. Nano is easier to use and learn than [[training/Linux_-_vi_editor|Vi]].  However, [[training/Linux_-_vi_editor|Vi]] has the advantage of being installed almost universally on every Unix/Linux system by default and is quicker to edit files with.
  
 
Below is how '''nano''' appears on the screen of a terminal connected to Viper:  
 
Below is how '''nano''' appears on the screen of a terminal connected to Viper:  
  
 
[[File:nano1.jpg]]
 
[[File:nano1.jpg]]
 +
 +
=== Starting Nano ===
 +
 +
For opening and creating files type:
 +
 +
<pre style="background-color: black; color: white; border: 2px solid black; font-family: monospace, sans-serif;">
 +
 +
[username@viper ~]$ nano filename
 +
 +
</pre>
 +
 +
'''Nano''' is a mode-less editor so you can start typing immediately to insert text. If you are editing a configuration file like ''/etc/fstab'' use the -w switch to disable wrapping on long lines as it might render the configuration file unparseable by whatever tools depend on it.
 +
 +
For example:
 +
 +
<pre style="background-color: black; color: white; border: 2px solid black; font-family: monospace, sans-serif;">
 +
 +
[username@viper ~]$ nano -w /etc/fstab
 +
 +
</pre>
 +
 +
== Commands ==
 +
 +
Commands in '''nano''' are usually prefixed by the <Ctrl> key with another key to indicate the command required. (Some require <Alt> also).
 +
 +
=== File operations ===
 +
 +
 +
{| class="wikitable"
 +
| style="width:25%" | <Strong>Key Stroke</Strong>
 +
| style="width:75%" | <Strong>Description</Strong>
 +
|-
 +
| <Ctrl> + O
 +
| Write file back to disk
 +
|-
 +
| <Ctrl> + R
 +
| Read a file from disk into the editor
 +
|-
 +
| <Ctrl> + X
 +
| Exit nano with a prompt to save the file
 +
|-
 +
|}
 +
 +
 +
=== Cutting and Pasting ===
 +
 +
{| class="wikitable"
 +
| style="width:25%" | <Strong>Key Stroke</Strong>
 +
| style="width:75%" | <Strong>Description</Strong>
 +
|-
 +
| <Ctrl> + K
 +
| Remove the current line and copy it
 +
|-
 +
| <Ctrl> + U
 +
| Paste the copied line to the current line
 +
|-
 +
|}
 +
 +
 +
=== Searching for text ===
 +
 +
{| class="wikitable"
 +
| style="width:25%" | <Strong>Key Stroke</Strong>
 +
| style="width:75%" | <Strong>Description</Strong>
 +
|-
 +
| <Ctrl> + W
 +
| Search for text within the editor
 +
|-
 +
| <Alt> + W
 +
| Search again for the previous search item
 +
|-
 +
|}
 +
 +
==Next Steps==
 +
 +
* [https://www.howtogeek.com/howto/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor/ Beginners guide to nano]
 +
* [https://wiki.gentoo.org/wiki/Nano/Basics_Guide Nano basics]
 +
 +
 +
 +
 +
 +
[[Main Page]]    /    [[FurtherTopics/FurtherTopics #Programming| Back to Further Topics]]

Latest revision as of 11:36, 16 November 2022

Introduction

Nano is a text editor for Viper and is invoked using the command-line interface. It emulates the Pico text editor, part of the Pine email client, and also provides additional functionality. Nano is easier to use and learn than Vi. However, Vi has the advantage of being installed almost universally on every Unix/Linux system by default and is quicker to edit files with.

Below is how nano appears on the screen of a terminal connected to Viper:

Nano1.jpg

Starting Nano

For opening and creating files type:


[username@viper ~]$ nano filename

Nano is a mode-less editor so you can start typing immediately to insert text. If you are editing a configuration file like /etc/fstab use the -w switch to disable wrapping on long lines as it might render the configuration file unparseable by whatever tools depend on it.

For example:


[username@viper ~]$ nano -w /etc/fstab

Commands

Commands in nano are usually prefixed by the <Ctrl> key with another key to indicate the command required. (Some require <Alt> also).

File operations

Key Stroke Description
<Ctrl> + O Write file back to disk
<Ctrl> + R Read a file from disk into the editor
<Ctrl> + X Exit nano with a prompt to save the file


Cutting and Pasting

Key Stroke Description
<Ctrl> + K Remove the current line and copy it
<Ctrl> + U Paste the copied line to the current line


Searching for text

Key Stroke Description
<Ctrl> + W Search for text within the editor
<Alt> + W Search again for the previous search item

Next Steps



Main Page / Back to Further Topics