Difference between revisions of "Nano"
m (Added "add to pacman IgnorePkg" part.) |
Kynikos.bot (talk | contribs) (wikify some external links, use https for archlinux.org) |
||
Line 24: | Line 24: | ||
==== Nano syntax highlight for PKGBUILD ==== | ==== Nano syntax highlight for PKGBUILD ==== | ||
− | This new version highlights like the ArchLinux [ | + | This new version highlights like the ArchLinux [https://projects.archlinux.org/svntogit/packages.git/tree "svntogit-server"]. |
# Arch PKGBUILD files | # Arch PKGBUILD files | ||
# | # | ||
Line 46: | Line 46: | ||
color brightblack "#.*$" | color brightblack "#.*$" | ||
− | This is another version from this [ | + | This is another version from this [https://bbs.archlinux.org/viewtopic.php?pid=565476 forumthread]. |
## Arch PKGBUILD files | ## Arch PKGBUILD files | ||
Line 215: | Line 215: | ||
== Additional Resources == | == Additional Resources == | ||
− | * [ | + | * [[wikipedia:Nano_(text_editor)|nano (text editor)]] - Wikipedia Entry |
* [http://www.nano-editor.org/ GNU nano Homepage] - Official Site | * [http://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] |
Revision as of 16:09, 4 December 2012
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.
Nano syntax highlight for PKGBUILD
This new version highlights like the ArchLinux "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 forumthread.
## 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 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
-
^G Get Help
(Template:Keypress)
- Displays the online help files within the session window. A suggested read for nano users of all levels
-
^O WriteOut
(Template:Keypress)
- Save the contents of the current file buffer to a file on the disk
-
^R Read File
(Template:Keypress)
- Inserts another file into the current one at the cursor location
-
^Y Prev Page
(Template:Keypress)
- Display the previous buffered screen
-
^K Cut Text
(Template:Keypress)
- Cut and store the current line from the beginning of the line to the end of the line
-
^C Cur Pos
(Template:Keypress)
- Display line, column and character position information at the current location of the cursor
-
^X Exit
(Template:Keypress)
- Close and exit nano
-
^J Justify
(Template:Keypress)
- Aligns text according to the geometry of the console window
-
^W Where
(Template:Keypress)
- Perform a case-insensitive string, or regular expression search
-
^V Next Page
(Template:Keypress)
- Display the next buffered screen
-
^U UnCut Text
(Template:Keypress)
- Paste the contents of the cut buffer to the current cursor location
-
^T To Spell
(Template:Keypress)
- Spellcheck the contents of the buffer with the built-in
spell
, if available
Selected Toggle Functions
-
Meta+c
(or Template:Keypress)
- Toggles support for line, column and character position information.
-
Meta+i
(or Template:Keypress)
- Toggles support for the auto indentation of lines
-
Meta+k
(or Template:Keypress)
- Toggles support for cutting text from the current cursor position to the end of the line
-
Meta+m
(or Template:Keypress)
- Toggles mouse support for cursor placement, marking and shortcut execution
-
Meta+x
(or Template:Keypress)
- 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
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
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
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
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
Additional Resources
- nano (text editor) - Wikipedia Entry
- GNU nano Homepage - Official Site
- GNU nano Bugs Bug Reporting
- Better syntax highlighting definitions