Difference between revisions of "Nano"

From ArchWiki
Jump to: navigation, search
(Configuration: Don't Wrap Text!)
m (Nano syntax highlight for PKGBUILD: /etc/nanorc is also possible for PKDBUILDStyle)
Line 75: Line 75:
 
  include "/usr/share/nano/pkgbuild.nanorc"
 
  include "/usr/share/nano/pkgbuild.nanorc"
 
to your ~/.nanorc
 
to your ~/.nanorc
 +
 +
or to /etc/nanorc
  
 
== Suggested Configuration ==
 
== Suggested Configuration ==

Revision as of 02:02, 7 May 2011

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.


Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어


External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

Introduction

GNU 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 opened with an empty buffer typically occupies under 1.5 MB of resident memory. nano Screenshot.

Package Installation

Template:Package Official is part of the official Arch Linux [core] repository.

$ pacman -Si nano
Repository     : core
Name           : nano
Version        : 2.2.5-1
URL            : http://www.nano-editor.org
Licenses       : GPL
Groups         : base
Provides       : None
Depends On     : glibc  ncurses
Optional Deps  : None
Conflicts With : None
Replaces       : None
Download Size  : 295.66 K
Installed Size : 1508.00 K
Packager       : Andreas Radke <andyrtr@archlinux.org>
Architecture   : x86_64
Build Date     : Mon 09 Aug 2010 10:52:08 AM PDT
MD5 Sum        : 320ff5bf6e073d8f6a7c26ab67e3aef6
Description    : Pico editor clone with enhancements

Install the latest version of nano:

# pacman -S 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.

Tip: NANORC details the complete list configuration commands available for nano.
Note: Command-line arguments override and take precedence over the configuration commands established in .nanorc

Nano syntax highlight for PKGBUILD

This is an updated version of the nanorc found here.

## Arch PKGBUILD files
##
syntax "pkgbuild" "^.*PKGBUILD$"
color green start="^." end="$"
color cyan "^.*(pkgbase|pkgname|pkgver|pkgrel|pkgdesc|arch|url|license).*=.*$"
color brightcyan "\<(pkgbase|pkgname|pkgver|pkgrel|pkgdesc|arch|url|license)\>"
color brightcyan "(\$|\$\{|\$\()(pkgbase|pkgname|pkgver|pkgrel|pkgdesc|arch|url|license)(|\}|\))"
color cyan "^.*(depends|makedepends|optdepends|conflicts|provides|replaces).*=.*$"
color brightcyan "\<(depends|makedepends|optdepends|conflicts|provides|replaces)\>"
color brightcyan "(\$|\$\{|\$\()(depends|makedepends|optdepends|conflicts|provides|replaces)(|\}|\))"
color cyan "^.*(groups|backup|noextract|options).*=.*$"
color brightcyan "\<(groups|backup|noextract|options)\>"
color brightcyan "(\$|\$\{|\$\()(groups|backup|noextract|options)(|\}|\))"
color cyan "^.*(install|source|md5sums|sha1sums|sha256sums|sha384sums|sha512sums).*=.*$"
color brightcyan "\<(install|source|md5sums|sha1sums|sha256sums|sha384sums|sha512sums)\>"
color brightcyan "(\$|\$\{|\$\()(install|source|md5sums|sha1sums|sha256sums|sha384sums|sha512sums)(|\}|\))"
color brightcyan "\<(startdir|srcdir|pkgdir)\>"
color cyan "\.install"
color brightwhite "=" "'" "\(" "\)" "\"" "#.*$" "\," "\{" "\}"
color brightred "build\(\)"
color brightred "package_.*.*$"
color brightred "\<(configure|make|cmake|scons)\>"
color red "\<(DESTDIR|PREFIX|prefix|sysconfdir|datadir|libdir|includedir|mandir|infodir)\>"

To use, save as /usr/share/nano/pkgbuild.nanorc and add:

include "/usr/share/nano/pkgbuild.nanorc"

to your ~/.nanorc

or to /etc/nanorc

Suggested Configuration

Suspension

Unlike most interactive programs, suspension is not enabled by default. To change this, uncomment the 'set suspend' line in '/etc/nanorc'. This will allow you to use the keys ctrl+z to send nano to the background.

Don't wrap text

If you're comming from another distro, you might wonder about nano's strange behaviour, so just edit /etc/nanorc like this:

## Don't wrap text at all.
set nowrap

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
Tip: See the nano online help files via 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
Tip: Feature Toggles lists the global toggles available for nano.

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

Warning: From man 8 visudo: Note that this can be a security hole since it allows the user to execute any program they wish simply by setting VISUAL or EDITOR.

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

Warning: From man 8 visudo: Note that this can be a security hole since it allows the user to execute any program they wish simply by setting VISUAL or EDITOR.

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

Note: This method can be considered draconian and may not be suitable for all users. Nonetheless, the following procedure exists as a viable example solution.

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

Note: This method can be considered draconian and may not be suitable for all users. Nonetheless, the following procedure exists as a viable example solution.

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

Template:Box Note

Additional Resources