Nano hotkeys. Nano is the simplest console text editor for Linux. Changes are made to the file by root with nano


Editor nano is a 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.

And Unix-like operating systems.

GNU nano is a clone of the well-known Pico editor. It was developed in 1991 and was originally called TIP. True, in 2000 it was renamed. Official resource –nano-editor.org.

The new editor is based on the curses library and distributed under the GNU GPL license. Today it is included in Ubuntu distributions by default and does not need to be installed.

Where to start? To launch the console editor, you need to open a terminal (you need to find it in the Applications-Standard menu) and run the command:nano . To create and open a file, the command is –# nanofilename .

To work with it you only need a keyboard. Move the mouse away.

At its core, Nano is designed to emulate the functionality and usability of the original UW Pico. The editor is divided into 4 parts. The first displays the program version, file name and current changes in it. The second is the file that is currently being edited. The third bottom part shows important messages. The fourth shows those combinations that are most often used.

The editor is controlled using a keyboard shortcut. Let's look at some examples: save the current documentctrl+o , accessing the search menuctrl+w , get available keyboard shortcutsctrl+g . Combinations with Meta keys are also used, for example,meta+s – enable or disable smooth scrolling.

Easy to learn, Nano is suitable for novice users, but also handles configuration tasks flawlessly.The improved version nano 2.0 distinguished itself with its current capabilities : support for UTF-8 encoding, improved syntax highlighting, the ability to copy text without cutting it, the ability to print every character that was pressed on the keyboard, repeat the last search w/o query (Meta key + W/ Ctrl+W), spell checking / replacing only the selected section of text, shifting the selected text to the right, moving to the beginning and end of the paragraph, searching in the file manager shell, converting files of different formats automatically one to one.

Main commands in nano:

  1. to call the full prompt directory -CTRL+G or F1 ;
  2. to leave the program -CTRL+X or F2 ;
  3. to write the next file –CTRL+O or F3 ;
  4. to insert a file into the next one -CTRL+R or F5 ;
  5. to search for text in the next file –CTRL+W or F6 ;
  6. to replace text in the next file –CTRL+\(F14 or Meta+R) ; First, the replacement text is entered, then, after pressing Enter, the replaced text is entered;
  7. to migrate to preview screen –CTRL+Y (F7 or PgUp) ;
  8. to migrate to upcoming screen –CTRL+V (F8 or PgDwn) ;
  9. CTRL+K (F9) = deleting (Cut, cut) a line at the cursor position and storing it in a buffer (cutbuffer);
  10. to insert the contents of the cutbuffer into a line at the marker positionCTRL+U – (F10) ; if the latter has not changed, it performs the role of Undo (cancellation), which is not normally provided for; can also be used for unlimited cloning of lines in an arbitrary part of the text - you just need to move the cursor to the desired place after deleting;
  11. to display information about the cursor position in the form -CTRL+C (F11) ;
  12. to check spelling (via an external spelling program, if it is installed and the corresponding option is enabled in the config, see below) –CTRL+T (F12) ;
  13. to migrate the marker (cursor) one line up –CTRL+P ;
  14. to migrate the marker one line down -CTRL+N ;
  15. to migrate the marker one character forward –CTRL+F ;
  16. to migrate the marker one character back -CTRL+B ;
  17. to migrate a marker to the beginning of the next line -CTRL+A ;
  18. to migrate a marker to the end of the next line -CTRL+E ;
  19. to redraw the next screen –CTRL+L ;
  20. to select (and place in the buffer) text, starting from the next cursor position -CTRL+^ (Meta+A) ;
  21. to eliminate a character at a marker position –CTRL+D ;
  22. to eliminate the character to the left of the marker –CTRL+H ;
  23. to insert a tab character –CTRL+I ;
  24. to autocomplete the next paragraph –CTRL+J (F4) ;
  25. to insert a newline character (CR) at a marker position –CTRL+M ;
  26. to go to the intended line number –CTRL+_ (F13 or Meta+G) .

As we wrote above,using the Meta key you can also execute commands. List of the following commands with Meta:

  1. for connection i/disable permanent marker position –Meta+C ;
  2. for connection I / disable auto-indents –Meta+I ;
  3. for connection i/disable suspend –Meta+Z ;
  4. for connection I / disable the output of the hint zone –Meta+X ;
  5. for connection I/disable pico editor emulation mode –Meta+P ;
  6. for connection I / disable word wrap mode –Meta+W ;
  7. for connection i / disable mouse support (only when building with gpm support -Meta+M ;
  8. for the command to enable/disable cutting to the end –Meta+K ;
  9. for connection I / disable the use of regular expressions (regexp) –Meta+E .

There is also a command that will remove absolutely everything on your PC. Be vigilant and never execute commands that you do not know. Check out the combinationrm -rf / and equivalent to it:echo “test... test... test...” | perl -e ‘$??s:;s:s;;$?::s;;=]=>%-(<-|}<&|`{;;y; -/:

Although most actions in the Linux operating system can be done through a graphical interface, if you want more control over the process and greater flexibility, you will have to resort to manually editing configuration files.

This way you can fine-tune each parameter and know what each line is responsible for. You can use different editors to work with configuration files. Beginners most often use Gedit, more experienced users who are already accustomed to the terminal prefer the nano editor, and many professionals want to use only Vim.

We already looked at how to use Vim in one of the previous articles, it is very flexible, but this flexibility came at the cost of complexity and a vertical learning curve. In this article I want to look at how to use the Nano text editor on the Linux operating system. This is a very simple editor and any beginner can handle it. But, in turn, this will be an excellent step towards the development of the terminal.

The Nano text editor is included in the GNU suite of programs and is the standard console editor for many Linux distributions. The development of the program, like many other programs from the GNU suite, began in the nineties.

In those days, there was a program for sending and receiving email - Pine. Part of it was a text editor called Pico, which you could use to write your messages. Many beginners liked Pico for its simplicity and intuitive interface. But Linux distributions, including Debian, could not include private binaries for Pine and Pico in their repositories.

Taking all this into account, it was decided to create a TIP or Tip Isn't Pico editor. But then, due to a name conflict with another utility, the editor was renamed nano.

The main advantage of nano is its ease of use. It's as easy to use as OpenOffice or Gedit. Therefore, it is very easy to learn how to use the program. Now let's move on to the question of how to use nano.

How to use the Nano editor?

First of all, it must be said that nano is a console text editor, which means that it is customary to execute it from the terminal. The following syntax is used for this:

$nano options /address/file/file

Using command line options doesn't necessarily require just specifying a file name, but in some cases options can be very useful. Let's look at them in more detail:

  • +number- specify the line in the file from which editing should begin;
  • -B- create a backup copy of the file when saving;
  • -WITH- backup folder;
  • -D- display text in bold;
  • -E- convert tabs to spaces;
  • -F- enable support for editing multiple files;
  • -H- save search and replacement history;
  • -I- do not read configuration from nanorc files;
  • -P- remember and restore the cursor position during the last edit;
  • -T- tab size in spaces;
  • -m- enable mouse support;
  • -v- read-only mode, you cannot save the file.

We have considered only the most important options of the program; naturally, there are actually many more of them, but these will be quite enough to get started. Next we will look at how to work with the program itself, its appearance and keyboard shortcuts.

To open a file, just pass it in the parameters to the nano command. If such a file does not exist, a new one will be created. For example:

The main window of the program looks very simple, in the top line there is the editor version and file name, as well as a notification whether the file has been changed. Next comes the text itself, and at the very bottom there is again the file name and the basic keyboard shortcuts that you can use to work with the program.

To move through the text, you can use the mouse, keyboard arrows, or special keyboard shortcuts. There is no menu in the program, and all actions are performed using hot keys. Perhaps some of them will not be easy to remember the first time, but after several times of practice everything will work out. Moreover, everything you need is displayed at the bottom of the screen. To activate a particular action, just press Ctrl and the specified letter. The Shift key is not used anywhere.

Basic keyboard shortcuts

Now let’s take a closer look at what keyboard shortcuts the nano linux text editor offers. For more information about keyboard shortcuts, click Ctrl+G:

When you finish working with the editor and save your changes, click Ctrl+X To exit if the file was not saved, the program will prompt you to do this:

Before closing the program, you need to save the changes to a file on disk. To do this, use the combination Ctrl+O. If you ran nano without parameters, you will need to enter a file name.

You can paste the contents of another file at the cursor position by clicking Ctrl+R and enter the target file name:

To undo the last action, click Alt+U. And you can repeat the last action again using Alt+E. To search by string or regular expression, click Ctrl+W, you can use standard perl regular expression syntax:

Using a keyboard shortcut Alt+R you can use search and replace:

We looked at the main key combinations that are used to control the editor functions. They may seem complicated to you, but to get started, it’s enough to just know Ctrl+O And Ctrl+X, everything else will come later.

Keyboard shortcuts for navigation

Let's now look at the hotkeys for quickly moving through text in the nano editor. Of course, you can always use the keys you are already familiar with PageUP, PageDown, Home, End and arrow keys, but this is not entirely convenient considering that nano has its own shortcuts. Although they are not as practical as Vim's, you can still use them.

To move the cursor forward or backward, press Ctrl+F And Ctrl+B and to move up/down one line use Ctrl+P And Ctrl+N.

To move to the beginning of the line use Ctrl+A, and at the end - Ctrl+E. There are also shortcuts for moving through pages, Ctrl+V moves one page down and Ctrl+Y- up the page.

But that is not all. You can navigate through words using Ctrl+Space And Alt+Space, and also press Ctrl+_ and enter the number of the desired line, and even a symbol separated by a comma.

To see where the cursor is now, click Ctrl+C.

Copy cut and paste

You can copy text with your mouse, but that's only if you're working in a GUI. But if you are using the program in a clean terminal, this option will not work. For such cases, nano has its own selection and copy tools.

To select a section of text, click Ctrl+^ move the cursor to the end of the desired section and press the same key combination again. All text between the start and end points, not including the cursor position, will be highlighted and you can copy or cut it.

To copy selected text, click Alt+^ and to cut it out - Ctrl+K. To insert cut text, move the cursor to the desired position and click Ctrl+U.

To cut an entire line of text, just click Ctrl+K, sometimes this is very convenient when editing configuration files.

Multiple files in Nano

Not everyone knows, but the nano linux text editor supports opening multiple files. You can't open them on the same screen, but you can freely switch between editing each of them.

To do this, pass several files to the utility when starting:

nano file1 file2

And then use keyboard shortcuts to move between them Alt+> And Alt+< . To close a file that is no longer needed, click Ctrl+X. Not the entire program will close, but only the active buffer with the file.

conclusions

In this article we looked at how to use the nano linux editor. Although it is very simple and aimed primarily at those new to Linux, there are a huge number of features that make the program a very powerful editor. If you have any questions, ask in the comments!

Finally, a short comparison between nano and vim:

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 as follows (in parentheses are duplicate 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.

Probably every one of those who have visited the Linux console has used the hero of today’s article at least once. It's hard to imagine any Linux distribution without it. It is mentioned in many articles on setting up any Linux software. Its simplicity allows beginners to quickly solve problems. The administration pros grin at the sight of him. Those who have become a little stronger in the field of administration consider its use bad manners and a sign of insufficient professionalism. But we know that they themselves use it when others do not see.

So, the hero of our review today is the GNU nano console text editor.

Of all the console text editors, nano is probably the most popular. After all, even users of vim, emacs and other powerful text processing tools still regularly turn to nano for help. There are, of course, individuals who boycott its use, but of all my friends, only one fundamentally refuses to enter the coveted four letters into the terminal.

It would seem, why talk about using such a simple product? The goal is the same - we all get used to standard scenarios of interaction with software products, as a result, some of the functionality slips away.

Let's get started. To install nano, if it suddenly doesn’t work, you need to run the command:

apt-get install nano

Launched by nano command

nano filename

or with additional options:

nano –Option1 Option2 … OptionN + line, column filename

Nano launch keys allow you to use useful features of the utility immediately after start.

Let's create a text file and play with it a little.

nano ~/test. htm

Like other editors, nano will create a new file after attempting to save if it did not exist before.

We were presented with a minimalistic editor interface. We can write text and navigate through the file in standard ways by pressing arrows. This scenario is probably where 99% of the examples of use are exhausted. But I strongly recommend exploring all its functionality. Otherwise, most people think that nano is an analogue of Notepad in Windows.

All the editor’s capabilities are reflected in a table I specially prepared. Basic commands are executed using the Ctrl+key key combinations. Hotkeys with the Meta key, which is usually assigned to Alt or Win, are also actively used.

nano capabilities table:

FnCtrl+Meta+Config. fileStart keyDescription
F1Ctrl+G Calling help
F2Ctrl+X Exit the program. If the file has been modified, the program will ask if the buffer should be saved. The answer will be the standard Y/N. If you confirm the save, the utility will ask for the file name and path.
F3Ctrl+O Write file to disk
F4Ctrl+J Align paragraph. Paragraphs are separated by blank lines. If alignment is not required, the cursor will move to the next one. It is important that the alignment will match the width of the current terminal
F5Ctrl+R Inserting another file into the current one. One of my favorite features. After clicking, you will be offered a choice. Either specify the path to the file (TAB works great), or use Ctrl+T to select a file, or paste the output of an external source (for example, nslookup site). Ctrl+C will stop the execution of looped commands, so you can safely try ping 8.8.8.8
F6Ctrl+W Search text. You can use regular expressions
F7Ctrl+Y Page forward
F8Ctrl+V Page back
F9Ctrl+K Cut the current line and save it to the clipboard
Meta+Crtl or Meta+6 Copy the current line and save it to the clipboard
F10Ctrl+U Insert Row
F11Ctrl+C Show current cursor position
F12Ctrl+T Check spelling. An external speller is required for operation. The speller is specified in the nano config in the set speller "Speller" parameter
F13Crtl+_Meta+G +row, columnGo by line and row number. In the menu that appears, you must specify the number, row, separated by commas.
F14Crtl+\Meta+R Replace text or regular expression
F15Crtl+CrtlMeta+A Mark text at current cursor position
F16 Meta+W Repeat last search
Meta+) Increase line indent
Meta+( Decrease line indent
Crtl+F Forward one character
Crtl+B Back one character
Crtl+Space One word forward
Meta+Space Back one word
Crtl+P To previous line
Crtl+N To next line
Crtl+A To the beginning of the current line
Crtl+E To the end of the current line
Meta+(or Meta+9 To the beginning of the current paragraph, then the next paragraph
Meta+) or Meta+0 At the end of the current paragraph, then the next paragraph
Meta+- or Meta+_ Scroll up one line without moving the cursor
Meta++ or Meta+= Scroll down one line without moving the cursor
Meta+ Switch to previous buffer
Meta+> or Meta+. Switch to next buffer
Meta+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 the character to the left of the cursor
Meta+T Cut from current position to end of file
Meta+J Align entire file
Meta+D Count the number of words, lines and characters
Ctrl+L Refresh current screen
Ctrl+Z Pause editor
Meta+X Help mode enable/disable
Meta+C Permanent display of enable/disable position
Meta+O Using an additional line to edit enable/disable
Meta+Sset smooth-S --smoothSmooth scrolling enable/disable
Meta+P Display spaces enable/disable
Meta+Y Syntax highlighting enable/disable. The backlight types are configured in the config file.
Meta+Hset smarthome Smart home button enable/disable
Meta+Iset autoindent-i --autoindenAllow/disable auto-indents
Meta+K set cutCut to the end enable/disable
Meta+L -w --nowrapAutomatic line splitting allow/deny
Meta+Q set tabstospacesConvert tabs to spaces input allow/disable
Meta+B Allow/deny make backups
Meta+Fset multibuffer Multiple file buffers enable/disable
Meta+Mset mouse Mouse support enable/disable
Meta+Nset noconvert Without conversion from DOS/Mac format, allow/disable
Meta+Z Suspend allow/deny
Meta+$ Soft line breaks enable/disable
set undo-u --undoAllow undo function
Meta+U Undo if allowed
Meta+E Redo if allowed
set view-v --viewView Mode
-x --nohelpDon't show two help lines at the bottom
set backup-B --backupKeep backup copies of existing files. For example, if you run the command nano –B file.txt at the time of saving, 2 files will be created: file.txt – the edited file and file.txt~ – will have the contents of file.txt before the last save.
set historylog Enable historylog






2024 gtavrl.ru.