Difference between revisions of "Nano"

From ArchWiki
Jump to: navigation, search
(use Template:Note directly)
m (Configuration: style)
 
(60 intermediate revisions by 12 users not shown)
Line 1: Line 1:
 +
{{Lowercase title}}
 
[[Category:Text editors]]
 
[[Category:Text editors]]
 
[[de:Nano]]
 
[[de:Nano]]
 +
[[es:Nano]]
 
[[it:Nano]]
 
[[it:Nano]]
 +
[[ru:Nano]]
 
[[ja:Nano]]
 
[[ja:Nano]]
{{Lowercase title}}
+
[https://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'' 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://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].
+
== Installation ==
  
== Package installation ==
+
''nano'' is available in the {{Pkg|nano}} package. It is likely that is already on your system, as it is included in the {{grp|base}} group.
{{Pkg|nano}} is part of the [[Official Repositories|Arch Linux [core] repository]], usually installed by default by AIF.
+
  
 
== Configuration ==
 
== 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 {{Ic|~/.nanorc}}.<br>
 
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:
 
  
$ cd ~
+
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}}.
$ touch .nanorc
+
or
+
$ cp /etc/nanorc ~/.nanorc
+
  
Proceed to establish the nano console environment by setting and/or unsetting commands within {{Ic|.nanorc}} file.
+
A sample configuration file is installed upon program installation and is located at {{ic|/etc/nanorc}}. To customize your nano configuration, first create a local copy at {{ic|~/.nanorc}}:
{{Tip|[http://www.nano-editor.org/dist/v2.2/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|}}
+
  
=== Syntax highlighting ===
+
$ cp /etc/nanorc ~/.nanorc
==== for PKGBUILD files ====
+
This new version highlights like the Arch Linux [https://projects.archlinux.org/svntogit/packages.git/tree "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 "<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].
+
Proceed to establish the nano console environment by setting and/or unsetting commands within {{ic|~/.nanorc}} file.
  
## Arch PKGBUILD files
+
{{Tip|{{man|5|nanorc|url=https://www.nano-editor.org/dist/latest/nanorc.5.html}} details the complete list configuration commands available for nano.|}}
##
+
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:
+
{{Note|Command-line arguments override and take precedence over the configuration commands established in {{ic|~/.nanorc}}}}
include "/usr/share/nano/pkgbuild.nanorc"
+
to your {{Ic|~/.nanorc}} or to {{Ic|/etc/nanorc}}.
+
  
==== Other definitions ====
+
=== Syntax highlighting ===
Syntax highlighting enhancements which replace and expand the defaults can be found in the AUR, {{AUR|nano-syntax-highlighting-git}}.
+
  
=== Suggested configuration ===
+
Nano ships with predefined [[wikipedia:Syntax highlighting|syntax highlighting]] rules, defined in {{ic|/usr/share/nano/*.nanorc}}. To enable them, add the following line to your {{ic|~/.nanorc}} or to {{ic|/etc/nanorc}}:
==== 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 {{ic|Ctrl+z}} to send nano to the background.
+
  
==== Do not wrap text ====
+
include "/usr/share/nano/*.nanorc"
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.
+
Syntax highlighting enhancements which replace and expand the defaults can be found in the AUR, {{AUR|nano-syntax-highlighting-git}}. See [https://paste.xinu.at/wc17YG/] for [[w:Forth (programming language)|Forth]] highlighting.
set nowrap
+
  
== nano usage ==
+
==== PKGBUILD ====
=== Special functions ===
+
* {{ic|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 {{ic|Alt}}) and/or {{ic|Esc}} key modified sequences.
+
  
==== Shortcut lists overview ====
+
* Save https://paste.xinu.at/4ss/ (similar to [https://projects.archlinux.org/svntogit/packages.git/tree svntogit-server]) to {{ic|/etc/nano/pkgbuild.nanorc}} and include it:
* {{Ic|^G Get Help}} ({{ic|F1}})
+
: Displays the online help files within the session window. A suggested read for nano users of all levels
+
* {{Ic|^O WriteOut}} ({{ic|F3}})
+
: Save the contents of the current file buffer to a file on the disk
+
* {{Ic|^R Read File}} ({{ic|F5}})
+
: Inserts another file into the current one at the cursor location
+
* {{Ic|^Y Prev Page}} ({{ic|F7}})
+
: Display the previous buffered screen
+
* {{Ic|^K Cut Text}} ({{ic|F9}})
+
: Cut and store the current line from the beginning of the line to the end of the line
+
* {{Ic|^C Cur Pos}} ({{ic|F11}})
+
: Display line, column and character position information at the current location of the cursor
+
* {{Ic|^X Exit}} ({{ic|F2}})
+
: Close and exit nano
+
* {{Ic|^J Justify}} ({{ic|F4}})
+
: Aligns text according to the geometry of the console window
+
* {{Ic|^W Where}} ({{ic|F6}})
+
: Perform a case-insensitive string, or regular expression search
+
* {{Ic|^V Next Page}} ({{ic|F8}})
+
: Display the next buffered screen
+
* {{Ic|^U UnCut Text}} ({{ic|F10}})
+
: Paste the contents of the cut buffer to the current cursor location
+
* {{Ic|^T To Spell}} ({{ic|F12}})
+
: Spellcheck the contents of the buffer with the built-in {{Ic|spell}}, if available
+
  
{{Tip|See the nano online help files via {{ic|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.|}}
+
include "/etc/nano/pkgbuild.nanorc"
  
==== Selected toggle functions ====
+
* {{AUR|nano-syntax-highlighting-git}} has an alternate version
* {{Ic|Meta+c}} (or {{ic|Esc+c}})
+
: Toggles support for line, column and character position information.
+
  
* {{Ic|Meta+i}} (or {{ic|Esc+i}})
+
=== Suspension ===
: Toggles support for the auto indentation of lines
+
  
* {{Ic|Meta+k}} (or {{ic|Esc+k}})
+
Unlike most interactive programs, suspension is not enabled by default. To change this, uncomment the {{ic|set suspend}} line in {{Ic|/etc/nanorc}}. This will allow you to use the keys {{ic|Ctrl+z}} to send nano to the background.
: Toggles support for cutting text from the current cursor position to the end of the line
+
  
* {{Ic|Meta+m}} (or {{ic|Esc+m}})
+
=== Text wrapping ===
: Toggles mouse support for cursor placement, marking and shortcut execution
+
  
* {{Ic|Meta+x}} (or {{ic|Esc+x}})
+
Unlike many text editors, ''nano'' wraps text. To disable this put this in your {{ic|~/.nanorc}}
: 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.|}}
+
set nowrap
  
== Tips & tricks ==
+
== Usage ==
=== 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'''.
+
  
==== Method one ====
+
Shortcuts can be viewed from inside ''nano''. See the nano online help files via {{ic|Ctrl+g}} within nano and the [https://www.nano-editor.org/dist/latest/nano.html nano Command Manual] for complete descriptions and additional support.
{{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.''}}
+
  
[[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'''.
+
=== Special functions ===
  
export EDITOR=nano  
+
Keyboard shortcuts representing commonly used functions are listed along the bottom two lines of the nano screen.
  
===== Example usage =====
+
They can be toggled by:
  export EDITOR=nano && sudo visudo
+
  
==== Method two ====
+
* {{ic|Ctrl}} for {{ic|^}} based shortcuts
{{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.''}}
+
* ''{{ic|Meta}}'' (typically {{ic|Alt}}) or {{ic|Esc}} for {{ic|M-}} based shortcuts
  
The EDITOR variable can also be set within the following files for persistent use:
+
{{Tip|[https://www.nano-editor.org/dist/latest/nano.html#Feature-Toggles Feature Toggles] lists the global toggles available for nano.|}}
  
* <S>~/[http://www.gnu.org/software/bash/manual/bashref.html#Bash-Startup-Files .bash_profile] (login shell)</S>
+
== Tips and tricks ==
* ~/.profile (instead of `.bash_profile` ; see [https://wiki.archlinux.org/index.php/Environment_Variables#Defining_Variables_Locally Environment Variables]
+
* ~/.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 {{Ic|root}})
+
  
===== Example .bash_profile =====
+
=== Replacing vi with nano ===
{{Bc|. $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 {{Ic|su -}}
+
 
+
Rename the {{Ic|vi}} executable to {{Ic|vi.old}} for ease of restoration:
+
# mv /usr/bin/vi /usr/bin/vi.old
+
 
+
Create a symbolic link from {{Ic|/usr/bin/nano}} to {{Ic|/usr/bin/vi}}
+
# ln -s /usr/bin/nano /usr/bin/vi
+
 
+
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 permanent.  Otherwise it will revert back to {{Ic|vi}} the next time it is updated.
+
 
+
===== Restoration of vi =====
+
Remove the {{Ic|/usr/bin/vi}} symbolic link:
+
unlink /usr/bin/vi
+
 
+
Rename the {{Ic|vi.old}} executable back to {{Ic|vi}}:
+
mv /usr/bin/vi.old /usr/bin/vi
+
  
==== Method four ====
+
To replace vi with nano as the default text editor for commands such as [[sudo#Using visudo|visudo]], set the {{ic|VISUAL}} and {{ic|EDITOR}} [[Environment_variable#Defining_variables|environment variables]], for example:
{{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 =====
+
export VISUAL=nano
Use [[Pacman|pacman]] to remove the {{Ic|vi}} package, its configuration, and all unneeded dependencies:
+
  export EDITOR=nano
  pacman -Rns vi
+
  
Create a symbolic link from {{Ic|/usr/bin/nano}} to {{Ic|/usr/bin/vi}}:
+
== Troubleshooting ==
ln -s /usr/bin/nano /usr/bin/vi
+
  
===== Restoration of vi =====
+
=== Hijacked keybindings ===
Remove the {{Ic|/usr/bin/vi}} symbolic link:
+
unlink /usr/bin/vi
+
  
Use pacman to install the previously deinstallled {{Ic|vi}} package:
+
Some window managers have keybindings that conflict with nano, for example {{ic|Alt+Enter}}. Remove or remap them to e.g {{ic|Super}} (with {{Pkg|dconf}} for {{Pkg|mutter}}, {{Pkg|muffin}} and {{Pkg|marco}}) and restart the window manager.
pacman -S vi
+
  
{{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}}).|}}
+
== See also ==
  
== Additional resources ==
 
 
* [[wikipedia:Nano_(text_editor)|nano (text editor)]] - Wikipedia Entry
 
* [[wikipedia:Nano_(text_editor)|nano (text editor)]] - Wikipedia Entry
* [http://www.nano-editor.org/ GNU nano Homepage] - Official Site
+
* [https://www.nano-editor.org/ GNU nano Homepage] - Official Site
 
* [https://savannah.gnu.org/bugs/?group=nano GNU nano Bugs] Bug Reporting
 
* [https://savannah.gnu.org/bugs/?group=nano GNU nano Bugs] Bug Reporting
 
* [https://github.com/craigbarnes/nanorc Better syntax highlighting definitions]
 
* [https://github.com/craigbarnes/nanorc Better syntax highlighting definitions]

Latest revision as of 14:18, 23 November 2016

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

Installation

nano is available in the nano package. It is likely that is already on your system, as it is included in the base group.

Configuration

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. To customize your nano configuration, first create a local copy at ~/.nanorc:

$ cp /etc/nanorc ~/.nanorc

Proceed to establish the nano console environment by setting and/or unsetting commands within ~/.nanorc file.

Tip: nanorc(5) 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

Nano ships with predefined syntax highlighting rules, defined in /usr/share/nano/*.nanorc. To enable them, add the following line to your ~/.nanorc or to /etc/nanorc:

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

Syntax highlighting enhancements which replace and expand the defaults can be found in the AUR, nano-syntax-highlighting-gitAUR. See [1] for Forth highlighting.

PKGBUILD

include "/etc/nano/pkgbuild.nanorc"

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.

Text wrapping

Unlike many text editors, nano wraps text. To disable this put this in your ~/.nanorc

set nowrap

Usage

Shortcuts can be viewed from inside nano. See the nano online help files via Ctrl+g within nano and the nano Command Manual for complete descriptions and additional support.

Special functions

Keyboard shortcuts representing commonly used functions are listed along the bottom two lines of the nano screen.

They can be toggled by:

  • Ctrl for ^ based shortcuts
  • Meta (typically Alt) or Esc for M- based shortcuts
Tip: Feature Toggles lists the global toggles available for nano.

Tips and tricks

Replacing vi with nano

To replace vi with nano as the default text editor for commands such as visudo, set the VISUAL and EDITOR environment variables, for example:

export VISUAL=nano
export EDITOR=nano

Troubleshooting

Hijacked keybindings

Some window managers have keybindings that conflict with nano, for example Alt+Enter. Remove or remap them to e.g Super (with dconf for mutter, muffin and marco) and restart the window manager.

See also