Nano Open File

broken image


Nano -version GNU nano, version 2.9.3. Open as many files as you want by listing them as separate arguments to nano, like so: nano file1.txt file2.log file3.c file4.js file5.py The first file is opened, e.g. Use the keyboard shortcuts below to switch between the files. Alt+.- move forward one file. Alt+,- move back one file. To open a file you must have read permissions to the file. If you want to open a file with the cursor on a specific line and character use the following syntax: nano +linenumber,characternumber filename. If you omit the characternumber the cursor will be positioned on the first character. Editing Files #.

If I need to edit text files directly on my Raspberry Pi my text editor of choice is nano. There are other text editors available but I prefer nano's relatively straightforward interface.

As a command line based utility it may feel strange for users who are more familiar with a graphical interface but it is easy to learn the basics. Syntax colouring is available which makes reading and reviewing scripts easy.

Launching nano

To start nano you can simply type nano at the command prompt. This will launch with a 'new buffer'. In other words an empty text file that has no name.

In order to launch an existing text file you type nano followed by the file name :

You will see something like this :

nano Main Screen
Files
If your file is not in the current directory you will need to specify the full path :

If the file is a system file you may need to use elevated permissions :

Note: Always use the -w switch when opening system files. It disables wrapping long lines and ensures the file isn't modified in a way that may affect your system.

Editing Text

Once in nano you can start typing. Additional functions can be activated by using the CTRL or ESC keys. These short-cuts are listed at the end of this post. You can list these keys while in nano using CTRL+G (Press and hold the CTRL key then press the G key) :

nano Help Pages (CTRL+G)Return to the main screen using CTRL+X.

To get you started here is a brief summary of nano's most useful features.

Saving and Quiting

To save a file you can use CTRL+O.

To quit nano you can use CTRL+X. You will be prompted to save your file if it has changed and you can answer this prompt with either a Y or a N. If you've changed your mind at this point you can return the main edit screen using CTRL+C.

Cutting and Pasting

Cut a line using CTRL+K. To copy a line use ALT+6.

Cmd edit file. Paste a line at the cursor position using CTRL+U.

To cut or copy multiple lines use CTRL+K or ALT+6 on each line and then paste them all using a single CTRL+U. They are pasted in the order that you cut/copied them. Using CTRL+U again will paste another set of text if required.

You can also mark a block of text before cutting. Position your cursor at the start of the text and press CTRL+6. Then position your cursor after the text and use CTRL+K or ALT+6 to cut or copy. CTRL+U to paste.

Searching and Replacing Text

To search for text use CTRL+W. Enter the text you need to find and press Enter. To repeat the search use ALT+W.
To perform a search and replace use ALT+R.

You can't open files once nano is running. Although you can insert a file into the current buffer you can not open a file directly once you are in nano. You need to launch it from the command line. I find this quite strange. If you need to edit a number of files you need to quit and then load each one in turn from the command line.

Key Short-cut Summary

For some reason the official nano website keeps the nano 'Control' and 'Meta' short-cuts a closely guarded secret so I have listed them here.

ControlMetaDescriptionCTRL+GDisplay the help textCTRL+XClose the current file buffer / Exit from nanoCTRL+OWrite the current file to diskCTRL+RInsert another file into the current oneCTRL+WSearch for a string or a regular expressionALT+WRepeat last searchCTRL+ALT+RReplace a string or a regular expressionControlMetaDescriptionCTRL+KCut the current line and store it in the cutbufferALT+6Copy the current line and store it in the cutbufferCTRL+UPaste from the cutbuffer into the current lineALT+TCut from the cursor position to the end of the fileALT+AMark text at the cursor positionCTRL+CDisplay the position of the cursorCTRL+_ALT+GGo to line and column numberCTRL+TInvoke the spell checker, if availableALT+}Indent the current lineALT+{Unindent the current lineControlMetaDescriptionCTRL+YMove to the previous screenCTRL+VMove to the next screenCTRL+FMove forward one characterCTRL+BMove back one characterCTRL+SpaceMove forward one wordALT+SpaceMove back one wordCTRL+PMove to the previous lineCTRL+NMove to the next lineCTRL+AMove to the beginning of the current lineCTRL+EMove to the end of the current lineALT+( or ALT+9Move to the beginning of the current paragraphALT+) or ALT+0Move to the end of the current paragraphALT+ or ALT+|Move to the first line of the fileALT+/ or ALT+?Move to the last line of the fileALT+]Move to the matching bracketALT+- or ALT+_Scroll up one line without scrolling the cursorALT++ or ALT+=Scroll down one line without scrolling the cursorALT+< or ALT+,Switch to the previous file bufferALT+> or ALT+.Switch to the next file bufferALT+VInsert the next keystroke verbatimCTRL+IInsert a tab at the cursor positionCTRL+MInsert a newline at the cursor positionCTRL+DDelete the character under the cursorCTRL+HDelete the character to the left of the cursorControl

How To Open Nano File

MetaDescriptionCTRL+JJustify the current paragraphALT+JJustify the entire fileALT+DCount the number of words, lines, and charactersCTRL+LRefresh (redraw) the current screenALT+XHelp mode enable/disableALT+CConstant cursor position display enable/disableALT+OUse of one more line for editing enable/disableALT+SSmooth scrolling enable/disableALT+PWhitespace display enable/disableALT+YColor syntax highlighting enable/disableALT+HSmart home key enable/disableALT+IAuto indent enable/disableALT+KCut to end enable/disableALT+LLong line wrapping enable/disableALT+QConversion of typed tabs to spaces enable/disableALT+BBackup files enable/disableALT+FMultiple file buffers enable/disableALT+MMouse support enable/disableALT+NNo conversion from DOS/Mac format enable/disableALT+ZSuspension enable/disable

Note : Some operations have multiple short-cuts.

The official GNU nano editor homepage : https://www.nano-editor.org/

Share.TwitterFacebookPinterestLinkedInTumblrEmail
In the following post, you will see how to open a new or an existing file in Nano editor. The commands have been tested on Ubuntu 20.04 LTS Terminal.

Open a new file in Nano

There are two methods for opening a new file in the Nano editor:

Method #1

In this method, we will first open the Nano editor and then create a new file.
1. Open the Nano editor (if not already opened):

It will open an empty file in Nano editor. Call of duty 4 modern warfare wii trailer. Hit Ctrl+o, type a name for the file, and then save it by hitting Enter.

Method #2

In the following method, we will open the file right from the Terminal (command line).
1.Type nano followed by the name of the file which you to open (create) in Nano editor. Fl studio fruity edition.

Example:

This command will create a new file named 'test' for editing in Nano editor.

Open an existing file in Nano

There are two methods for opening an existing file in the Nano editor:

Method #1

In this method, we will first open the Nano editor and then open an existing file.
1.Open the Nano editor:

2.Then to open a new file in Nano, hit Ctrl+r. The Ctrl+r (Read File) shortcut allows you to read a file in the current editing session
3.Then, in the search prompt, type the file name (mention full path) and hit Enter.


It will open the existing 'sample.txt' file in the Nano editor.

Save File Nano Linux

Method #2

Nano Open File Extension

In this method, we will open the file right from the command line.
1.Type nano followed by the name of the existing file:

Example:

This command will open the 'testfile' for editing in Nano editor.

Open File In Nano

Open multiple files in Nano and switch between them

To open multiple files in Nano editor, type nano followed by the name of all files:

Example:

In the above screenshot, 1/3 indicates the first file (out of three files) is currently being edited. To switch between these files (move forward and backward), use the following shortcut:





broken image