Nano is a text editor. Nano hotkeys Exit nano

List of hotkeys for nano. It's incomplete - missing some combinations that I haven't been able to test in action. Either because I don’t do yoga, or the Gnome settings are such that some combinations or certain keys are intercepted by it - for example, combinations like Alt-( and Alt-). When typing them, you need to use Shift (i.e. Alt-( on a regular keyboard is converted to Alt-Shift-[). And I have a change of layouts attached to Alt-Shift in the system. It overlaps the hot keys that I send to nano. But, this is all lyrics and lack of time, but here is the list

  • Home= Ctrl-a
  • end= Ctrl-e
  • pgup= ctrl-y
  • PgDn= ctrl-v
  • Cursor keys= Ctrl-(f,b,n,p)
  • Tab= Ctrl-i
  • backspace= ctrl-h
  • Delete= ctrl-d
  • return= Ctrl-m
  • Help- Ctrl-g
  • Exit- Ctrl-x
  • Save file- Ctrl-o
  • Toggle syntax highlighting-Alt-y
  • Go to next word- Ctrl-Space
  • Go to previous word- Alt Space
  • Go to the beginning of the line-Home
  • Go to end of line- end
  • Go to next paragraph-Alt-0
  • Skip to previous paragraph- Alt-9
  • Next page-PgDn
  • Previous page - PgUp
  • Go to line no.-Ctrl-_
  • Go to end of file-Alt-/
  • Go to the beginning of the file- Alt-\
  • Go to matching parenthesis-Alt-]
  • rewind down- Alt-=
  • rewind up-Alt-
  • Toggle text selection mode- Ctrl-6 (Ctrl-^). One of the few combinations where both 6 and ^ are unambiguous (i.e. you don't need to press shift for ^). To select text after switching on the selection mode, use the cursor keys.
  • Copy current selection- Alt-6 (Alt-^ or Ctrl-k Ctrl-u). Another combination that does not require pressing Shift for ^.
  • Cut current selection- Ctrl-k
  • Insert- Ctrl-u
  • Paste the contents of a file into a new buffer- Ctrl-r<имя файла>. If you need to insert the contents of the file into the current buffer in the place after the cursor, then first you need to turn off Multi-buffer mode for nano. This is done using the Alt-f combination.
  • Paste command output- Ctrl-r Ctrl-x
  • Search- Ctrl w
  • Find the next occurrence (Find Next…)- Alt-w or Ctrl-w Enter
  • Find-replace- Ctrl-\ or Alt-r
  • Search help- Ctrl-w Ctrl-g
  • Justify the current paragraph (where the cursor is located)- Ctrl-j
  • Justify the entire document-Alt-j

I mentioned Multi-buffer mode - this is nano's mode of operation, in which you can edit several files at the same time. Switching between multiple buffers is done using Alt-, and Alt- combinations. .

I also mentioned syntax highlighting.

Syntax highlighting, like other nano settings, must be specified in the nanorc. For the current user, this file is usually located here ~/.nanorc , and an example with a configuration can be taken from /usr/share/doc/nano/examples/nanorc.sample.gz

In Ubuntu, you can find ready-made configurations with syntax highlighting at /usr/share/nano/ . This directory contains the nano configuration files, one for each type of backlight. They are enabled by default.

If you need to change colors and other highlight settings, you can also see ready-made configurations with syntax highlighting. You can change files both in /usr/share/nano , and in home directory in the .nanorc file. In the first case, the changes will be global, in the second - only for the current user.

Editor nano- it's console text editor. It is in almost all Linux distributions, is available in macOS and can be run under Windows. nano is often used for editing configuration files, When GUI absent.

Management in nano is carried out from the keyboard using hot keys. At the bottom of the editor is a list of the main keyboard shortcuts. The ^ character means the Ctrl key. For example, ^X means the keyboard shortcut Ctrl+X . Characters are case insensitive, Ctrl+X is equivalent to Ctrl+x .

Let's take a look at how to perform basic operations when working with nano .

Create new file

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

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

After executing the command, the nano editor will start and a new empty file will open in it 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

A message will appear in the status line: File Name to Write: filename(if there is no file name, then you need to enter the file name). Press Enter to save changes.

Save and exit

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

Exit without saving changes

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

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

Copy and paste

Copying and pasting rows

To cut the whole line and put it in the buffer, move the cursor to the required line and press:
Ctrl+K

To insert line from buffer press:
Ctrl+U

Copying and pasting free text

To copy arbitrary text to the clipboard, it must first be selected. To start selection place the cursor at the beginning of the text to be copied and press:
ctrl+6

Move the cursor, the text will be highlighted.

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

or to cut highlighted text, press:
Ctrl+K

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

Text Search

To search for text within 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 search text (relative to the cursor). To move to the next occurrence, press:
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 prompted to enter the text you want to replace with. Type in a string and press Enter .
Next, a request will be issued to replace the found occurrence of the search 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 the found occurrences of the search string.

Hotkeys

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

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 cursor 1 page up (similar to PageUp )
ctrl+vMove cursor 1 page down (similar to PageDown )
ctrl+_Jump to a specific line (you will need to enter the line number).
ctrl+cShow on which line and at what position the cursor is located.
ctrl+wFinding text in a file. You must enter a search string.
Ctrl+\Find and replace text in a file. The search string is entered first, 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 the 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 tap on the Esc key. For example,
Esc+Esc+X
This is equivalent to Ctrl+X .

Only for reading

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

File backup

You can make sure that when a file is changed, a backup copy of it is created. For this, the -B switch is used:

If you modify 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 modification. Name backup matches the name source file with a tilde ~ at the end.

All commands are given by pressing key combinations - function buttons or a combination of Ctrl-letter, Alt-letter.

Alt is emulated by a single press on Esc, Ctrl - double. 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.
Line start - Home
End of line - End
Page down - PgDn
Pages up - PgUp

One word ahead - Ctrl-Space
One word back - Alt space(cursor 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-? (similar to Alt "this" button)
Down to the first blank line - Alt-0(or Alt-))
Up to the first empty line - Alt-9(or Alt-()


Turn on turn off line wrapping - Alt L
Jump to the line with the specified number - Alt-G

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

The 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 in the absence of a selection deletes the line. Either entirely, or from the cursor to the end of the line. Behavior is switched by combination Alt-K(by default, the mode is to delete the entire line, and Alt-K switches it back and forth).

Note that the deleted line is in the buffer, so it can be pasted with 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 major Control sequences are listed at the bottom of the terminal window.

Control-sequences - the following (in parentheses - duplicating function keys and sometimes Meta sequences):

    control+G (F1) - call the full tooltip menu;
  • control+X (F2) - exit from the program;
  • control+O (F3) - record of 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) - replacement of text in the current file; first, the replacement text is entered, then, after pressing 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) the line at the cursor position and saving it in the buffer (cutbuffer);
  • control+U - (F10) - inserting the contents of cutbuffer "a into the line at the cursor position; if the latter has not changed, it plays the role of Undo (cancellation), not normally provided; can also be used for unlimited cloning of lines in an arbitrary part of the text - it is enough to move the cursor to the right place after deletion;
  • control+C (F11) - display information about the position of the cursor in the form vr
  • control+T (F12) - spell checker (using external program spelling, if it is installed and the corresponding option is enabled in the config, see below);
  • control+P- moving the cursor one line up;
  • control+N- moving the cursor one line down;
  • control+F- moving the cursor one character forward;
  • control+B- moving 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) - selection (and buffering) of text, starting from the current cursor position;
  • control+D- deleting a character at the cursor position;
  • control+H- delete 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.

In this guide, you will learn how to install and use the Linux Nano text editor. While Vim and Emacs can be tricky for new Linux users, Nano is pretty easy to learn. That is why it is one of the most popular text editors for Unix and others. operating systems using the command line interface.

Before you start this guide, you will need the following:

  • Any package installer, for example apt-get

Step 1 — Installing the Nano Text Editor

It all depends on what OS you have installed, some of them already have a pre-installed editor Nano. You can skip this step if the editor Nano you already have installed. Click here to switch to Step 2 this guide.

To install a text editor Nano, your system must have a package installer, for example the command to install Nano on Ubuntu will be:

sudo apt-get install nano

IMPORTANT! Part sudo means to run this command as root user, in case you are not under account root user in this moment you will need to enter the appropriate password.

This completes the installation, now you should be able to use a text editor Nano. You can check this by typing this command:

Nano test.txt

It should open a new text editor window, and if you make changes to this file, they will be saved in a file named test.txt. To exit the editor, press the keyboard shortcut CTRL+X.

Step 2 — Using the Linux Text Editor – Nano

The basic command to open the editor is:

Nano filename


IMPORTANT! Instead of filename you can enter the file name you need or the name of an existing one. Note that if you want to edit an existing file, you must be in the same directory as that file. Another way is to specify the full path to the file.

After running the command, you will be taken to the editor window, where you can freely change the text using the editor Nano. Use the arrow keys on your keyboard to move the cursor through the text.

At the bottom of this window, you can see shortcuts to use with the editor Nano. Symbol ^ means you have to press CTRL + [Button] (CMD + [Button] for Mac users) to use selected commands:

Team Explanation
CTRL+A Go to the beginning of the line.
CTRL+E Go to end of line.
CTRL+Y Scroll down the page.
CTRL+V Scroll up the page.
CTRL+G This command will bring up a windowHelpwith all the necessary information about the commands you can use with the editorNano.
CTRL+O command to save. After use, it will ask for confirmation to change or save the file name, and after pressingEnterwill save your file.
CTRL+W One of the most useful commands. Used to search for a phrase in your text. She works like a team familiar to usCTRL+Fon other platforms. To search for the same phrase again, pressALT+W.
CTRL+K Cut the entire selected line to the "clipboard".
CTRL+U Paste the text from the "clipboard" into the selected line.
CTRL+J Formats the current paragraph.
CTRL+C Shows the current position of the cursor in the text (line/column/letter).
CTRL+X Exits the editorNano.If changes have been made, it will ask for permission to save the changes.
CTRL+R Opens a file with the Read File command. Inserts a file from disk at the current cursor position.
CTRL + \ Replace string or set expression.
CTRL+T Enable spell checking if available.
CTRL+_ Jump to a specific line and column number.
ALT+A Select text. First, move the cursor to the location where the beginning of the part of the text you want to highlight is located. Next clickALT+A. Now move the cursor with the arrow keys on your keyboard to the right to highlight the text. You can use this command in combination withCTRL+Kto cut a certain part of the text to the "clipboard".

These are the main and most useful commands to work in the editor Nano. Don't forget to use the command CTRL+G to display a window Help.

IMPORTANT! If you are a Mac user use instead CTRLcmd.

Conclusion

In this tutorial, you have learned how to install and use the Nano text editor. For tutorials about bash, SSH and VPS visit our tutorials page.

The nano editor may well play the role of a kind of shock absorber for a novice user. Yes, it's not emacs, and not even joe. But he copes with the task of configuring successfully. And in development and handling - it is simple as a rake. It is no coincidence that in many Linux distributions it is offered as a system-wide one. IN Gentoo Linux, where during installation the need for manual editing of configuration files arises quite often - it is simply the only editor available at the installation stage of the system. In CRUX and Archlinux, however, during installation, it is adjacent to vi - which mimics the original one, and therefore may also be preferable.

The nano editor is started at the command line with the following syntax: nano /path_to_file/file. rice. 1

If you indicated non-existent file, then it will be created.

After running the above command, you will see something similar to Fig. 2.

I think it makes no sense to explain that moving the cursor, as well as deleting text, is done with the corresponding keyboard keys, as in other editors. The remaining nano functions are controlled using control sequences, the list of which is taken from http://posix.ru/apps/nano_editor/ and is given below.

In nano, there are two types of control sequences - the actual control sequences, control+literal, and meta-sequences, Meta+ letter. Through the former, text editing and file operations are carried out. Control sequences are partially duplicated by function keys F1-F16(call F13-F16- through a combination Shift+F1-F4). Meta sequences are for changing editor settings (the same result is achieved with command line options).

Let me remind you that on a PC keyboard, the role of the Meta-key is usually performed by pressing the key alt(in some layouts - specifically alt"and right, or, conversely, left), or pressing and releasing a key Escape.

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

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

    control+G (F1) - call the full tooltip menu;
  • control+X (F2) - exit from the program;
  • control+O (F3) - record of 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) - replacement of text in the current file; first, the replacement text is entered, then, after pressing 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) the line at the cursor position and saving it in the buffer (cutbuffer);
  • control+U - (F10) - inserting the contents of cutbuffer "a into the line at the cursor position; if the latter has not changed, it plays the role of Undo (cancellation), not normally provided; can also be used for unlimited cloning of lines in an arbitrary part of the text - it is enough to move the cursor to the right place after deletion;
  • control+C (F11) - display information about the position of the cursor in the form vr
  • control+T (F12) - spell checker (using an external spelling program, if it is installed and the corresponding option is enabled in the config, see below);
  • control+P- moving the cursor one line up;
  • control+N- moving the cursor one line down;
  • control+F- moving the cursor one character forward;
  • control+B- moving 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) - selection (and buffering) of text, starting from the current cursor position;
  • control+D- deleting a character at the cursor position;
  • control+H- delete 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.

Meta sequences usually work like switches. With their help, the following actions are performed:

  • Meta+C- enable/disable constant cursor position;
  • Meta+I- enable/disable auto-indents;
  • Meta+Z- enable/disable suspend;
  • Meta+X- enable/disable prompt zone output;
  • Meta+P- enable/disable pico editor emulation mode;
  • Meta+W- enable/disable word wrap mode;
  • Meta+M- enable/disable mouse support (only when building with gpm support;
  • Meta+K- enable/disable cutting to the end;
  • Meta+E- enable/disable use regular expressions(regex).
In addition, nano also provides external agent configuration - user config ~/.nanorc . Having performed some manipulations in it, you can somewhat expand the functionality of the editor, in particular, provide syntax highlighting.
  • Sergey Savenkov

    some kind of “scanty” review ... as if in a hurry somewhere