Exit and save from nano. Nano - text editor

All commands are issued by pressing key combinations - function buttons or the combination Ctrl-letter, Alt-letter.

Alt is emulated by pressing Esc once, Ctrl by double pressing. Instead of Alt-X you can type Esc X , instead of Ctrl K you can type Esc Esc K .

The up-left-right-down arrows do exactly what they're supposed to do.
Start of line - Home
End of line - End
Page down - PgDn
Pages up - PgUp

A word ahead - Ctrl-Space
A word back - Alt-Space(cursor appears at the beginning of the word)
To the beginning of the file - Alt-| or Alt-\ (in short, Alt- and “this” button)
To the end of the file - Alt-/ or Alt-? (similarly, Alt "this" button)
Down to the first empty line - Alt-0(or Alt-))
Up to the first empty line - Alt-9(or Alt-()


Enable/Disable Line Wrap - Alt-L
Go to the line with the specified number - Alt-G

Text selection is carried out either with the mouse or with the keyboard. From the keyboard, selection occurs like this: first, the beginning of the selection is marked: Alt-A or Ctrl-^. Next comes navigation - and until the action is performed on the text in the buffer, the selection is saved.

Selected text can be copied to the clipboard - combination Alt-6.

Next, we can paste the text from the clipboard − Ctrl-U or F10.

In addition, for ease of editing, Ctrl-K deletes the line if there is no selection. Either entirely, or from the cursor to the end of the line. The behavior is switched by a combination Alt-K(by default, the mode is to delete the entire line, and Alt-K switches it back and forth).

Please note that the deleted line is in the buffer, so you can paste it using Ctrl-U .

Another combination for lazy people - Alt-T, erasing everything from the cursor to the end of the file (trunkate command).

To insert text from another file, use the button Ins(I think all vim users are well aware of the behavior of this button in nano).

All basic Control sequences are listed at the bottom of the terminal window.

Control sequences are the following (in brackets - duplicates function keys and, sometimes, Meta-sequences):

    Control+G (F1) - call the full help menu;
  • Control+X (F2) - exit the program;
  • Control+O (F3) - record the current file;
  • Control+R (F5) - insert a file into the current one;
  • Control+W (F6) - search for text in the current file;
  • Control+\ (F14 or Meta+R) - replacing text in the current file; First, the replacement text is entered, then, after clicking Enter- replaceable;
  • Control+Y (F7 or PgUp) - move to the previous screen;
  • Control+V (F8 or PgDwn) - move to the next screen;
  • Control+K (F9) = deleting (Cut, cut) a line at the cursor position and storing it in a buffer (cutbuffer);
  • Control+U - (F10) - inserts the contents of the cutbuffer into a line at the cursor position; if the latter has not changed, it performs the role of Undo (cancellation), which is not normally provided; can also be used for unlimited cloning of lines in an arbitrary part of the text - after deleting, it is enough to move the cursor to the desired place;
  • Control+C (F11) - display information about the position of the cursor in the form of VR
  • Control+T (F12) - spell checking (via an external spelling program, if it is installed and the corresponding option is enabled in the config, see below);
  • Control+P- move the cursor one line up;
  • Control+N- move the cursor one line down;
  • Control+F- move the cursor one character forward;
  • Control+B- move the cursor one character back;
  • Control+A- moving the cursor to the beginning of the current line;
  • Control+E- moving the cursor to the end of the current line;
  • Control+L- redrawing the current screen;
  • Control+^ (Meta+A) - selecting (and placing in the buffer) text, starting from the current cursor position;
  • Control+D- deleting a character at the cursor position;
  • Control+H- deleting a character to the left of the cursor;
  • Control+I- insert a tab character;
  • Control+J (F4) autocomplete the current paragraph;
  • Control+M inserting a newline character (CR) at the cursor position;
  • Control+_ (F13 or Meta+G) - jump to the specified line number.

Editor nano- it's console text editor. It is available in almost all Linux distributions, is available on macOS and can be run on Windows. nano is often used to edit configuration files when a GUI is not available.

Control in nano is carried out from the keyboard using hotkeys. At the bottom of the editor is a list of basic keyboard shortcuts. The ^ symbol represents the Ctrl key. For example, ^X means the keyboard shortcut Ctrl+X. Character case is not sensitive; Ctrl+X is equivalent to Ctrl+x .

Let's look at how to perform basic actions when working with nano.

Create a new file

To create a file, simply launch the editor without parameters. When you close the editor, you will need to enter a file name.

You can also immediately set the name of the new file:

After executing the command, the nano editor will launch and a new empty file will open for editing.

Open an existing file for editing

To edit an existing file, you need to launch the nano editor and specify the path to the file you want to open:

Saving changes

Save and continue working

The following message will appear in the status line: File Name to Write: file_name(if the file name is missing, then you need to enter the file name). To save changes, press Enter.

Save and exit

In this case, if you changed the file, the question will appear: " Save modified buffer (ANSWERING No Will DESTROY CHANGES)?". Press the y key. A question will appear asking you to enter a file name. Enter a new file name or just press Enter. The changes will be saved and the editor will close.

Exit without saving changes

To exit the editor and not save changes, use the keyboard shortcut:
Ctrl+X

There is a question" Save modified buffer ..?", press n.

Copy and paste

Copying and pasting rows

To cut entire line and place it in the buffer, move the cursor to the desired line and press:
Ctrl+K

To insert click the line from the buffer:
Ctrl+U

Copy and paste free text

To copy arbitrary text to the clipboard, you must first select it. To start selection Place the cursor at the beginning of the text you plan to copy and press:
Ctrl+6

Move the cursor, the text will be highlighted.

To copy selected text to the clipboard, press:
Alt+6

or, to cut selected text, click:
Ctrl+K

Move the cursor to the place where you want to paste the text from the buffer. To insert text from buffer click:
Ctrl+U

Search text

To search for text inside a file, use the keyboard shortcut:
Ctrl+W

You need to enter a search string and press Enter.

The cursor will be placed on the first occurrence of the searched text (relative to the cursor). To move to the next occurrence, click:
Alt+W

To stop searching, click:
Ctrl+C

Find and replace text

To find and replace text, use the keyboard shortcut:
Ctrl+\

You will be prompted to enter text to search. Enter a search string and press Enter.
You will then be asked to enter the text you want to replace with. Type a string and press Enter.
Next, a request will be issued to replace the found occurrence of the required string. You can press the A key to replace all occurrences in the file at once, or use the Y or N keys to replace or not replace found occurrences of the search string.

Hotkeys

To display information on all hotkeys, use the combination Ctrl+G.

The most commonly used nano hotkeys are:

HotkeysDescription
Ctrl+AMove the cursor to the beginning of the line.
Ctrl+EMove the cursor to the end of the line.
Ctrl+YMove the cursor 1 page up (analogous to PageUp)
Ctrl+VMove the cursor 1 page down (analogous to PageDown)
Ctrl+_Go to a specific line (you will need to enter a line number).
Ctrl+CShow what line and position the cursor is on.
Ctrl+WSearch for text in a file. You must enter a search string.
Ctrl+\Find and replace text in a file. First enter the search string, then the replacement string.
Ctrl+DDelete the character under the cursor.
Ctrl+KDelete the current line.
Ctrl+OSave changes without closing the editor.
Ctrl+XExit the editor. If the file has been modified, you will be prompted to save your changes.

Something else

A couple more interesting tricks when working with nano, which not everyone knows about.

Ctrl = Esc Esc

Instead of the Ctrl key, you can use double-clicking the Esc key. For example,
Esc+Esc+X
This is equivalent to Ctrl+X.

Only for reading

To open a file read-only, use the -v switch:

File backup

You can make sure that when a file is changed, a backup copy is created. To do this, use the -B switch:

If you change a file and save the changes, a backup copy of the file will be created, with the contents of the file as it was before the change. The backup name is the same as the original file name with a tilde ~ at the end.

For newbies who are just starting to learn Linux, the terminal is a lot of stress, but when it comes to the nano command...

Almost all servers running on Linux, including Ubuntu Server, do not use a graphical shell; all settings are made using the terminal. In desktop Linux distributions, the situation is slightly simpler, but still, if you want to fine-tune the system, then you can’t avoid getting familiar with the terminal. One of the most difficult “commands” to master is Nano Linux. This command, " nano ", nothing more than a console text editor.

How to Use Nano Text Editor in Linux Terminal

In this article we will try to clearly tell you how to use this text editor so that Linux does not seem such a complex operating command.

Installing Nano on Linux

If the terminal does not respond in any way to the nano command, then this text editor is not installed. To install it, enter the command:

sudo apt install nano

Everything is ready to launch!

Launch of the Nano

Text editor nano only works in the terminal. One more clarification before we begin, operating system Linux is case sensitive; if a word or part of a command is written with a capital letter, then you need to type it that way, otherwise you will get an error.

If you are in the directory (folder) where the required text file is located, then, in order to start editing it using nano you need to write in the terminal like this:

Nano index.html

By the way, the team will help you find out which directory you are in now pwd , and what files are located nearby? ls .

If we are editing a file that is located in another directory (folder), then you need to specify the full path in the terminal:

Nano /var/www/html/index.html

If you suddenly edit a file sensitive to word wrapping, then enter the command in the terminal nano with additional key -w :

Nano -w/var/www/html/index.html

In order to open a document on a specific row or column nano + row, column file_name

For example nano +3,2 /etc/hosts

Nano hotkeys for control in a text editor

With text information entered into nano no one should have any problems. But how convenient it is to manage text data, delete it in bulk, move it, and most importantly, how to save it in nano, many people have problems with this.

Action name nano hotkeys
Open a file on a specific line

+ line_number

For example:

nano +25 log.txt

“Slow” movement to the sides - up, down, left, right Keys

or

Ctrl F And Ctrl B

←→ or

Ctrl P And Ctrl N

Move to the beginning of the file Alt | or Alt\
Move to the end of the file Alt / or Alt?
Move forward one word Ctrl Space
Move to the beginning of the line Ctrl A
Move to the end of the line Ctrl E
Move back a word Alt Space
Move to line by number Alt G or Ctrl -
Next page (if long text file) Ctrl Y
Previous page (if long text file) Ctrl V
Cut "delete" entire line Ctrl K
Erase everything from the cursor to the end of the file ALT T
Paste a previously cut or copied line Ctrl U
Select part of the text, copy or cut it (or delete) Move to the required section of text

Clamp ALT A

and move the keys ↓←→

Copy Alt-6

Cut or delete Ctrl K

Insert Tab Ctrl I
Insert text information from another file Ctrl R

indicate the path to the file

In nano show row and column number CTRL C
Find in text file necessary word Ctrl W

write the search word

Find next Ctrl W
Saving changes to a file Ctrl O

press Enter

Saving changes to a file and exiting the nano editor Ctrl O

press Enter

Do not save changes made Ctrl Z
Save changes and rename file Ctrl X

press Y

enter a new file name

press Enter

I hope using the nano terminal text editor will no longer be such a big headache as before!

Do you still have additional questions? Write them in the comments about what you did or vice versa!

That's all! Read more articles and instructions in the section. Stay with the site, it will be even more interesting!

Nano- text editor command line, which is preinstalled in almost every Linux distribution. It is often preferred by new users due to its simplicity compared to other command line text editors such as vi/vim And emacs. It has many useful features such as syntax highlighting, line numbering, easy search and many more.

Installing Nano Editor on Linux

If for any reason nano is not already installed on your Linux distribution, you should be able to install it easily using the following commands:

# apt install nano [For Ubuntu/Debian] # yum install nano [For CentOS/Fedora]

Nano Hotkeys

Nano uses keyboard shortcuts for various functions such as searching for text in a file, aligning text, etc. These shortcuts are very easy to see while editing a file. They change automatically depending on what actions you take.

One thing you should know is that a keyboard shortcut with a ^ icon and a symbol (such as ^W) is a combination of the Ctrl key and that symbol (Ctrl + W in our example).

A combination shown to begin with M means it must be completed by pressing the Alt key and the next character.

Below are the options you will see when you first open nano :

  • G Get help
  • ^O Write down
  • ^W Where
  • ^K Cut text
  • ^J Align
  • ^C Current position
  • M-U cancel (back)
  • ^X Exit
  • ^R Read file
  • ^\ Replace
  • ^U Split text
  • ^T Check spelling
  • ^_ Go to line
  • M-E cancel (forward)

You don't need to remember every option since it's always in front of you. You can get a full list of keyboard shortcuts by pressing ^G (or pressing F1), which will open nano's help menu. You will notice that some shortcuts can be used with a single key.

For example, F1 for help or F2 to exit nano.

Nano Editor Keyboard Shortcuts

Creating a new file in Nano

Create new file as easy as running nano:

This will open the editor and after saving the file, it will ask you to provide a name to save the new file with.


Create a new file in Nano

Open file in Nano

To open the file you can run:

$nano ~/my_text_file.txt

The above command will try to open the file "my_text_file.txt" from your home directory. If the file does not exist, nano will try to create it.

Sometimes you may need to open a file and go to an exact row or column. Nano allows you to do this with:

$ nano +line,columns file

For example:

$ nano +3.2 ~/.bashrc

Will open your .bashrc file and the cursor will be located on the third line, second column.


Opening a file in Nano

Editing Files in Nano

After opening or creating files, you can start editing/recording immediately. Unlike vim, V nano there is no need to switch to edit mode. To move the cursor around the file, you can use the arrow keys on your keyboard.


Editing a file in Nano

Searching for text in Nano

You can search for text inside a file using ^W , which represents the " Where" This will open a search box above the menu where you can enter the text you're looking for:


Searching for text in Nano

You will also see that the bottom menu will change to show some Extra options. They pretty much explain themselves, so we'll look at the more important ones.

  • Search with regular expressions- Press M-R (Alt + R keys) and enter your query using the regular expressions you want to use.
  • Go to line- press ^T (Ctrl + T) and then the line where you want to move the cursor.
  • Replace text— press the ^R (Ctrl + T) button in search mode or ^\ in normal mode. You will be prompted to enter your original text, after pressing Enter you will be prompted to enter the text that will be used for the replacement. Finally, you will be asked whether you want to replace the matching instance of your search or all matches. If you select "No", the cursor will be moved to the next match.
  • Go to first line— press ^Y (Ctrl + Y).
  • Go to last line- press ^V (Ctrl + V).

Copy/Paste/Cut Text in Nano

Nano's interface is very similar to GUI text editors. If you want to copy or cut text in a graphics editor, you first need to select it. The same thing happens in nano. To mark up text, press Ctrl + ^, then move the cursors using the arrow keys.

  • To copy selected text, press Alt + ^.
  • To cut selected text, press ^K (Ctrl + K).
  • To paste the selected text, move the cursor to the desired position and press ^U (Ctrl + U).

Copying and pasting text in Nano

Save file to Nano

If you want to save the current changes to the file, press the combination ^O (Ctrl + O). If you are editing a new file, you will be prompted to provide a name for the file. This will save your current changes and nano will remain open so you can continue making changes to the file.

Save file with backup

Sometimes when editing a file, you may need to keep temporary copies of the same file just in case. You can use the -B option in nano, which will create a backup copy of the file you are editing. You can use it in combination with the -C option to tell nano where to save these backups as stated in the example:

$ nano -BC ~/backups myfile.txt

The above steps will make backup copies of the file myfile.txt in folder " backups", located in the user's home directory. Please note that the catalog Reserve copy must exist, otherwise nano will tell you that the directory is invalid.

Exit Nano Editor

To exit nano, simply press ^X (Ctrl+X keys). If the file has not yet been saved, you will be prompted to save changes using yes/no or cancel exit.

Conclusion

Nano is an easy-to-use command line text editor that attracts users with its simplicity. Its interface is similar to that of graphic editors, making it ideal for Linux newbies.

And distributed under the GNU GPL license. Currently included in Ubuntu distributions by default and does not require installation.
To run nano, open a terminal and run:

nano

Usage options

Using a standard command that allows you to get help on using the program, where you can view possible options for opening files and other information, you should run:

nano --help

We get the “exhaust” given below. To be repeated, the command

Program_name --help

Standard for all console programs.

Usage: nano [OPTIONS] [[+ROW,COLUMN] FILE]... Option Long form Meaning -h, -? --help Show this message +ROW,COLUMN Start at the specified row and row -A --smarthome Enable smart home button -B --backup Keep backups of existing files -C<дир>--backupdir=<дир>Directory for storing unique backups -D --boldtext Use bold font instead of the usual -E --tabstospaces Convert tabs to spaces -F --multibuffer Allow multiple file buffers -H --historylog Save and read line search/replace history -I --ignorercfiles Do not use on nanorc files -K --rebindkeypad Fix the problem small keyboard -L --nonewlines Do not add empty lines at the end of the file -N --noconvert Do not convert from DOS/Mac format -O --morespace Use an additional line for editing -Q<стр>--quotestr=<стр>Quote line -R --restricted Limited mode-S --smooth Line-by-line scrolling instead of half-screen -T<#чис>--tabsize=<#чис>Set tab width to #number of columns -U --quickblank Use quick clear status bar -V --version Show version and exit -W --wordbounds Use more precise word boundary detection -Y<стр>--syntax=<стр>Use syntax description for highlighting -c --const Always show cursor position -d --rebinddelete Fix Backspace/Delete problem -i --autoindent Automatically indent new lines -k --cut Cut from cursor to end of line -l --nofollow Don't follow symbolic links, override -m --mouse Allow mouse use -o<дир>--operatingdir=<дир>Set working directory -p --preserve Reserve XON (^Q) and XOFF (^S) buttons -q --quiet Silently ignore startup errors, such as rc file -r<#столбцы>--fill=<#столбцы>Set line break point to #columns -s<программа>--speller=<программа>Use alternative program spellcheck -t --tempfile Auto-record on exit, no questions asked -u --undo Allow undo feature [EXPERIMENTAL] -v --view View mode (read-only) -w --nowrap Don't wrap long lines -x -- nohelp Don't show the two help lines at the bottom -z --suspend Allow suspension -$ --softwrap Enable soft line wraps -a, -b, -e, -f, -g, -j (ignored, for Pico compatibility)

nano help text

nano editor designed to emulate the functionality and ease of use of the original editor UW Pico. The editor is divided into 4 main parts: the top line contains the version of the program, the current name of the file that is being edited, and whether changes have been made to the current file. The second part is the main editing window, which displays the file being edited. The status bar - line 3 from the bottom - shows various important messages. The two lines below show the most commonly used key combinations.

The notation system for key combinations is as follows: Combinations with Control are indicated by the symbol (^) and are entered by pressing the Ctrl button or pressing Escape Esc twice; combinations with Esc are indicated by the Meta m symbol and can be entered using the Esc, Alt or Meta buttons, depending on the keyboard used. Also, pressing Esc twice and then entering a three-digit number from 000 to 255 will enter the corresponding character.
The following combinations are available in the main editing window. Alternative combinations are shown in brackets:

Ctrl + G or F1 - Show this help
Ctrl + X or F2 - Close current buffer / Exit nano
Ctrl + O or F3 - Write current file to disk
Ctrl + J or F4 - Align current paragraph

Ctrl + R or F5 - Paste another file into the current one
Ctrl + W or F6 - Search text or regular expression
Ctrl + Y or F7 - Go to previous screen
Ctrl + V or F8 - Go to next screen

Ctrl + K or F9 - Cut the current line and save it to the clipboard
Ctrl + U or F10 - Paste the contents of the clipboard into the current line
Ctrl + C or F11 - Show cursor position
Ctrl + T or F12 - Check spelling if available

m + \ or m + | - To the first line of the file
m + / or m + ? - To the last line of the file

Ctrl + _ or m + G - Go to the specified line number and row
Ctrl + \ or m + R - Replace text or regular expression
Ctrl + ^ or m + Alt - Mark text at the current cursor position
m + W - Repeat last search

m + ^ or m + 6 - Copy the current line and save it to the clipboard
m + ) - Increase line indent
m + ( - Decrease line indent
Ctrl + F - Forward one character
Ctrl + B - Back one character
Ctrl + Space - Forward one word
m + Space - Go back one word
Ctrl + P - Go to previous line
Ctrl + N - Go to next line

Ctrl + Alt - Go to the beginning of the current line
Ctrl + E - To the end of the current line
m + (or m + 9 - To the beginning of the current paragraph; then to the next paragraph
m +) or m + 0 - To the end of the current paragraph; then the next paragraph
m + ] - To the corresponding bracket
m + − or m + _ - Scroll up one line without moving the cursor
m + + or m + = - Scroll down one line without moving the cursor
m+< или m + , - Переключить на предыдущий буфер
m + > or m + . - Switch to next buffer

m + V - Paste the following key combination as is
Ctrl + I - Insert tab at cursor position
Ctrl + M - Insert line at cursor position
Ctrl + D - Delete the character under the cursor
Ctrl + H - Delete character to the left of the cursor
m + T - Cut from current position to end of file

m + J - Align entire file
m + D - Count the number of words, lines and characters
Ctrl + L - Refresh current screen
Ctrl + Z - Pause editor (if enabled)
m + X - Help mode enable/disable
m + C - Constant display of enable/disable position
m + O - Use an additional line to edit enable/disable
m + Shift - Smooth scrolling enable/disable
m + P - Display spaces enable/disable
m + Y - Syntax highlighting enable/disable
m + H - Smart home button allow/deny
m + I - Allow/disable auto-indents
m + K - Cut to the end enable/disable
m + L - Automatic line breaking enable/disable
m + Q - Convert tabs to spaces input enable/disable
m + B - Make backups allow/disable
m + F - Multiple file buffers enable/disable
m+M - Mouse support enable/disable
m + N - Without conversion from DOS/Mac format, enable/disable
m + Z - Suspend enable/disable
m + $ - Soft line breaks enable/disable

Syntax highlighting

On remote servers to edit configs you can use nano - a fast, understandable, simple text editor with syntax highlighting. Agree, it's very convenient

1. Let's find where the example .nanorc files are located in our system. On Ubuntu they are usually in the /usr/share/nano/ directory. Let's copy the configuration file to our directory:

$ cp / etc/ nanorc ~/ .nanorc

2. Add lines to the file ~/.nanorc(on Ubuntu configuration examples are included in the delivery) to highlight the files we need if they are missing in standard file configurations:

## TeX include "/usr/share/nano/patch.nanorc"## POV-Ray include "/usr/share/nano/pov.nanorc" ## Perl include "/usr/share/nano/perl.nanorc" ## Nanorc files include "/usr/share/nano/nanorc.nanorc"## Python include "/usr/share/nano/python.nanorc"## C/C++ include "/usr/share/nano/c.nanorc" ## Groff include "/usr/share/nano/groff.nanorc"## Assembler include "/usr/share/nano/asm.nanorc" ## Ruby include "/usr/share/nano/ruby.nanorc" ## Manpages include "/usr/share/nano/man.nanorc" ## HTML include "/usr/share/nano/html.nanorc" ## Bourne shell scripts include "/usr/share/nano/sh.nanorc" ## Sun Java include "/usr/share/nano/java.nanorc"

3. If this is not enough, then take the Syntax Highlight Pack and adjust the highlighting when editing anything and everything.

mob_info