Difference between revisions of "Nano"

From ArchWiki
Jump to: navigation, search
(Introduction)
(Other syntax highlighting definitions, minor fixes)
(41 intermediate revisions by 21 users not shown)
Line 1: Line 1:
= Introduction =
+
[[Category:Text editors]]
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 [http://www.ubuntu.com/ Ubuntu] and supports features including colorized syntax highlighting, DOS/Mac file type conversions, spellchecking and [http://en.wikipedia.org/wiki/UTF-8 UTF-8] encoding. [http://i275.photobucket.com/albums/jj281/adamchrista/Arch%20Linux/Wiki%20Examples/nano-man.png nano Screenshot].
+
[[de:Nano]]
 +
[[it:Nano]]
 +
{{Lowercase title}}
  
= Package Installation =
+
[http://www.nano-editor.org/ 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 [[Wikipedia:UTF-8|UTF-8]] encoding. nano opened with an empty buffer typically occupies under 1.5 MB of resident memory. [http://i275.photobucket.com/albums/jj281/adamchrista/Arch%20Linux/Wiki%20Examples/nano-man.png nano Screenshot].
nano is part of the [[Official Repositories|official Arch Linux (core) repositories]].
+
  
$ pacman -Si nano
+
== Package installation ==
 +
{{Pkg|nano}} is part of the [[Official Repositories|Arch Linux [core] repository]], usually installed by default by AIF.
  
<pre>Repository    : core
+
== Configuration ==
Name          : nano
+
=== Creating ~/.nanorc ===
Version        : 2.0.9-1
+
The look, feel and function of nano is typically controlled by way of either command-line arguments, or configuration commands within the file {{Ic|~/.nanorc}}.<br>
URL            : http://www.nano-editor.org
+
A sample configuration file is installed upon program installation and is located at {{Ic|/etc/nanorc}}.The file {{Ic|~/.nanorc}} must be first created by the user:
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</pre>
+
 
+
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 <tt>~/.nanorc</tt>.<br>
+
A sample configuration file is installed upon program installation and is located at <tt>/etc/nanorc</tt>.The file <tt>~/.nanorc</tt> must be first created by the user:
+
  
 
  $ cd ~
 
  $ cd ~
Line 39: Line 19:
 
  $ cp /etc/nanorc ~/.nanorc
 
  $ cp /etc/nanorc ~/.nanorc
  
Proceed to establish the nano console environment by setting and/or unsetting commands within <tt>.nanorc</tt> file.
+
Proceed to establish the nano console environment by setting and/or unsetting commands within {{Ic|.nanorc}} file.
 
{{Tip|[http://www.nano-editor.org/dist/v2.1/nanorc.5.html NANORC] details the complete list configuration commands available for nano.|}}
 
{{Tip|[http://www.nano-editor.org/dist/v2.1/nanorc.5.html 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|}}
 
{{Note|Command-line arguments override and take precedence over the configuration commands established in .nanorc|}}
  
= nano Usage =
+
=== Syntax highlighting ===
== Special Functions ==
+
==== for PKGBUILD files ====
* <tt>Ctrl</tt> key modified shortcuts <tt>(^)</tt> respresenting commonly used functions are listed along the bottom two lines of the nano screen.
+
This new version highlights like the Arch Linux [https://projects.archlinux.org/svntogit/packages.git/tree "svntogit-server"].
* Additional functions can be interactively toggled by way of <tt>Meta</tt> (typically <tt>Alt</tt>) and/or <tt>Esc</tt> key modified sequences.  
+
# Arch PKGBUILD files
 +
#
 +
syntax "pkgbuild" "^.*PKGBUILD*"
 +
# commands
 +
color red "\<(cd|echo|enable|exec|export|kill|popd|pushd|read|source|touch|type)\>"
 +
color brightblack "\<(case|cat|chmod|chown|cp|diff|do|done|elif|else|esac|exit|fi|find|for|ftp|function|grep|gzip|if|in)\>"
 +
color brightblack "\<(install|ln|local|make|mv|patch|return|rm|sed|select|shift|sleep|tar|then|time|until|while|yes)\>"
 +
# ${*}
 +
icolor blue "\$\{?[0-9A-Z_!@#$*?-]+\}?"
 +
# numerics
 +
color blue "\ [0-9]*"
 +
color blue "\.[0-9]*"
 +
color blue "\-[0-9]*"
 +
color blue "=[0-9]"
 +
# spaces
 +
color ,green "<nowiki>[[:space:]]</nowiki>+$"
 +
# strings; multilines are not supported
 +
color brightred ""(\\.|[^"])*"" "'(\\.|[^'])*'"
 +
# comments
 +
color brightblack "#.*$"
 +
 
 +
This is another version from this [https://bbs.archlinux.org/viewtopic.php?pid=565476 forum thread].
  
=== Shortcut Lists Overview ===
+
## Arch PKGBUILD files
* <tt>^G Get Help</tt> (<tt>F1</tt>)
+
##
 +
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 {{Ic|~/.nanorc}} or to {{Ic|/etc/nanorc}}.
 +
 
 +
==== Other definitions ====
 +
Syntax highlighting enhancements which replace and expand the defaults can be found in the AUR, {{AUR|nano-syntax-highlighting-git}}.
 +
 
 +
=== Suggested configuration ===
 +
==== Suspension ====
 +
Unlike most interactive programs, suspension is not enabled by default. To change this, uncomment the 'set suspend' line in {{Ic|/etc/nanorc}}. This will allow you to use the keys {{Keypress|Ctrl+z}} to send nano to the background.
 +
 
 +
==== Do not wrap text ====
 +
If you are coming from another distribution, you might wonder about nano's strange behaviour, so just edit /etc/nanorc like this:
 +
 
 +
## Do not wrap text at all.
 +
set nowrap
 +
 
 +
== nano usage ==
 +
=== Special functions ===
 +
* {{Keypress|Ctrl}} key modified shortcuts ({{Ic|^}}) representing commonly used functions are listed along the bottom two lines of the nano screen.
 +
* Additional functions can be interactively toggled by way of {{Ic|Meta}} (typically {{Keypress|Alt}}) and/or {{Keypress|Esc}} key modified sequences.
 +
 
 +
==== Shortcut lists overview ====
 +
* {{Ic|^G Get Help}} ({{Keypress|F1}})
 
: Displays the online help files within the session window. A suggested read for nano users of all levels
 
: Displays the online help files within the session window. A suggested read for nano users of all levels
* <tt>^O WriteOut</tt> (<tt>F3</tt>)
+
* {{Ic|^O WriteOut}} ({{Keypress|F3}})
 
: Save the contents of the current file buffer to a file on the disk
 
: Save the contents of the current file buffer to a file on the disk
* <tt>^R Read File</tt> (<tt>F5</tt>)
+
* {{Ic|^R Read File}} ({{Keypress|F5}})
 
: Inserts another file into the current one at the cursor location
 
: Inserts another file into the current one at the cursor location
* <tt>^Y Prev Page</tt> (<tt>F7</tt>)
+
* {{Ic|^Y Prev Page}} ({{Keypress|F7}})
 
: Display the previous buffered screen
 
: Display the previous buffered screen
* <tt>^K Cut Text</tt> (<tt>F9</tt>)
+
* {{Ic|^K Cut Text}} ({{Keypress|F9}})
 
: Cut and store the current line from the beginning of the line to the end of the line  
 
: Cut and store the current line from the beginning of the line to the end of the line  
* <tt>^C Cur Pos</tt> (<tt>F11</tt>)
+
* {{Ic|^C Cur Pos}} ({{Keypress|F11}})
 
: Display line, column and character position information at the current location of the cursor  
 
: Display line, column and character position information at the current location of the cursor  
* <tt>^X Exit</tt> (<tt>F2</tt>)
+
* {{Ic|^X Exit}} ({{Keypress|F2}})
 
: Close and exit nano  
 
: Close and exit nano  
* <tt>^J Justify</tt> (<tt>F4</tt>)
+
* {{Ic|^J Justify}} ({{Keypress|F4}})
 
: Aligns text according to the geometry of the console window
 
: Aligns text according to the geometry of the console window
* <tt>^W Where</tt> (<tt>F6</tt>)
+
* {{Ic|^W Where}} ({{Keypress|F6}})
 
: Perform a case-insensitive string, or regular expression search
 
: Perform a case-insensitive string, or regular expression search
* <tt>^V Next Page</tt> (<tt>F8</tt>)
+
* {{Ic|^V Next Page}} ({{Keypress|F8}})
 
: Display the next buffered screen
 
: Display the next buffered screen
* <tt>^U UnCut Text</tt> (<tt>F10</tt>)
+
* {{Ic|^U UnCut Text}} ({{Keypress|F10}})
 
: Paste the contents of the cut buffer to the current cursor location
 
: Paste the contents of the cut buffer to the current cursor location
* <tt>^T To Spell</tt> (<tt>F12</tt>)
+
* {{Ic|^T To Spell}} ({{Keypress|F12}})
: Spellcheck the contents of the buffer with the built-in <tt>spell</tt>, if available
+
: Spellcheck the contents of the buffer with the built-in {{Ic|spell}}, if available
  
{{Tip|See the nano online help files via <code>Ctrl+g</code> within nano and the [http://www.nano-editor.org/dist/v2.1/nano.html nano Command Manual] for complete descriptions and additional support.|}}
+
{{Tip|See the nano online help files via {{Keypress|Ctrl+g}} within nano and the [http://www.nano-editor.org/dist/v2.1/nano.html nano Command Manual] for complete descriptions and additional support.|}}
  
=== Selected Toggle Functions ===
+
==== Selected toggle functions ====
* <tt>Meta+c</tt> (or <tt>Esc+c</tt>)
+
* {{Ic|Meta+c}} (or {{Keypress|Esc+c}})
 
: Toggles support for line, column and character position information.
 
: Toggles support for line, column and character position information.
  
* <tt>Meta+i</tt> (or <tt>Esc+i</tt>)
+
* {{Ic|Meta+i}} (or {{Keypress|Esc+i}})
 
: Toggles support for the auto indentation of lines
 
: Toggles support for the auto indentation of lines
  
* <tt>Meta+k</tt> (or <tt>Esc+k</tt>)
+
* {{Ic|Meta+k}} (or {{Keypress|Esc+k}})
 
: Toggles support for cutting text from the current cursor position to the end of the line
 
: Toggles support for cutting text from the current cursor position to the end of the line
  
* <tt>Meta+m</tt> (or <tt>Esc+m</tt>)
+
* {{Ic|Meta+m}} (or {{Keypress|Esc+m}})
 
: Toggles mouse support for cursor placement, marking and shortcut execution
 
: Toggles mouse support for cursor placement, marking and shortcut execution
  
* <tt>Meta+x</tt> (or <tt>Esc+x</tt>)
+
* {{Ic|Meta+x}} (or {{Keypress|Esc+x}})
 
: Toggles the display of the shortcut list at the bottom of the nano screen for additional screen space  
 
: Toggles the display of the shortcut list at the bottom of the nano screen for additional screen space  
  
 
{{Tip|[http://www.nano-editor.org/dist/v2.1/nano.html#Feature-Toggles Feature Toggles] lists the global toggles available for nano.|}}
 
{{Tip|[http://www.nano-editor.org/dist/v2.1/nano.html#Feature-Toggles Feature Toggles] lists the global toggles available for nano.|}}
  
= Tips & Tricks =
+
== Tips & tricks ==
 +
=== Replacing vi with nano ===
 +
Casual users may prefer the use of {{Ic|nano}} over {{Ic|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'''.
  
== Replacing <tt>vi</tt> with <tt>nano</tt> ==
+
==== Method one ====
 +
{{Warning|From {{Ic|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.''}}
  
Casual users may prefer the use of <tt>nano</tt> over <tt>vi</tt> for its simplicity and ease of use and may opt to replace vi with nano as the default text editor for commands such as <code>visudo</code>.
+
[[Sudo|sudo]] from the core repository is compiled with {{Ic|--with-env-editor}} by default and honors the use of the {{Ic|VISUAL}} and {{Ic|EDITOR}} variables. To establish nano as the '''visudo''' editor for the duration of the current shell session, set and export the {{Ic|EDITOR}} variable before calling '''visudo'''.
 
+
=== 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. Set and export the <tt>EDITOR</tt> variable within the current shell session before calling <code>visudo</tt> to temporarily establish nano as the <code>visudo</code> editor:
+
  
 
  export EDITOR=nano  
 
  export EDITOR=nano  
  
{{Warning|From <tt>man 8 visudo</tt>: ''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.''}}
+
===== Example usage =====
 +
  export EDITOR=nano && sudo visudo
  
==== Example Usage ====
+
==== Method two ====
 +
{{Warning|From {{Ic|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.''}}
  
  export EDITOR=nano && sudo visudo
 
 
=== Method Two ===
 
 
The EDITOR variable can also be set within the following files for persistent use:
 
The EDITOR variable can also be set within the following files for persistent use:
  
 
* ~/[http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files .bash_profile] (login shell)
 
* ~/[http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files .bash_profile] (login shell)
 
* ~/.bashrc (interactive, non-login shell)
 
* ~/.bashrc (interactive, non-login shell)
* [http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files /etc/profile] (global settings for all system users except <tt>root</tt>)
+
* [http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files /etc/profile] (global settings for all system users except {{Ic|root}})
 
+
{{Warning|From <tt>man 8 visudo</tt>: ''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.''}}
+
 
+
==== Example .bash_profile ====
+
  
<pre>. $HOME/.bashrc
+
===== Example .bash_profile =====
 +
{{Bc|. $HOME/.bashrc|
  
 
export EDITOR=nano
 
export EDITOR=nano
Line 130: Line 173:
 
   startx
 
   startx
 
   logout
 
   logout
fi</pre>
+
fi
 +
}}
  
=== Method Three ===
+
==== 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.}}
 
{{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 ====
+
===== Symbolic linking =====
As root, or with <code>su -</code>
+
As root, or with {{Ic|su -}}
  
mv /usr/bin/vi /usr/bin/vi.old
+
Rename the {{Ic|vi}} executable to {{Ic|vi.old}} for ease of restoration:
  ln -s /usr/bin/nano /usr/bin/vi
+
  # mv /usr/bin/vi /usr/bin/vi.old
  
Assuming sudo is installed and properly configured
+
Create a symbolic link from {{Ic|/usr/bin/nano}} to {{Ic|/usr/bin/vi}}
 +
# ln -s /usr/bin/nano /usr/bin/vi
  
sudo mv /usr/bin/vi /usr/bin/vi.old
+
Assuming sudo is installed and properly configured. You will need to add {{Ic|vi}} to the {{ic|IgnorePkg}} list in {{ic|pacman.conf}} to make this permanentOtherwise it will revert back to {{Ic|vi}} the next time it is updated.
  sudo ln -s /usr/bin/nano /usr/bin/vi
+
  
==== Overview of Commands ====
+
===== Restoration of vi =====
mv /usr/bin/vi /usr/bin/vi.old
+
Remove the {{Ic|/usr/bin/vi}} symbolic link:
* Rename the <tt>vi</tt> executable to <tt>vi.old</tt> for ease of restoration
+
unlink /usr/bin/vi
ln -s /usr/bin/nano /usr/bin/vi
+
* Create a symbolic link from <tt>/usr/bin/nano</tt> to <tt>/usr/bin/vi</tt>
+
  
==== Restoration of <tt>vi</tt> ====
+
Rename the {{Ic|vi.old}} executable back to {{Ic|vi}}:
unlink /usr/bin/vi
+
* Remove the <tt>/usr/bin/vi</tt> symbolic link
+
 
  mv /usr/bin/vi.old /usr/bin/vi
 
  mv /usr/bin/vi.old /usr/bin/vi
* Rename the <tt>vi.old</tt> executable back to <tt>vi</tt>
 
  
=== Method Four ===
+
==== 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.}}
 
{{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 ====
+
===== Removal & symbolic linking =====
 +
Use [[Pacman|pacman]] to remove the {{Ic|vi}} package, its configuration, and all unneeded dependencies:
 
  pacman -Rns vi
 
  pacman -Rns vi
ln -s /usr/bin/nano /usr/bin/vi
 
  
==== Overview of Commands ====
+
Create a symbolic link from {{Ic|/usr/bin/nano}} to {{Ic|/usr/bin/vi}}:
pacman -Rns vi
+
* Use [[Pacman|pacman]] to remove the <tt>vi</tt> package, its configuration, and all unneeded dependencies
+
 
  ln -s /usr/bin/nano /usr/bin/vi
 
  ln -s /usr/bin/nano /usr/bin/vi
* Create a symbolic link from <tt>/usr/bin/nano</tt> to <tt>/usr/bin/vi</tt>
 
  
==== Restoration of <tt>vi</tt> ====
+
===== Restoration of vi =====
 +
Remove the {{Ic|/usr/bin/vi}} symbolic link:
 
  unlink /usr/bin/vi
 
  unlink /usr/bin/vi
* Remove the <tt>/usr/bin/vi</tt> symbolic link
 
pacman -S vi
 
* Use pacman to install the previously deinstallled <tt>vi</tt> package
 
 
{{Box Note|Do not clean <tt>-c</tt> or refresh <tt>-y</tt> the package database if you wish to retain the previously installed version of the <tt>vi</tt> package.<br>If this case, subsequent updates will also require the judicious use of the <tt>--ignore vi</tt> switch (and optionally <tt>--ignore glibc ncurses coreutils</tt>).|}}
 
 
= 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
 
  
{{Box Note|Pacman will not remove configuration files outside of the defaults that were created during package installation. This includes <tt>~/.nanorc</tt>|}}
+
Use pacman to install the previously deinstallled {{Ic|vi}} package:
 +
pacman -S vi
  
= Additional Resources =
+
{{Box Note|Do not clean {{Ic|-c}} or refresh {{Ic|-y}} the package database if you wish to retain the previously installed version of the {{Ic|vi}} package.<br>If this case, subsequent updates will also require the judicious use of the {{Ic|--ignore vi}} switch (and optionally {{Ic|--ignore glibc ncurses coreutils}}).|}}
  
* [http://en.wikipedia.org/wiki/Nano_(text_editor) nano (text editor)] - Wikipedia Entry
+
== Additional resources ==
* [http://www.nano-editor.org/ GNU Nano Homepage] - Official Site
+
* [[wikipedia:Nano_(text_editor)|nano (text editor)]] - Wikipedia Entry
 +
* [http://www.nano-editor.org/ GNU nano Homepage] - Official Site
 +
* [https://savannah.gnu.org/bugs/?group=nano GNU nano Bugs] Bug Reporting
 +
* [https://github.com/craigbarnes/nanorc Better syntax highlighting definitions]

Revision as of 04:41, 16 March 2013

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

nano is part of the Arch Linux [core] repository, usually installed by default by AIF.

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

Syntax highlighting

for PKGBUILD files

This new version highlights like the Arch Linux "svntogit-server".

# Arch PKGBUILD files
#
syntax "pkgbuild" "^.*PKGBUILD*"
# commands
color red "\<(cd|echo|enable|exec|export|kill|popd|pushd|read|source|touch|type)\>"
color brightblack "\<(case|cat|chmod|chown|cp|diff|do|done|elif|else|esac|exit|fi|find|for|ftp|function|grep|gzip|if|in)\>"
color brightblack "\<(install|ln|local|make|mv|patch|return|rm|sed|select|shift|sleep|tar|then|time|until|while|yes)\>"
# ${*}
icolor blue "\$\{?[0-9A-Z_!@#$*?-]+\}?"
# numerics
color blue "\ [0-9]*"
color blue "\.[0-9]*"
color blue "\-[0-9]*"
color blue "=[0-9]"
# spaces
color ,green "[[:space:]]+$"
# strings; multilines are not supported
color brightred ""(\\.|[^"])*"" "'(\\.|[^'])*'"
# comments
color brightblack "#.*$"

This is another version from this forum thread.

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

Other definitions

Syntax highlighting enhancements which replace and expand the defaults can be found in the AUR, nano-syntax-highlighting-gitAUR.

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 Template:Keypress to send nano to the background.

Do not wrap text

If you are coming from another distribution, you might wonder about nano's strange behaviour, so just edit /etc/nanorc like this:

## Do not wrap text at all.
set nowrap

nano usage

Special functions

  • Template:Keypress key modified shortcuts (^) representing 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 Template:Keypress) and/or Template:Keypress key modified sequences.

Shortcut lists overview

Displays the online help files within the session window. A suggested read for nano users of all levels
Save the contents of the current file buffer to a file on the disk
Inserts another file into the current one at the cursor location
Display the previous buffered screen
Cut and store the current line from the beginning of the line to the end of the line
Display line, column and character position information at the current location of the cursor
Close and exit nano
Aligns text according to the geometry of the console window
Perform a case-insensitive string, or regular expression search
Display the next buffered screen
Paste the contents of the cut buffer to the current cursor location
Spellcheck the contents of the buffer with the built-in spell, if available
Tip: See the nano online help files via Template:Keypress within nano and the nano Command Manual for complete descriptions and additional support.

Selected toggle functions

Toggles support for line, column and character position information.
Toggles support for the auto indentation of lines
Toggles support for cutting text from the current cursor position to the end of the line
Toggles mouse support for cursor placement, marking and shortcut execution
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

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 -

Rename the vi executable to vi.old for ease of restoration:

# mv /usr/bin/vi /usr/bin/vi.old

Create a symbolic link from /usr/bin/nano to /usr/bin/vi

# ln -s /usr/bin/nano /usr/bin/vi

Assuming sudo is installed and properly configured. You will need to add vi to the IgnorePkg list in pacman.conf to make this permanent. Otherwise it will revert back to vi the next time it is updated.

Restoration of vi

Remove the /usr/bin/vi symbolic link:

unlink /usr/bin/vi

Rename the vi.old executable back to vi:

mv /usr/bin/vi.old /usr/bin/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

Use pacman to remove the vi package, its configuration, and all unneeded dependencies:

pacman -Rns vi

Create a symbolic link from /usr/bin/nano to /usr/bin/vi:

ln -s /usr/bin/nano /usr/bin/vi
Restoration of vi

Remove the /usr/bin/vi symbolic link:

unlink /usr/bin/vi

Use pacman to install the previously deinstallled vi package:

pacman -S vi

Template:Box Note

Additional resources