nano, a small and friendly text editor.
Tags: linux, productivity, beginners, tooling
Published: 2021-09-08 17:13:47

When we want to do simple changes in a file, we don't want to open an integrated development environment. For example when we have to edit a configuration file or search something within a file, we want to do this quickly, ideally keeping our hands on the keyboard. Always - no mouse support or graphical user interface needed.

Beside nano there are other well known command line text editors like [vi](https://www.vim.org/) or [emacs](https://www.gnu.org/software/emacs/). Nano is a superset of [pico](https://en.wikipedia.org/wiki/Pico_(text_editor)) written in C for Unix-like systems as a free software. It was released in 1999 and is part of the GNU project since 2001.

The reasons why we want to have a closer look on [nano](https://www.nano-editor.org/) today are:
- it is one of the most common used command line text editors
- it is included in most of the Linux distributions by default
- Mr. Robots fsociety uses it ;) 
- it has a _shortcut bar_ at the bottom of the screen, displaying some available commands
- it offers features like syntax highlighting, line numbers, regular expression search and replace, that pico does not have.


### Prerequisite
Install nano.
If we are on Mac OS X nano is installed by default. If nano is not installed on your Linux distribution we can install it with `sudo apt-get -y install nano`.

Once it is installed type `nano` in the terminal and we are using the command line editor. When we click `ctrl+g` the help text will be displayed. `ctrl` is displayed as `^` (caret symbol) in nano.

![image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ixqrqctgl20lc0uie7zf.png)



### Navigating
We can use the arrow keys to navigate around. But if we don't want to move the fingers away from the letters, we can use the following commands.

| command | explanation |
| :-------------: | ----------- |
| ctrl+b | move forward one char  |
| ctrl+f | move backward one char |
| ctrl+p | move one line up  |
| ctrl+n| move one line down  |
| ctrl+a | move to the beginning of a line |
| ctrl+e | move to the end of a line |
| ctrl+y | move to the beginning of a page |
| ctrl+v | move to the end of a page |
| ctrl+space | move forward one word |


### Editing
| command  | explanation |
| :-------------: | ----------- |
|  ctrl+c |  Cancel current command  |
|  ctrl+x |  Exit. You will be asked if you want to save changes. The shortcut bar at the bottom will display the available commands |
|  ctrl+o|  Writing out.  You will be asked to type a filename for the new file. The shortcut bar at the bottom will display the available commands |
| ctrl+r |  Insert content from another file into current buffer  |
| ctrl+k | Kut. Cut (Delete) current line |
| ctrl+u | Uncut. Pastes the line who was cut  |
| ctrl+6 | set a mark |


### Search and Replace
| command  | explanation |
|:-------------:| ----------- |
|  ctrl+w |  "Where is ...?" You will be asked, what to search for |
| alt+r | Find and replace. First you will be asked what to search for and then for the replacement text.|


You can find the entire nano manual [here](https://www.nano-editor.org/dist/v2.2/nano.html).