Menu
Is free
registration
home  /  Firmware/ Nano save the file. Working with the nano editor: basic keyboard shortcuts

Nano save the file. Working with the nano editor: basic keyboard shortcuts

List of hotkeys for nano. It is incomplete - some combinations are missing that I was not able to test in action. Either because I don't do yoga, or the Gnome settings are such that it intercepts some combinations or individual keys - for example, combinations like Alt- (and Alt-). When typing them, you must use Shift (i.e. Alt- (on regular keyboard converted to Alt-Shift- [). And I have to change layouts on Alt-Shift in the system. It also overrides those hotkeys 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
  • Output- Ctrl-x
  • Save file- Ctrl-o
  • Toggle syntax highlighting- Alt-y
  • Move to next word- Ctrl-Space
  • Move to the previous word- Alt-Space
  • Move to start of line- Home
  • Move to end of line- End
  • Go to next paragraph- Alt-0
  • Go to the previous paragraph- Alt-9
  • Next page- PgDn
  • Previous page- PgUp
  • Go to line No.- Ctrl-_
  • Move to the end of the file- Alt- /
  • Go to the beginning of the file- Alt- \
  • Move to matching parenthesis- Alt-]
  • Rewind down- Alt- =
  • Rewind up- Alt–
  • Toggle text selection mode- Ctrl-6 (Ctrl- ^). One of the few combinations in which both 6 and ^ are unambiguous (i.e. you don't have to press shift for ^). To select text after turning 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 the current selection- Ctrl-k
  • Insert- Ctrl-u
  • Paste the contents of the 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 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 the nano mode in which you can edit multiple files at the same time. Switching between several buffers is done using Alt- and Alt- combinations. ...

I also mentioned syntax highlighting.

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

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

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

And Unix-like operating systems.

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

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

How to get started? To start 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 -# nano filename .

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

At its core, Nano is built to emulate the functionality and usability of the original UW Pico. The editor is divided into 4 parts. The first one displays the program version, file name and current changes in him. The second is the file that is being edited on this moment... The third bottom section shows important messages. The fourth shows the combinations that are most commonly used.

The editor is controlled by a keyboard shortcut. Let's look at some examples: save the current documentctrl + o , access to the search menuctrl + w to get the available keyboard shortcutsctrl + g ... Also used 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 each 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 area 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 different format automatically one to one.

The main commands in nano are:

  1. to invoke the full hint 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 the 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 replaceable 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 with saving it in the buffer (cutbuffer);
  10. to insert the content of the cutbuffer into the line at the marker positionCTRL + U - (F10) ; if the latter has not changed, it performs the role of Undo, 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 desired place after deleting;
  11. to display information about the position of the cursor in the form -CTRL + C (F11) ;
  12. to check spelling (using external program spelling, if it is installed and the corresponding option is enabled in the config, see below) -CTRL + T (F12) ;
  13. to migrate 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 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 place in the buffer) text, starting from the next cursor position -CTRL + ^ (Meta + A) ;
  21. to eliminate the character at the 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 line feed character (CR) at the marker position -CTRL + M ;
  26. to jump to a 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 permanent marker position -Meta + C ;
  2. to connect i / disable auto margins -Meta + I ;
  3. to connect i / disable suspension -Meta + Z ;
  4. to connect i / disable output zone prompt -Meta + X ;
  5. to connect i / disable pico editor emulation mode -Meta + P ;
  6. to connect i / disable 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 use 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 are unknown to you. Check out the combinationrm -rf / and equivalent to it:echo “test… test… test…” | perl -e ‘$ ?? s:; s: s ;; $? :: s ;; =] =>% - (<-|}<&|`{;;y; -/:[email protected][-` (-); `- (/” - ;; s ;; $ _; see ’ can unnoticeably delete all information from your computer. Therefore, watch what commands you execute.

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

nano

Usage options

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

nano --help

We get the "exhaust" below. It should be repeated, the command

Program_name --help

Standard for all console programs.

Usage: nano [OPTIONS] [[+ ROW, COLUMN] FILE] ... Option Long form Value -h, -? --help Show this message + LINE, COLUMN Start at specified line and row -A --smarthome Enable home smart button -B --backup Back up existing files -C<дир>--backupdir =<дир>Directory for storing unique backups -D --boldtext Use bold instead of normal -E --tabstospaces Convert tabs to spaces -F --multibuffer Allow multiple file buffers -H --historylog Save and read string search / replace history -I - -ignorercfiles Do not use on nanorc files -K --rebindkeypad Fix small keyboard problem -L --nonewlines Do not add blank lines at the end of the file -N --noconvert Do not convert from DOS / Mac format -O --morespace Use an extra line for editing -Q<стр>--quotestr =<стр>Quote line -R --restricted Restricted mode -S --smooth Line-by-line scrolling instead of semi-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 issue Backspace / Delete -i --autoindent Automatic indent on new lines -k --cut Cut from cursor to end of line -l --nofollow Do not follow symbolic links, rewrite -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, e.g. rc file -r<#столбцы>--fill =<#столбцы>Set line break to # columns -s<программа>--speller =<программа>Use alternative spell checker -t --tempfile Auto-write on exit, no questions asked -u --undo Enable undo function [EXPERIMENTAL] -v --view View mode (read only) -w --nowrap Do not wrap long lines - x --nohelp Don't show two help lines at the bottom -z --suspend Allow suspend - $ --softwrap Enable soft line wrapping -a, -b, -e, -f, -g, -j (ignored, for compatibility with Pico )

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

The system of notation of key combinations is as follows: Combinations with Control are denoted by the symbol (^) and are entered by pressing the Ctrl key or pressing Escape Esc twice; combinations with Esc are indicated by the symbol Meta m and can be entered using the Esc, Alt or Meta keys, 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 parentheses:

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

Ctrl + R or F5 - Paste another file into the current one
Ctrl + W or F6 - Search for text or regular expression
Ctrl + Y or F7 - Go to the 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 - Backward one character
Ctrl + Space - Forward One Word
m + Space - Back one word
Ctrl + P - Move to the previous line
Ctrl + N - To the next line

Ctrl + Alt - To the beginning of the current line
Ctrl + E - Move to the end of the current line
m + (or m + 9 - At the beginning of the current paragraph; then the next paragraph
m +) or m + 0 - At the end of the current paragraph; then next paragraph
m +] - To the corresponding parenthesis
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 next key combination as is
Ctrl + I - Insert tab stop at cursor position
Ctrl + M - Insert a line at the cursor position
Ctrl + D - Delete the character under the cursor
Ctrl + H - Delete character to the left of the cursor
m + T - Cut from the current position to the end of the file

m + J - Justify the entire file
m + D - Count the number of words, lines and characters
Ctrl + L - Refresh the current screen
Ctrl + Z - Pause editor (if enabled)
m + X - Help mode enable / disable
m + C - Permanent display of position enable / disable
m + O - Use an additional line for editing 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 enable / disable
m + I - Auto-indentation enable / disable
m + K - Cut to end enable / disable
m + L - Automatic line splitting enable / disable
m + Q - Convert tabs input to spaces enable / disable
m + B - Make backups enable / disable
m + F - Multiple file buffers enable / disable
m + M - Mouse support enable / disable
m + N - No conversion from DOS / Mac format enable / disable
m + Z - Suspend enable / disable
m + $ - Soft line break enable / disable

Syntax highlighting

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

1. Let's find where in our system are the sample files .nanorc. 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 not present in the standard configuration file:

## 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 set up the highlighting when editing everything and everyone.

,

The days when Linux seemed like a puzzle to newbies are long gone. Most popular nowadays Linux-distributions have a convenient and intuitive graphical interface, as well as the standard programs supplied with them. But there are also exceptions. Text editor Nano, for example, does not have GUI using the command line interface instead. What is it for if there is gedit?


Nano used mainly in server rooms Linux, it is convenient when editing configuration files and, if you have decided to master the terminal, along the way it will be highly desirable to master and Nano... There is nothing particularly complicated in this, of all console text editors Nano is the easiest to use, you just need to know the basic key combinations used to work with files and text.

Installation and launch

In the latest versions Ubuntu editor Nano is present by default and therefore does not need to be installed.

To start it, you need to open a terminal and run the command nano... If the terminal responds with a message "Command not found" or something like that, then it will mean that the editor is not installed. In this case, you will need to install it by executing the following command in the console right there:

sudo apt-get install nano

To start the editor, one command is enough - nano... This will create a new file in the current directory. To determine which folder is the current one, you can use the command pwd in the terminal. If you need to open a specific file, specify its name, and if it is located in a folder other than the current one, add the full path to it, as shown in the example of the second command:

nano hello.tхt
nano /home/kompick/hello.tхt

As for the config files, when opening them after nano a key should be added -w, this is important because it disables line wrapping, which is not used in system files. The editor interface is represented by a console window, in the upper part of which the version of the program and the name of the current file, as well as the status (whether it was changed or not) ... At the bottom of the window there are two lines showing the most frequently used keyboard shortcuts. The status bar is also displayed at the bottom, which displays various messages and fields for commands, for example, the F6 button starts a text search.

Basic principles of working with the Nano editor

Hotkey designations may confuse a novice user a little, but this is only at first. Symbol (^) means Ctrl key and (M) Meta- Alt or Esc key. All this can be found in the built-in help. nano triggered by pressing ^ + G, that is, Ctrl + G.

You can use the arrow keys to move through the content, to save changes - Ctrl + O and then enter Y to confirm and N to cancel. At the time of saving, the editor asks for a file name, which must be entered in a special field at the bottom of the window.

To undo the changes made to the still unsaved file, you need to press Ctrl + C. For cutting entire lines and paragraphs into nano the combination Ctrl + K is responsible, for their insertion - Ctrl + U. To select certain line elements, use Ctrl + 6 or Alt + A, to call the search line - Ctrl + W or F6. Commands Ctrl + A and Ctrl + E allow you to quickly move to the beginning and end of a line, commands Ctrl + Y and Ctrl + V - scroll the contents of a text file up and down. Finally, Ctrl + X is used to exit the editor to the terminal.

But all this is only part of the functionality. nano... The editor supports counting words, lines and characters, working with multiple files at once, creating backup copies of edited documents, using the mode "only for reading", enable partial mouse support, describe the syntax for highlighting, change the tab width, enable autosave on exit, and much more. Additional parameters are set mainly when starting the editor, but some, for example, the key responsible for the backup -b can be used when saving a file.

Additional features nano it is worth noting the customization of the appearance of the console window.

The nano editor may well play the role of a shock absorber for a novice user. Yes, it's not emacs, or even joe. But he copes with the task of configuration successfully. And in the development and handling - simple as a rake. It is no coincidence that many Linux distributions offer it as a system-wide one. In Gentoo Linux, where the need for manual editing of configuration files arises quite often during installation, 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 - imitating the very original, and therefore may also be preferable.

The nano editor is launched on the command line with the following syntax nano / path_to_file / 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 with the corresponding keyboard keys, as in other editors. The rest of the 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 control itself, Control+ letter, 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- by combining Shift+F1-F4). Meta sequences are used 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"and right, or, on the contrary, left), or pressing and releasing a key Escape.

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

The 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) - write 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) - replace text in the current file; the replacement text is entered first, 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) = delete (Cut) the line at the cursor position and save it in the buffer (cutbuffer);
  • Control+U - (F10) - inserting the contents of the cutbuffer "a into the line at the cursor position; if the latter has not changed, it plays the role of Undo (undo), which is 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 desired place after deleting;
  • Control+C (F11) - output information about the position of the cursor in the form of vr
  • Control+T (F12) - spell check (using 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) - selection (and placing in the buffer) of the 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- insertion of a tabulation character;
  • Control+J (F4) autocomplete the current paragraph;
  • Control+M inserting a line feed 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-indentation;
  • Meta+Z- enable / disable suspension;
  • Meta+X- enable / disable display of the prompt zone;
  • Meta+P- enable / disable pico editor emulation mode;
  • Meta+W- enable / disable hyphenation 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 the use of regular expressions (regexp).
In addition, nano also provides an external configuration tool - the user config ~ / .nanorc. Having performed some manipulations in it, you can slightly expand the functionality of the editor, in particular, provide syntax highlighting.