How to work with the nano command. GNU nano - console text editor

And Unix-like operating systems.

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

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

How to get started? To launch the console editor, you need to open the terminal (you need to find it in the Applications-Accessories menu) and run the command:nano . To create and open a file, the command is −# nano filename .

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

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

The editor is controlled by keyboard shortcuts. Consider examples: save the current documentctrl+o , accessing the search menuctrl+w , get available keyboard shortcutsctrl+g . It also uses shortcuts with Meta keys, for example,meta+s – enable or disable smooth scrolling.

The easy-to-learn Nano is suitable for novice users, but it also handles configuration tasks flawlessly.An improved version of nano 2.0 distinguished itself by 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 check / replace only the selected section of text, shift the selected text to the right, move to the beginning and end of the paragraph, search in the shell file manager, converting files of different formats automatically one to one.

The main commands in nano are:

  1. to call the full prompt directory −CTRL+G or F1 ;
  2. to leave the programCTRL+X or F2 ;
  3. for the record next fileCTRL+O or F3 ;
  4. to insert a file into the next -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 replacement text;
  7. to migrate to the preview screen -CTRL+Y (F7 or PgUp) ;
  8. to migrate to the upcoming screen -CTRL+V (F8 or PgDwn) ;
  9. CTRL+K (F9) = deleting (Cut, cut) the line at the cursor position and saving it in the buffer (cutbuffer);
  10. to insert the contents of the cutbuffer into the string at the position of the markerCTRL+U - (F10) ; 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 - you just need to move the cursor to the right place after deletion;
  11. to display information about the position of the cursor in the form -CTRL+C (F11) ;
  12. to check spelling (using 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 back one character -CTRL+B ;
  17. to migrate the marker to the beginning of the next line -CTRL+A ;
  18. to migrate the marker to the end of the next line -CTRL+E ;
  19. to redraw the next screen -CTRL+L ;
  20. to select (and buffer) text starting at 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 the marker position -CTRL+M ;
  26. to jump to the predetermined 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. to connect i/disable constant marker position –Meta+C ;
  2. to connect i/disable auto-indents -Meta+I ;
  3. to connect i/disable suspend –Meta+Z ;
  4. to connect i / disable the output of the hint zone -Meta+X ;
  5. to connect i/disable pico editor emulation mode -Meta+P ;
  6. to connect i/disable word wrap mode -Meta+W ;
  7. to connect 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. to connect i/off 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 its equivalent:echo “test… test… test…” | perl -e ‘$??s:;s:s;;$?::s;;=]=>%-(<-|}<&|`{;;y; -/:[email protected][-`(-);`-(/” -;;s;;$_;see’ may delete all information from your computer without your noticing. Therefore, watch what commands you execute.

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 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.

Ctrl + W is a shortcut for searching. The same effect can be achieved by pressing the F6 key. After entering the search term, press Enter . To redo your search, type Alt + W. In this menu, you can select older searches using the up/down arrow keys.

To switch back, you need to press Alt + B in the search dialog.

For more shortcuts press F1

Nano Basics Guide

^W

  1. Not in all system operation F1 for reference. Try ^G.
  2. Not in the whole system nano there is a help page

Yes, it's just a reference page below. For those who see this message [Sorry, support for this feature is disabled] instead of nano-enabled pages

^G(F1) Display this help text

^x(F2) Close current file buffer / Exit nano

^O(F3) Write current file to disk

^J(F4) Mark current paragraph

^R(F5) Paste another file into the current one

^W(F6) Search for string or regular expression

^Y(F7) Go to previous screen

^V(F8) Go to next screen

^K(F9) Cut the current line and store it in the buffer

^u(F10) Cut from buffer on current line

^ C(F11) Display cursor position

^T(F12) Invoke spell checker if available

M- \ (M- |) Go to first line of file

M-/(M-?) Jump to last line of file

^ _ (F13) (MG) Go to row and column number

^\ (F14) (MR) Replace string or regular expression

^^ (F15) (MA) Mark text at cursor position

MW(F16) Redo last search

M-^(M-6) Copy the current line and store it in the clipboard

M-) Current line indent

M-( Cancel current line

^F Go ahead one symbol

^B Return one character

^ Space Go one word

M-Space Return one word

^P Go to previous line

^N Go to next line

^A Move to the beginning of the current line

^E Go to the end of the current line

M-((M-9) Go to the beginning of the paragraph and then the previous paragraph

M-)(M-0) Jump straight out of paragraph; then the next paragraph

M-] Transition to matching bracket

M–(M-_) Scroll up to one line without scrolling the cursor

M-+(M-=) Scroll down one line without scrolling the cursor

M-< (M-) Switch to previous file buffer

M->(M-.) Move to the next file buffer

MV Paste next keystroke verbatim

^I Insert tab at cursor position

^M Insert a new line at the cursor position

^D Delete character under cursor

^H Delete character to the left of the cursor

MT Cut off from cursor position to end of file

MJ Justify the whole file

MD. Number of words, lines and characters.

^ L Refresh (redraw) the current screen

^Z Pause editor (if pause is enabled)

(MX) Enable/Disable permission mode

(MC) Constant display of the cursor position on / off

(MO) Using one more line to edit enable / disable

(MS) Smooth scrolling on/off

(MP) Enable / disable the display of spaces

(MY) Color syntax highlighting enable/disable

(MH) Turn on/off smart home

(MI) Auto indent enable/disable

(MK) Allow / disable

(ML) Enable / disable long line wrapping

(MQ) Convert entered tabs to spaces enable/disable

You can search for text in nano with Ctrl W.

Alt W (or Esc , W) will repeat the search. (Alternatively, leaving the field blank will default to the latest text.)

Pressing the Ctrl R key while in search mode will activate replace mode.

(Unfortunately, Ctrl W doesn't work when the Ctrl G help screen is displayed..)

For beginners 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 familiarity with the terminal is indispensable. 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 tell you in an accessible way how to use this text editor so that Linux does not seem like 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!

Nano launch

Text editor nano only works in terminal. One more clarification, before starting, the Linux operating system is case sensitive, if a word or part of a command is capitalized, then you need to type it like that, 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 with nano you need to write in the terminal like this:

Nano index.html

By the way, the command will help you find out in which directory you are now pwd , and what files are 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 that is sensitive to word wrapping, then enter the command in the terminal nano with additional key -w :

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

To open a document at a specific row or column nano +row,column filename

For example nano +3.2 /etc/hosts

Nano keyboard shortcuts for text editor control

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

Action name Nano hotkeys
Open file at 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 a file Alt | or Alt\
Move to end of file alt / or Alt?
Move forward a word Ctrl Space
Move to the beginning of the line Ctrl A
Move to end of 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" the entire line Ctrl K
Erase everything from cursor to end of file ALT T
Paste previously cut or copied line Ctrl U
Select part of the text copy or cut it (or delete) Move to the desired section of text

Clamp ALT-A

and move the keys ↓←→

Copy Alt-6

Cut or delete Ctrl K

Insert Tab Ctrl I
Paste text information from another file ctrl-r

specify the path to the file

In nano show row and column number CTRL C
Find a word in a text file CtrlW

write the search word

Find next CtrlW
Saving changes to a file Ctrl O

press Enter

Save the changes to the file and exit the nano editor Ctrl O

press Enter

Do not save changes Ctrl Z
Save changes and rename file ctrl x

press Y

enter a new filename

press Enter

I hope using the nano terminal text editor will not be such a big headache now!

Do you have any further 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!

Programs October 18, 2010

The nano editor is a small entry-level editor with a simple interface, often found as a standard editor on linux systems. The editor has a console character and is launched by the command nano, For example:

Opening and creating a file with the nano editor

Opening and creating a file in nano is simple. Need to dial:

Nano is a non-modal editor and you can start typing right away to insert text. If you are editing a configuration file such as /etc/fstab, use the -w option, for example:

There are several command line options:

  • -T # to set the amount (in characters) of the tab stop,
  • -i to enable automatic indentation,
  • -w, which disables line wrapping at the screen border (which is very important when editing configuration files), and so on.

Saving the document and exiting the nano editor

To save your changes, press Ctrl+O. To exit nano, press Ctrl+X. If you exit the editor and the file has changed, nano will prompt you to save the file. To refuse saving, just press N, and to confirm - Y. The editor will ask for a file name. Just enter a name and then press Enter.

If you accidentally confirm the need to save a file that you do not need to save, you can always refuse to save by pressing Ctrl + C when prompted for a file name.

Cutting and pasting text in the nano editor

To cut a single line, use Ctrl+K (hold Ctrl and press K). The line will disappear. To paste it, simply move the cursor to where you want to insert the line and type Ctrl+U. The line reappeared. To move multiple lines, simply cut them with multiple Ctrl+K presses in succession, and then paste them with a single Ctrl+U press. The whole paragraph appears where you need it.

If you need to act more gently, mark the text. Move the cursor to the beginning of the text to be cut. Press Ctrl+6 (or Alt+A). Then position the cursor at the end of the text to be cut; the marked text is highlighted. To uncheck it, just press Ctrl+6 again. To cut marked text, press Ctrl+K. Use Ctrl+U to paste it.

Finding text in the nano editor

Finding a string is easy: press Ctrl+W (for "WhereIs"), type what you want to find, and press Enter. To find the same line again, press Alt+W.

Note: In nano's help text, the Ctrl key is represented by "^", so Ctrl+W is shown as ^W, and so on. The Alt key is labeled M (for "Meta"), and Alt+W is shown as M-W.



Loading...
Top