Nano end of file. Nano - text editor

Today we will talk about the GNU nano console text editor.

History of GNU nano

GNU nano is a clone of the Pico text editor that comes bundled with the Alpine email client. We have already talked about the latter in two articles (see links at the end of the article). Gnu nano was born in 1999, when Chris Allegretta began creating a clone of the Pico editor. Initially, the new editor was named TIP, which was an acronym: TIP isn't Pico. Quite quickly, the name of the program had to be changed to nano. This happened on January 10, 2000. The reason was a name conflict with another program that also called tip. The latter was responsible for establishing communication between a terminal and a remote host and was included in many Unix distributions (for example, Solaris).

First start

To get started with GNU nano, go to the console or launch a terminal emulator. It should be noted here that all further work will be performed in Linux Mint 14 "Nadya".

Once you are in the console or terminal emulator, issue the command:

$ nano filename

After successfully completing the latter, you will see the GNU nano program window. At the top of the screen the program version will be indicated (in our case 2.2.6) and the name of the open file (or simply “New Buffer”, as when you first start GNU nano - see Fig. 1). Next comes the editing window, the status bar. And the very bottom part is a kind of hint, which is a description of the key combination and the actions that will be performed when these keys are pressed. For example:

^G (or F1)

where "^" is Ctrl;

will result in the "nano help text" being displayed. You can scroll through the help using the cursor keys. Or using keyboard shortcuts:

^N — move forward one line;

^P — go back one line;

^V — move forward one screen;

^Y - go back one screen.

Figure 1. GNU nano - first start

To exit the help and return to the main window, press the following key combination:

^X (or F2)

Please note once again that you can use the hint at the bottom of the screen. In addition, this hint is “contextual” in nature. In other words, it changes depending on where you are now (main window, help, etc.). Please note that in addition to using keyboard shortcuts with Ctrl, so-called Meta sequences (denoted by the letter "M") are used. For example, to enable/disable the display of a hint, use the following key combination:

Entering a Meta sequence begins with the Esc or Alt key, and then the subsequent key (in our case, X).

So we're back in the main GNU nano window. Now let's type some text. And then save it by pressing the key combination:

^O (or F3)

When saving a file, the program will prompt you to enter the name of the file that needs to be saved (see Fig. 2):

Recording file name:

Type a name, such as Text, and press Enter.

Figure 2. Saving text to a file in GNU nano

After which, GNU nano will save the file and display information about the number of lines saved.

Editing text

During editing you have to perform various actions. For example, move through the text. We have already said partly about this above. Now let's continue.

To move the cursor forward one character, use the following combination:

and back one character:

To move the cursor to the beginning of the current line, press:

and at the end of the current line:

You can delete characters in text using “Delete” and “Backspace”, and the keyboard shortcuts ^D and ^H, respectively.

In order to cut a line in the text and save it to the clipboard, you need to click:

^K (or F9)

You can paste the contents of the clipboard into the current line as follows:

^U (or F10)

You can copy the current line (saving it to the clipboard) using keyboard shortcuts:

and then paste, respectively, using (^U or F10).

You can cut content from the current cursor position to the end of the file as follows:

This concludes the review of the editing capabilities available in GNU nano and say a few words about the additional capabilities of the program.

Additional features

GNU nano allows you to get information about the current cursor position. To do this, just use the keyboard shortcut:

After pressing this key sequence, you will see information in the following format (see Fig. 3):

Line 25/25(100%), row 1/1 (100%), symbol 100/100 (100%)

Figure 3. Obtaining information about the current cursor position

To count the number of words, lines and characters, you can use the following sequence:

After pressing this key combination, you will see a message in the format:

Words: 3 Lines: 5 Characters: 28

The transition to the required line of text is carried out using the following key sequence (the “_” character is entered with the Shift key pressed):

^_

after which you will see the following message:

Enter the line number, row number (a row can be designated as the position of a character in a line):

Conclusion

GNU nano is a clone of the Pico text editor that came with the Alpine email client. The program was first released in 1999.

GNU nano - easy to use console text editor. Its capabilities are sufficient to solve most relevant tasks related to text editing.

In addition to the basic capabilities (moving around a document, between characters, copying/cutting/pasting lines), the program has a number of additional features: obtaining information about the current position of the cursor, counting words, lines and characters, moving to the required line.

List of hotkeys for nano. It is incomplete - it is missing some combinations that I was not able to test in action. Either because I don’t do yoga, or Gnome’s settings are such that some combinations or individual 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 in my system, Alt-Shift is linked to changing layouts. This is what overrides those hot keys that which I send to nano. But these are 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 start of line- Home
  • Go to end of line-End
  • Go to next paragraph-Alt-0
  • Go 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 bracket-Alt-]
  • Rewind down-Alt-=
  • Rewind up-Alt–
  • Switching text selection mode- Ctrl-6 (Ctrl-^). One of the few combinations in which both 6 and ^ are unambiguous (i.e., you don’t need to press shift for ^). To select text after turning on the selection mode, you must use the cursor keys.
  • Copy current selection- Alt-6 (Alt-^ or Ctrl-k Ctrl-u). Another combination that doesn't 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 paste the contents of the file into current buffer to the place after the cursor, then you first 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 next occurrence (Find Next...)- Alt-w or Ctrl-w Enter
  • Find-replace- Ctrl-\ or Alt-r
  • Search help- Ctrl-w Ctrl-g
  • Align the width of the current paragraph (where the cursor is located)- Ctrl-j
  • Align the width of the entire document- Alt-j

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

I also mentioned syntax highlighting.

Syntax highlighting, like other nano settings, must be written in the nanorc file. For the current user, this file is usually located here ~/.nanorc, and an example with the 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 nano configuration files, one for each backlight type. They are enabled by default.

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

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

The nano editor is launched in the command line with the following syntax nano /file_path/file. rice. 1

If you specified a non-existent file, it will be created.

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

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

In nano there are two types of control sequences - actual control sequences, Control+letter, and meta-sequences, Meta+litera. The former are used for text editing and file operations. Control sequences are partially duplicated by function keys F1-F16(call F13-F16- through combination Shift+F1-F4). Meta sequences are intended to change 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"a right, or, conversely, left), or pressing and releasing a key Escape.

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

Control sequences are the following (in brackets - 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 Right 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.

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

  • Meta+C- enable/disable permanent cursor position;
  • Meta+I- enable/disable auto-indents;
  • Meta+Z- enable/disable suspension;
  • Meta+X- turn on/off the display of the hint zone;
  • 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- allow/prohibit cutting to the end;
  • Meta+E- enable/disable the use of regular expressions (regexp).
In addition, nano also provides an external configuration tool - the user config ~/.nanorc. By performing some manipulations in it, you can somewhat expand the functionality of the editor, in particular, provide syntax highlighting.

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 others powerful tools text processing, they 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 escapes.

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

either with additional options:

nano –Option1 Option2 … OptionN + line, column filename

Nano launch keys allow you to use it immediately after start useful features utilities.

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

nano ~/test. htm

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

We were presented with a minimalistic editor interface. We can write text, navigate the file using standard methods by clicking the 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 fine), or use Ctrl+T to select the file, or paste the output 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 allow/deny
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 Do backups allow/deny
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

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
Paste 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
Preservation changes made to 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!