Difference between revisions of "Nano"
(→Method One) |
(→Method One) |
||
Line 101: | Line 101: | ||
=== Method One === | === Method One === | ||
− | [[Sudo|sudo]] from the core repository is compiled with <code>--with-env-editor</code> by default and honors the use of the <tt>VISUAL</tt> and <tt>EDITOR</tt> variables. | + | [[Sudo|sudo]] from the core repository is compiled with <code>--with-env-editor</code> by default and honors the use of the <tt>VISUAL</tt> and <tt>EDITOR</tt> variables. To establish nano as the <code>visudo</code> editor for the duration of the current shell session, set and export the <tt>EDITOR</tt> variable before calling <code>visudo</code> |
export EDITOR=nano | export EDITOR=nano |
Revision as of 09:25, 18 February 2009
Contents
Introduction
Nano (or nano) is a text editor which aims to introduce a simple interface and intuitive command options to console based text editing. nano is the default console editor in distributions such as Ubuntu and supports features including colorized syntax highlighting, DOS/Mac file type conversions, spellchecking and UTF-8 encoding. nano Screenshot.
Package Installation
nano is part of the official Arch Linux (core) repositories.
$ pacman -Si nano
Repository : core Name : nano Version : 2.0.9-1 URL : http://www.nano-editor.org Licenses : GPL Groups : base Provides : None Depends On : glibc ncurses texinfo Optional Deps : None Conflicts With : None Replaces : None Download Size : 391.35 K Installed Size : 1144.00 K Packager : Andreas Radke <andyrtr@archlinux.org> Architecture : i686 Build Date : Mon 22 Sep 2008 10:20:00 AM PDT MD5 Sum : fa5017796de45d0e7baed3ba019dc6dd Description : Pico editor clone with enhancements
Install the latest version of nano:
# pacman -Sy nano
Configuration
Creating ~/.nanorc
The look, feel and function of nano is typically controlled by way of either command-line arguments, or configuration commands within the file ~/.nanorc.
A sample configuration file is installed upon program installation and is located at /etc/nanorc.The file ~/.nanorc must be first created by the user:
$ cd ~ $ touch .nanorc
or
$ cp /etc/nanorc ~/.nanorc
Proceed to establish the nano console environment by setting and/or unsetting commands within .nanorc file.
nano Usage
Special Functions
- Ctrl key modified shortcuts (^) respresenting commonly used functions are listed along the bottom two lines of the nano screen.
- Additional functions can be interactively toggled by way of Meta (typically Alt) and/or Esc key modified sequences.
Shortcut Lists Overview
- ^G Get Help (F1)
- Displays the online help files within the session window. A suggested read for nano users of all levels
- ^O WriteOut (F3)
- Save the contents of the current file buffer to a file on the disk
- ^R Read File (F5)
- Inserts another file into the current one at the cursor location
- ^Y Prev Page (F7)
- Display the previous buffered screen
- ^K Cut Text (F9)
- Cut and store the current line from the beginning of the line to the end of the line
- ^C Cur Pos (F11)
- Display line, column and character position information at the current location of the cursor
- ^X Exit (F2)
- Close and exit nano
- ^J Justify (F4)
- Aligns text according to the geometry of the console window
- ^W Where (F6)
- Perform a case-insensitive string, or regular expression search
- ^V Next Page (F8)
- Display the next buffered screen
- ^U UnCut Text (F10)
- Paste the contents of the cut buffer to the current cursor location
- ^T To Spell (F12)
- Spellcheck the contents of the buffer with the built-in spell, if available
Ctrl+g
within nano and the nano Command Manual for complete descriptions and additional support.Selected Toggle Functions
- Meta+c (or Esc+c)
- Toggles support for line, column and character position information.
- Meta+i (or Esc+i)
- Toggles support for the auto indentation of lines
- Meta+k (or Esc+k)
- Toggles support for cutting text from the current cursor position to the end of the line
- Meta+m (or Esc+m)
- Toggles mouse support for cursor placement, marking and shortcut execution
- Meta+x (or Esc+x)
- Toggles the display of the shortcut list at the bottom of the nano screen for additional screen space
Tips & Tricks
Replacing vi with nano
Casual users may prefer the use of nano over vi for its simplicity and ease of use and may opt to replace vi with nano as the default text editor for commands such as visudo
.
Method One
sudo from the core repository is compiled with --with-env-editor
by default and honors the use of the VISUAL and EDITOR variables. To establish nano as the visudo
editor for the duration of the current shell session, set and export the EDITOR variable before calling visudo
export EDITOR=nano
Example Usage
export EDITOR=nano && sudo visudo
Method Two
The EDITOR variable can also be set within the following files for persistent use:
- ~/.bash_profile (login shell)
- ~/.bashrc (interactive, non-login shell)
- /etc/profile (global settings for all system users except root)
Example .bash_profile
. $HOME/.bashrc export EDITOR=nano export GREP_COLOR="1;33" if [[ -z "$DISPLAY" ]] && [[ $(tty) = /dev/vc/1 ]]; then startx logout fi
Method Three
Symbolic Linking
As root, or with su -
mv /usr/bin/vi /usr/bin/vi.old ln -s /usr/bin/nano /usr/bin/vi
Assuming sudo is installed and properly configured
sudo mv /usr/bin/vi /usr/bin/vi.old sudo ln -s /usr/bin/nano /usr/bin/vi
Overview of Commands
mv /usr/bin/vi /usr/bin/vi.old
- Rename the vi executable to vi.old for ease of restoration
ln -s /usr/bin/nano /usr/bin/vi
- Create a symbolic link from /usr/bin/nano to /usr/bin/vi
Restoration of vi
unlink /usr/bin/vi
- Remove the /usr/bin/vi symbolic link
mv /usr/bin/vi.old /usr/bin/vi
- Rename the vi.old executable back to vi
Method Four
Removal & Symbolic Linking
pacman -Rns vi ln -s /usr/bin/nano /usr/bin/vi
Overview of Commands
pacman -Rns vi
- Use pacman to remove the vi package, its configuration, and all unneeded dependencies
ln -s /usr/bin/nano /usr/bin/vi
- Create a symbolic link from /usr/bin/nano to /usr/bin/vi
Restoration of vi
unlink /usr/bin/vi
- Remove the /usr/bin/vi symbolic link
pacman -S vi
- Use pacman to install the previously deinstallled vi package
Package Removal
To remove the nano package while retaining its configuration files and dependencies:
# pacman -R nano
To remove the nano package and its configuration files while retaining its dependencies:
# pacman -Rn nano
To remove the nano package and dependencies not required by any other packages while retaining its configuration files:
# pacman -Rs nano
To remove the nano package, its configuration files and dependencies not required by any other packages:
# pacman -Rns nano
Additional Resources
- nano (text editor) - Wikipedia Entry
- GNU nano Homepage - Official Site
- GNU nano Bugs Bug Reporting