Basic tutorial for Nano users

Basics of using Nano as an editor

Nano is a pretty powerful text editor that is the GPL variant of pico. Technically, you can get to the help screen very easily by hitting Ctrl+g, and there are a ton of resources out on the web for it, for example howtogeek's https://www.howtogeek.com/howto/42980/the-beginners-guide-to-nano-the-linux-command-line-text-editor/ . This tutorial is not intended for people to "learn more about", rather, it is intended to be a slightly more verbose explanation for the most common tasks encountered by new ECN staff as part of their daily work.

 

1. Creating a file

To create a file named pratfall.txt in the current directory you are in, invoke nano by typing nano pratfall.txt

To create a file in a separate directory, provide the path to nano, eg: nano /path/to/file/pratfall.txt

There is a .nanorc file that can be used to set up variables, eg: unset nowrap, ECN has a simple .nanorc in our templates folder, along with templates for .bashrc, .ahrc and various email templates for users of ECN email. This will set up colors for the queue, if your client supports it.

2. Opening a file

Opening a file uses the same command as creating it. Therefore, if the file exists, the nano pratfall.txt command will open the file, and if not, it will open it in the buffer, and write it upon exit.

You can use some tricks to open files: for example, nano +24 pratfall.txt will open the file at line 24. nano +24,5 pratfall.txt will open pratfall.txt at line 24, word 5

3. Editing a file

  • Search
    • Ctrl+w starts a search. You can search for a word, or a position. When you hit this, noteice the contextual help that pops up... indicating how one searches for First Line, Last Line, GoToLineNumber, etc. There's also an option to replace a single search term.
    • Type your search term and hit enter. The cursor will jump to your search term, if it exists.
    • Typing Ctrl+w again brings up the search tool, but this time, it will search the last searched term by default without needing additional input. The default search term appears inside square brackets [searchterm] - so repetitive searching becomes as easy as ctrl+w, enter.
  • Mark
    • Control+^ (Ctrl+Shift+6) sets a mark. If you move your cursor around, it highlights the selected text. You can also search (ctrl+w) to a (Control+t) specific line number, or to (Control+v) end of file, to highlight chunks of text. You can then manipulate it by hitting  Ctrl+k to delete. Using Control+k puts the cut text into the buffer, so you can adjust your cursor and hit Control+u to paste the buffer contents into the location of your cursor.
  • Copy
    • Here's a fun thing. If you highlight text in a proper linux client, it automatically copies it for you. This does not happen in Windows OS, and needs additional work to enable on MacOS. But - highlight-to-copy paired with easy right-click-to-paste makes text manipulation delightfully simple.
  • Cut
    • Since you are not in an actual GUI, highlighting text using the mouse and trying to go to the Edit>Cut menu option will not work. You have to highlight the text using marks, and hit control+k. Hitting control+k at the beggining of a line without marking text will cut the entire line, placing it in the buffer ready to paste. You can cut and paste multiple lines in this way.
  • Undo
    • Control+u undoes your last manipulation. Since you are not in a regular GUI window, the behavior might not be exactly what you expect - what nano thinks is your last action may surprise you.
  • Paste
    • If you have cut text or lines using control+k, using control+u will paste it in the new location.
    • If you have copied text by highlighting it in a different part of the file, right-click will paste the contents of your buffer into the file.
    • If you have copied text from a different program using the familiar highlight text, and either use the mouse to go to Edit>Copy, or typing control+c, you can use right-click to paste the text in your clipboard into the file.
  • Attaching a separate file
    • Heyyyy - you can attach a file into the outgoing message by using control+r. The file needs to be in the working direcotory, or you need to provide a path/to/file. Use this judiciously in the queue, though. The preferred mechanism is to drop the file into a homeDir, or share it in a mutually accessible location like a fileshare.
  • Find+Replace
    • Control+\ opens up a toolbox just like the search invokation for control+w, but with advanced replace options. "Replace All", for example.

4. Exiting a file (with our without saving)

  • Your options are y, n, or Control+c to return to the editor.
  • If you've screwed up, and don't want to save the file, hit Control+x, followed by 'n' for "No, please, this is a mess, I don't want to save this"
  • If you're good to go, hit y
  • If you wish to make additional changes, cancel out of the save function by using Control+c

 

 

 

 

 

 

 

 

Last modified: 2020/10/29 06:59:25.501246 GMT-4 by sundeep.rao.1
Created: 2020/10/29 05:52:17.878817 GMT-4 by sundeep.rao.1.

Categories

Search

Type in a few keywords describing what information you are looking for in the text box below.

Admin Options: Edit this Document