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 or emacs. Nano is a superset of pico 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 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.
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.
Top comments (2)
I'm using bash/ssh since 15y, and I'm still loving nano. Maybe is too difficoult/complex to me using vim, for my use case, but nano just works for the type of file editing that I do.
I've managed to defeat "discomfort of using vim" and was a vim dude ever since, vim is noice