Difference between revisions of "Nano"

From ArchWiki
Jump to: navigation, search
(Undo revision 404015 by Vladimir Shatalin (talk) - the package is not required (contains only configurations), already suggested in #Other definitions)
 
(41 intermediate revisions by 11 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]]
{{Lowercase title}}
+
[[ru:Nano]]
 
+
[[ja:Nano]]
[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].
+
[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'' 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.
  
 
== Package installation ==
 
== Package installation ==
{{Pkg|nano}} is part of the [[Official Repositories|Arch Linux [core] repository]], usually installed by default by AIF.
+
 
 +
You can install the {{Pkg|nano}} package from the [[official repositories]]. It is likely that is already on your system, as it is included in the {{grp|base}} group.
  
 
== Configuration ==
 
== Configuration ==
 +
 
=== Creating ~/.nanorc ===
 
=== 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
+
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}}:
 +
 
 
  $ cp /etc/nanorc ~/.nanorc
 
  $ cp /etc/nanorc ~/.nanorc
  
Proceed to establish the nano console environment by setting and/or unsetting commands within {{Ic|.nanorc}} 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.2/nanorc.5.html NANORC] details the complete list configuration commands available for nano.|}}
 
{{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|}}
+
 
 +
{{Note|Command-line arguments override and take precedence over the configuration commands established in {{ic|~/.nanorc}}}}
  
 
=== Syntax highlighting ===
 
=== Syntax highlighting ===
==== for PKGBUILD files ====
+
 
 +
==== PKGBUILD ====
 +
 
 
This new version highlights like the Arch Linux [https://projects.archlinux.org/svntogit/packages.git/tree "svntogit-server"].
 
This new version highlights like the Arch Linux [https://projects.archlinux.org/svntogit/packages.git/tree "svntogit-server"].
 +
 
  # Arch PKGBUILD files
 
  # Arch PKGBUILD files
 
  #
 
  #
Line 73: Line 81:
 
  color red "\<(DESTDIR|PREFIX|prefix|sysconfdir|datadir|libdir|includedir|mandir|infodir)\>"
 
  color red "\<(DESTDIR|PREFIX|prefix|sysconfdir|datadir|libdir|includedir|mandir|infodir)\>"
  
To use, save as /usr/share/nano/pkgbuild.nanorc and add:
+
Save this file as (for example) {{ic|/etc/nano/pkgbuild.nanorc}}.
  include "/usr/share/nano/pkgbuild.nanorc"
+
 
to your {{Ic|~/.nanorc}} or to {{Ic|/etc/nanorc}}.
+
Then include the file in your {{ic|~/.nanorc}} or to {{ic|/etc/nanorc}} by adding the following line:
 +
 
 +
  include "/etc/nano/pkgbuild.nanorc"
 +
 
 +
==== Forth ====
 +
 
 +
{{bc|<nowiki>
 +
## Here is an example for Forth.
 +
##
 +
syntax "forth" "\.(fs|4th|4mu)$"
 +
 +
## Preprocessor statements
 +
color brightred "\[.+\]"
 +
 +
## Numbers
 +
color magenta "-?[0-9]+"
 +
 +
## Floats
 +
color cyan "-?[0-9\.]+e[0-9]+"
 +
 +
## Other Words
 +
 +
color green "\<(2constant|2drop|2dup|2literal|2nip|2over|2rdrop|2rot|2swap|2tuck|2variable|abort|abs|accept|again|ahead|alias|align|aligned|allocate|allot|also|and|arg|argc|argv|asptr|asptr|assembler|base|begin|bin|bind|bind|bl|blank|blk|block|bootmessage|bound|bounds|buffer|bye|case|catch|cell|cells|cfalign|cfaligned|char|chars|class|class|class|clearstack|clearstacks|cmove|code|compare|constant|construct|context|convert|count|cputime|cr|create|current|dabs|dbg|decimal|defer|defer|defers|defines|definitions|definitions|depth|dfalign|dfaligned|dfloats|discode|dispose|dmax|dmin|dnegate|do|done|dpl|drop|dump|dup|early|ekey|else|emit|endcase|endif|endof|endscope|endtry|endwith|erase|evaluate|exception|execute|exit|exitm|expect|fabs|facos|facosh|falign|faligned|falog|false|fasin|fasinh|fatan|fatan2|fatanh|fconstant|fcos|fcosh|fdepth|fdrop|fdup|fexp|fexpm1|field|fill|find|fliteral|fln|flnp1|float|floats|flog|floor|floored|flush|fmax|fmin|fnegate|fnip|for|form|forth|fover|fp0|fpath|fpick|free|frot|fround|fsin|fsincos|fsinh|fsqrt|fswap|ftan|ftanh|ftuck|fvariable|getenv|gforth|here|hex|hold|i|if|iferror|immediate|implementation|include|included|init|interface|invert|is|is|j|k|key|latest|latestxt|leave|link|list|literal|load|loop|lp0|lshift|marker|max|maxalign|maxaligned|method|method|method|methods|min|mod|move|ms|naligned|name|needs|negate|new|new|next|nextname|nip|noname|nothrow|object|object|of|off|on|only|or|order|over|overrides|pad|page|parse|perform|pi|pick|postpone|postpone|precision|previous|print|printdebugdata|protected|ptr|ptr|public|query|quit|rdrop|recurse|recursive|refill|repeat|represent|require|required|resize|restore|restrict|roll|root|rot|rp0|rshift|savesystem|scope|scr|seal|search|see|selector|self|sfalign|sfaligned|sfloats|sh|sign|sliteral|source|sourcefilename|sp0|space|spaces|span|static|stderr|stdin|stdout|struct|super|swap|system|table|then|this|throw|thru|tib|to|toupper|true|try|tuck|type|typewhite|unloop|unreachable|until|unused|update|use|user|utime|value|var|var|variable|vlist|vocabulary|vocs|while|with|within|word|wordlist|words|xemit|xkey|xor)\>"
 +
 +
## I can't get words with symbols in their names to work :/
 +
#color brightgreen "(\<!\|\#\|\#\!\|\#\>\|\#\>\>\|\#s\|\#tib\|\$\?\|%align\|\%alignment\|\%alloc\|\%allocate\|\%allot\|\%size\|\'\|\'\|\'cold\|\(\|\(local\)\|\)\|\*\|\*\/\|\*\/mod\|\+\|\+\!\|\+DO\|\+field\|\+load\|\+LOOP\|\+thru\|\+x\/string\|\,\|\-\|\-\-\>\|\-DO\|\-LOOP\|\-rot\|\-trailing\|\-trailing\-garbage\|\.\|\.\"\|\.\(\|\.\\\"\|\.debugline\|\.id\|\.name\|\.path\|\.r\|\.s\|\/\|\/does\-handler\|\/l\|\/mod\|\/string\|\/w\|0\<\|0\<\=\|0\<\>\|0\=\|0\>\|0\>\=\|1\+\|1\-\|1\/f\|2\!\|2\*\|2\,\|2\/\|2\>r\|2\@\|2field\:\|2r\>\|2r\@\|\:\|\:\|\:\:\|\:\:\|\:m\|\:noname\|\;\|\;code\|\;m\|\;s\|\<\|\<\#\|\<\<\#\|\<\=\|\<\>\|\<bind\>\|\<compilation\|\<interpretation\|\<to\-inst\>\|\=\|\>\|\>\=\|\>body\|\>code\-address\|\>definer\|\>does\-code\|\>float\|\>in\|\>l\|\>name\|\>number\|\>order\|\>r\|\?\|\?DO\|\?dup\|\?DUP\-0\=\-IF\|\?DUP\-IF\|\?LEAVE\|\@\|\@local\#\|\[\|\[\'\]\|\[\+LOOP\]\|\[\?DO\]\|\[\]\|\[AGAIN\]\|\[BEGIN\]\|\[bind\]\|\[Char\]\|\[COMP\'\]\|\[compile\]\|\[current\]\|\[DO\]\|\[ELSE\]\|\[ENDIF\]\|\[FOR\]\|\[IF\]\|\[IFDEF\]\|\[IFUNDEF\]\|\[LOOP\]\|\[NEXT\]\|\[parent\]\|\[REPEAT\]\|\[THEN\]\|\[to\-inst\]\|\[UNTIL\]\|\[WHILE\]\|\\\|\\c\|\\G\|\]\|\]L\|ABORT\"\|action\-of\|add\-lib\|ADDRESS\-UNIT\-BITS\|also\-path\|assert\(\|assert\-level\|assert0\(\|assert1\(\|assert2\(\|assert3\(\|ASSUME\-LIVE\|at\-xy\|base\-execute\|begin\-structure\|bind\'\|block\-included\|block\-offset\|block\-position\|break\"\|break\:\|broken\-pipe\-error\|c\!\|C\"\|c\,\|c\-function\|c\-library\|c\-library\-name\|c\@\|call\-c\|cell\%\|cell\+\|cfield\:\|char\%\|char\+\|class\-\>map\|class\-inst\-size\|class\-override\!\|class\-previous\|class\;\|class\>order\|class\?\|clear\-libs\|clear\-path\|close\-file\|close\-pipe\|cmove\>\|code\-address\!\|common\-list\|COMP\'\|compilation\>\|compile\,\|compile\-lp\+\!\|compile\-only\|const\-does\>\|create\-file\|create\-interpret\/compile\|CS\-PICK\|CS\-ROLL\|current\'\|current\-interface\|d\+\|d\-\|d\.\|d\.r\|d0\<\|d0\<\=\|d0\<\>\|d0\=\|d0\>\|d0\>\=\|d2\*\|d2\/\|d\<\|d\<\=\|d\<\>\|d\=\|d\>\|d\>\=\|d\>f\|d\>s\|dec\.\|defer\!\|defer\@\|definer\!\|delete\-file\|df\!\|df\@\|dffield\:\|dfloat\%\|dfloat\+\|dict\-new\|docol\:\|docon\:\|dodefer\:\|does\-code\!\|does\-handler\!\|DOES\>\|dofield\:\|double\%\|douser\:\|dovar\:\|du\<\|du\<\=\|du\>\|du\>\=\|edit\-line\|ekey\>char\|ekey\>fkey\|ekey\?\|emit\-file\|empty\-buffer\|empty\-buffers\|end\-c\-library\|end\-class\|end\-class\|end\-class\-noname\|end\-code\|end\-interface\|end\-interface\-noname\|end\-methods\|end\-struct\|end\-structure\|endtry\-iferror\|environment\-wordlist\|environment\?\|execute\-parsing\|execute\-parsing\-file\|f\!\|f\*\|f\*\*\|f\+\|f\,\|f\-\|f\.\|f\.rdp\|f\.s\|f\/\|f0\<\|f0\<\=\|f0\<\>\|f0\=\|f0\>\|f0\>\=\|f2\*\|f2\/\|f\<\|f\<\=\|f\<\>\|f\=\|f\>\|f\>\=\|f\>buf\-rdp\|f\>d\|f\>l\|f\>str\-rdp\|f\@\|f\@local\#\|fe\.\|ffield\:\|field\:\|file\-position\|file\-size\|file\-status\|find\-name\|float\%\|float\+\|floating\-stack\|flush\-file\|flush\-icache\|fm\/mod\|forth\-wordlist\|fp\!\|fp\@\|fs\.\|f\~\|f\~abs\|f\~rel\|get\-block\-fid\|get\-current\|get\-order\|heap\-new\|hex\.\|how\:\|id\.\|include\-file\|included\?\|infile\-execute\|init\-asm\|init\-object\|inst\-value\|inst\-var\|interpret\/compile\:\|interpretation\>\|k\-alt\-mask\|k\-ctrl\-mask\|k\-delete\|k\-down\|k\-end\|k\-f1\|k\-f10\|k\-f11\|k\-f12\|k\-f2\|k\-f3\|k\-f4\|k\-f5\|k\-f6\|k\-f7\|k\-f8\|k\-f9\|k\-home\|k\-insert\|k\-left\|k\-next\|k\-prior\|k\-right\|k\-shift\-mask\|k\-up\|key\-file\|key\?\|key\?\-file\|l\!\|laddr\#\|lib\-error\|lib\-sym\|list\-size\|lp\!\|lp\!\|lp\+\!\#\|lp\@\|m\*\|m\*\/\|m\+\|m\:\|maxdepth\-\.s\|name\>comp\|name\>int\|name\>string\|name\?int\|new\[\]\|next\-arg\|open\-blocks\|open\-file\|open\-lib\|open\-path\-file\|open\-pipe\|os\-class\|outfile\-execute\|parse\-name\|parse\-word\|path\+\|path\-allot\|path\=\|postpone\,\|r\/o\|r\/w\|r\>\|r\@\|read\-file\|read\-line\|rename\-file\|reposition\-file\|resize\-file\|restore\-input\|rp\!\|rp\@\|S\"\|s\>d\|s\>number\?\|s\>unumber\?\|s\\\"\|save\-buffer\|save\-buffers\|save\-input\|search\-wordlist\|see\-code\|see\-code\-range\|set\-current\|set\-order\|set\-precision\|sf\!\|sf\@\|sffield\:\|sfloat\%\|sfloat\+\|shift\-args\|simple\-see\|simple\-see\-range\|sl\@\|slurp\-fid\|slurp\-file\|sm\/rem\|source\-id\|sourceline\#\|sp\!\|sp\@\|str\<\|str\=\|string\-prefix\?\|sub\-list\?\|sw\@\|threading\-method\|time\&date\|to\-this\|U\+DO\|U\-DO\|u\.\|u\.r\|u\<\|u\<\=\|u\>\|u\>\=\|ud\.\|ud\.r\|ul\@\|um\*\|um\/mod\|under\+\|updated\?\|uw\@\|w\!\|w\/o\|write\-file\|write\-line\|x\-size\|x\-width\|x\\string\-\|xc\!\+\?\|xc\-size\|xc\@\+\|xchar\+\|xchar\-\|xchar\-encoding\|xt\-new\|xt\-see\|\~\~)\>"
 +
 +
## Comment highlighting
 +
color brightblue start="(^| )\( " end="\)"
 +
color brightblue "\\ .*$"
 +
</nowiki>}}
  
 
==== Other definitions ====
 
==== Other definitions ====
 +
 
Syntax highlighting enhancements which replace and expand the defaults can be found in the AUR, {{AUR|nano-syntax-highlighting-git}}.
 
Syntax highlighting enhancements which replace and expand the defaults can be found in the AUR, {{AUR|nano-syntax-highlighting-git}}.
  
 
=== Suggested configuration ===
 
=== Suggested configuration ===
 +
 
==== Suspension ====
 
==== 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.
 
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 ====
+
==== Text wrapping ====
If you are coming from another distribution, you might wonder about nano's strange behaviour, so just edit /etc/nanorc like this:
+
 
 +
Unlike many text editors, ''nano'' wraps text. To disable this put this in your {{ic|~/.nanorc}}
  
## Do not wrap text at all.
 
 
  set nowrap
 
  set nowrap
  
== nano usage ==
+
== Usage ==
 +
 
 
=== Special functions ===
 
=== Special functions ===
 +
 
* {{ic|Ctrl}} key modified shortcuts ({{Ic|^}}) representing commonly used functions are listed along the bottom two lines of the nano screen.
 
* {{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.  
 
* Additional functions can be interactively toggled by way of {{Ic|Meta}} (typically {{ic|Alt}}) and/or {{ic|Esc}} key modified sequences.  
  
 
==== Shortcut lists overview ====
 
==== Shortcut lists overview ====
* {{Ic|^G Get Help}} ({{ic|F1}})
+
 
: Displays the online help files within the session window. A suggested read for nano users of all levels
+
{| class="wikitable"
* {{Ic|^O WriteOut}} ({{ic|F3}})
+
! Key1 !! Key2 !! Command !! Description
: Save the contents of the current file buffer to a file on the disk
+
|-
* {{Ic|^R Read File}} ({{ic|F5}})
+
|^G || F1 || Get Help || Displays the online help files within the session window. A suggested read for nano users of all levels
: Inserts another file into the current one at the cursor location
+
|-
* {{Ic|^Y Prev Page}} ({{ic|F7}})
+
|^X || F2 || Exit || Close and exit nano
: Display the previous buffered screen
+
|-
* {{Ic|^K Cut Text}} ({{ic|F9}})
+
|^O || F3 || WriteOut || Save the contents of the current file buffer to a file on the disk
: Cut and store the current line from the beginning of the line to the end of the line  
+
|-
* {{Ic|^C Cur Pos}} ({{ic|F11}})
+
|^J || F4 || Justify || Aligns text according to the geometry of the console window
: Display line, column and character position information at the current location of the cursor  
+
|-
* {{Ic|^X Exit}} ({{ic|F2}})
+
|^R || F5 || Read File || Inserts another file into the current one at the cursor location
: Close and exit nano
+
|-
* {{Ic|^J Justify}} ({{ic|F4}})
+
|^W || F6 || Where || Perform a case-insensitive string, or regular expression search
: Aligns text according to the geometry of the console window
+
|-
* {{Ic|^W Where}} ({{ic|F6}})
+
|^Y || F7 || Prev Page || Display the previous buffered screen
: Perform a case-insensitive string, or regular expression search
+
|-
* {{Ic|^V Next Page}} ({{ic|F8}})
+
|^V || F8 || Next Page || Display the next buffered screen
: Display the next buffered screen
+
|-
* {{Ic|^U UnCut Text}} ({{ic|F10}})
+
|^K || F9 || Cut Text || Cut and store the current line from the beginning of the line to the end of the line
: Paste the contents of the cut buffer to the current cursor location
+
|-
* {{Ic|^T To Spell}} ({{ic|F12}})
+
|^U || F10 || UnCut Text || Paste the contents of the cut buffer to the current cursor location
: Spellcheck the contents of the buffer with the built-in {{Ic|spell}}, if available
+
|-
 +
|^C || F11 || Cur Pos || Display line, column and character position information at the current location of the cursor
 +
|-
 +
|^T || F12 || To Spell || 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.|}}
 
{{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.|}}
  
 
==== Selected toggle functions ====
 
==== Selected toggle functions ====
* {{Ic|Meta+c}} (or {{ic|Esc+c}})
 
: Toggles support for line, column and character position information.
 
  
* {{Ic|Meta+i}} (or {{ic|Esc+i}})
+
{| class="wikitable"
: Toggles support for the auto indentation of lines
+
! Key1 !! Key2 !! Description
 
+
|-
* {{Ic|Meta+k}} (or {{ic|Esc+k}})
+
|Meta+c || Esc+c || Toggles support for line, column and character position information
: Toggles support for cutting text from the current cursor position to the end of the line
+
|-
 
+
|Meta+i || Esc+i || Toggles support for the auto indentation of lines
* {{Ic|Meta+m}} (or {{ic|Esc+m}})
+
|-
: Toggles mouse support for cursor placement, marking and shortcut execution
+
|Meta+k || Esc+k || Toggles support for cutting text from the current cursor position to the end of the line
 
+
|-
* {{Ic|Meta+x}} (or {{ic|Esc+x}})
+
|Meta+m || Esc+m || 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  
+
|-
 +
|Meta+x || Esc+x || 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'''.
 
 
==== 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.''}}
 
 
[[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'''.
 
  
export EDITOR=nano
+
=== Replacing vi with nano ===
 
+
===== Example usage =====
+
  export EDITOR=nano && sudo visudo
+
 
+
==== 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.''}}
+
 
+
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)
+
* ~/.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 =====
+
{{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}}:
+
Casual users may prefer to use {{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 [[sudo#Using visudo|visudo]].
mv /usr/bin/vi.old /usr/bin/vi
+
  
==== Method four ====
+
Setting the {{ic|EDITOR}} [[Environment_variable#Defining_variables|environment variable]] will work for many applications, 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 EDITOR=nano
Use [[Pacman|pacman]] to remove the {{Ic|vi}} package, its configuration, and all unneeded dependencies:
+
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
+
  
{{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}}).|}}
+
== 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
 
* [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]

Latest revision as of 09:07, 24 January 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.

Package installation

You can install the nano package from the official repositories. It is likely that is already on your system, as it is included in the base group.

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

PKGBUILD

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)\>"

Save this file as (for example) /etc/nano/pkgbuild.nanorc.

Then include the file in your ~/.nanorc or to /etc/nanorc by adding the following line:

include "/etc/nano/pkgbuild.nanorc"

Forth

 ## Here is an example for Forth.
 ##
 syntax "forth" "\.(fs|4th|4mu)$" 
 
 ## Preprocessor statements
 color brightred "\[.+\]"
 
 ## Numbers
 color magenta "-?[0-9]+"
 
 ## Floats
 color cyan "-?[0-9\.]+e[0-9]+"
 
 ## Other Words
 
 color green "\<(2constant|2drop|2dup|2literal|2nip|2over|2rdrop|2rot|2swap|2tuck|2variable|abort|abs|accept|again|ahead|alias|align|aligned|allocate|allot|also|and|arg|argc|argv|asptr|asptr|assembler|base|begin|bin|bind|bind|bl|blank|blk|block|bootmessage|bound|bounds|buffer|bye|case|catch|cell|cells|cfalign|cfaligned|char|chars|class|class|class|clearstack|clearstacks|cmove|code|compare|constant|construct|context|convert|count|cputime|cr|create|current|dabs|dbg|decimal|defer|defer|defers|defines|definitions|definitions|depth|dfalign|dfaligned|dfloats|discode|dispose|dmax|dmin|dnegate|do|done|dpl|drop|dump|dup|early|ekey|else|emit|endcase|endif|endof|endscope|endtry|endwith|erase|evaluate|exception|execute|exit|exitm|expect|fabs|facos|facosh|falign|faligned|falog|false|fasin|fasinh|fatan|fatan2|fatanh|fconstant|fcos|fcosh|fdepth|fdrop|fdup|fexp|fexpm1|field|fill|find|fliteral|fln|flnp1|float|floats|flog|floor|floored|flush|fmax|fmin|fnegate|fnip|for|form|forth|fover|fp0|fpath|fpick|free|frot|fround|fsin|fsincos|fsinh|fsqrt|fswap|ftan|ftanh|ftuck|fvariable|getenv|gforth|here|hex|hold|i|if|iferror|immediate|implementation|include|included|init|interface|invert|is|is|j|k|key|latest|latestxt|leave|link|list|literal|load|loop|lp0|lshift|marker|max|maxalign|maxaligned|method|method|method|methods|min|mod|move|ms|naligned|name|needs|negate|new|new|next|nextname|nip|noname|nothrow|object|object|of|off|on|only|or|order|over|overrides|pad|page|parse|perform|pi|pick|postpone|postpone|precision|previous|print|printdebugdata|protected|ptr|ptr|public|query|quit|rdrop|recurse|recursive|refill|repeat|represent|require|required|resize|restore|restrict|roll|root|rot|rp0|rshift|savesystem|scope|scr|seal|search|see|selector|self|sfalign|sfaligned|sfloats|sh|sign|sliteral|source|sourcefilename|sp0|space|spaces|span|static|stderr|stdin|stdout|struct|super|swap|system|table|then|this|throw|thru|tib|to|toupper|true|try|tuck|type|typewhite|unloop|unreachable|until|unused|update|use|user|utime|value|var|var|variable|vlist|vocabulary|vocs|while|with|within|word|wordlist|words|xemit|xkey|xor)\>"
 
 ## I can't get words with symbols in their names to work :/
 #color brightgreen "(\<!\|\#\|\#\!\|\#\>\|\#\>\>\|\#s\|\#tib\|\$\?\|%align\|\%alignment\|\%alloc\|\%allocate\|\%allot\|\%size\|\'\|\'\|\'cold\|\(\|\(local\)\|\)\|\*\|\*\/\|\*\/mod\|\+\|\+\!\|\+DO\|\+field\|\+load\|\+LOOP\|\+thru\|\+x\/string\|\,\|\-\|\-\-\>\|\-DO\|\-LOOP\|\-rot\|\-trailing\|\-trailing\-garbage\|\.\|\.\"\|\.\(\|\.\\\"\|\.debugline\|\.id\|\.name\|\.path\|\.r\|\.s\|\/\|\/does\-handler\|\/l\|\/mod\|\/string\|\/w\|0\<\|0\<\=\|0\<\>\|0\=\|0\>\|0\>\=\|1\+\|1\-\|1\/f\|2\!\|2\*\|2\,\|2\/\|2\>r\|2\@\|2field\:\|2r\>\|2r\@\|\:\|\:\|\:\:\|\:\:\|\:m\|\:noname\|\;\|\;code\|\;m\|\;s\|\<\|\<\#\|\<\<\#\|\<\=\|\<\>\|\<bind\>\|\<compilation\|\<interpretation\|\<to\-inst\>\|\=\|\>\|\>\=\|\>body\|\>code\-address\|\>definer\|\>does\-code\|\>float\|\>in\|\>l\|\>name\|\>number\|\>order\|\>r\|\?\|\?DO\|\?dup\|\?DUP\-0\=\-IF\|\?DUP\-IF\|\?LEAVE\|\@\|\@local\#\|\[\|\[\'\]\|\[\+LOOP\]\|\[\?DO\]\|\[\]\|\[AGAIN\]\|\[BEGIN\]\|\[bind\]\|\[Char\]\|\[COMP\'\]\|\[compile\]\|\[current\]\|\[DO\]\|\[ELSE\]\|\[ENDIF\]\|\[FOR\]\|\[IF\]\|\[IFDEF\]\|\[IFUNDEF\]\|\[LOOP\]\|\[NEXT\]\|\[parent\]\|\[REPEAT\]\|\[THEN\]\|\[to\-inst\]\|\[UNTIL\]\|\[WHILE\]\|\\\|\\c\|\\G\|\]\|\]L\|ABORT\"\|action\-of\|add\-lib\|ADDRESS\-UNIT\-BITS\|also\-path\|assert\(\|assert\-level\|assert0\(\|assert1\(\|assert2\(\|assert3\(\|ASSUME\-LIVE\|at\-xy\|base\-execute\|begin\-structure\|bind\'\|block\-included\|block\-offset\|block\-position\|break\"\|break\:\|broken\-pipe\-error\|c\!\|C\"\|c\,\|c\-function\|c\-library\|c\-library\-name\|c\@\|call\-c\|cell\%\|cell\+\|cfield\:\|char\%\|char\+\|class\-\>map\|class\-inst\-size\|class\-override\!\|class\-previous\|class\;\|class\>order\|class\?\|clear\-libs\|clear\-path\|close\-file\|close\-pipe\|cmove\>\|code\-address\!\|common\-list\|COMP\'\|compilation\>\|compile\,\|compile\-lp\+\!\|compile\-only\|const\-does\>\|create\-file\|create\-interpret\/compile\|CS\-PICK\|CS\-ROLL\|current\'\|current\-interface\|d\+\|d\-\|d\.\|d\.r\|d0\<\|d0\<\=\|d0\<\>\|d0\=\|d0\>\|d0\>\=\|d2\*\|d2\/\|d\<\|d\<\=\|d\<\>\|d\=\|d\>\|d\>\=\|d\>f\|d\>s\|dec\.\|defer\!\|defer\@\|definer\!\|delete\-file\|df\!\|df\@\|dffield\:\|dfloat\%\|dfloat\+\|dict\-new\|docol\:\|docon\:\|dodefer\:\|does\-code\!\|does\-handler\!\|DOES\>\|dofield\:\|double\%\|douser\:\|dovar\:\|du\<\|du\<\=\|du\>\|du\>\=\|edit\-line\|ekey\>char\|ekey\>fkey\|ekey\?\|emit\-file\|empty\-buffer\|empty\-buffers\|end\-c\-library\|end\-class\|end\-class\|end\-class\-noname\|end\-code\|end\-interface\|end\-interface\-noname\|end\-methods\|end\-struct\|end\-structure\|endtry\-iferror\|environment\-wordlist\|environment\?\|execute\-parsing\|execute\-parsing\-file\|f\!\|f\*\|f\*\*\|f\+\|f\,\|f\-\|f\.\|f\.rdp\|f\.s\|f\/\|f0\<\|f0\<\=\|f0\<\>\|f0\=\|f0\>\|f0\>\=\|f2\*\|f2\/\|f\<\|f\<\=\|f\<\>\|f\=\|f\>\|f\>\=\|f\>buf\-rdp\|f\>d\|f\>l\|f\>str\-rdp\|f\@\|f\@local\#\|fe\.\|ffield\:\|field\:\|file\-position\|file\-size\|file\-status\|find\-name\|float\%\|float\+\|floating\-stack\|flush\-file\|flush\-icache\|fm\/mod\|forth\-wordlist\|fp\!\|fp\@\|fs\.\|f\~\|f\~abs\|f\~rel\|get\-block\-fid\|get\-current\|get\-order\|heap\-new\|hex\.\|how\:\|id\.\|include\-file\|included\?\|infile\-execute\|init\-asm\|init\-object\|inst\-value\|inst\-var\|interpret\/compile\:\|interpretation\>\|k\-alt\-mask\|k\-ctrl\-mask\|k\-delete\|k\-down\|k\-end\|k\-f1\|k\-f10\|k\-f11\|k\-f12\|k\-f2\|k\-f3\|k\-f4\|k\-f5\|k\-f6\|k\-f7\|k\-f8\|k\-f9\|k\-home\|k\-insert\|k\-left\|k\-next\|k\-prior\|k\-right\|k\-shift\-mask\|k\-up\|key\-file\|key\?\|key\?\-file\|l\!\|laddr\#\|lib\-error\|lib\-sym\|list\-size\|lp\!\|lp\!\|lp\+\!\#\|lp\@\|m\*\|m\*\/\|m\+\|m\:\|maxdepth\-\.s\|name\>comp\|name\>int\|name\>string\|name\?int\|new\[\]\|next\-arg\|open\-blocks\|open\-file\|open\-lib\|open\-path\-file\|open\-pipe\|os\-class\|outfile\-execute\|parse\-name\|parse\-word\|path\+\|path\-allot\|path\=\|postpone\,\|r\/o\|r\/w\|r\>\|r\@\|read\-file\|read\-line\|rename\-file\|reposition\-file\|resize\-file\|restore\-input\|rp\!\|rp\@\|S\"\|s\>d\|s\>number\?\|s\>unumber\?\|s\\\"\|save\-buffer\|save\-buffers\|save\-input\|search\-wordlist\|see\-code\|see\-code\-range\|set\-current\|set\-order\|set\-precision\|sf\!\|sf\@\|sffield\:\|sfloat\%\|sfloat\+\|shift\-args\|simple\-see\|simple\-see\-range\|sl\@\|slurp\-fid\|slurp\-file\|sm\/rem\|source\-id\|sourceline\#\|sp\!\|sp\@\|str\<\|str\=\|string\-prefix\?\|sub\-list\?\|sw\@\|threading\-method\|time\&date\|to\-this\|U\+DO\|U\-DO\|u\.\|u\.r\|u\<\|u\<\=\|u\>\|u\>\=\|ud\.\|ud\.r\|ul\@\|um\*\|um\/mod\|under\+\|updated\?\|uw\@\|w\!\|w\/o\|write\-file\|write\-line\|x\-size\|x\-width\|x\\string\-\|xc\!\+\?\|xc\-size\|xc\@\+\|xchar\+\|xchar\-\|xchar\-encoding\|xt\-new\|xt\-see\|\~\~)\>"
 
 ## Comment highlighting
 color brightblue start="(^| )\( " end="\)"
 color brightblue "\\ .*$"

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

Special functions

  • Ctrl 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 Alt) and/or Esc key modified sequences.

Shortcut lists overview

Key1 Key2 Command Description
^G F1 Get Help Displays the online help files within the session window. A suggested read for nano users of all levels
^X F2 Exit Close and exit nano
^O F3 WriteOut Save the contents of the current file buffer to a file on the disk
^J F4 Justify Aligns text according to the geometry of the console window
^R F5 Read File Inserts another file into the current one at the cursor location
^W F6 Where Perform a case-insensitive string, or regular expression search
^Y F7 Prev Page Display the previous buffered screen
^V F8 Next Page Display the next buffered screen
^K F9 Cut Text Cut and store the current line from the beginning of the line to the end of the line
^U F10 UnCut Text Paste the contents of the cut buffer to the current cursor location
^C F11 Cur Pos Display line, column and character position information at the current location of the cursor
^T F12 To Spell 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

Key1 Key2 Description
Meta+c Esc+c Toggles support for line, column and character position information
Meta+i Esc+i Toggles support for the auto indentation of lines
Meta+k Esc+k Toggles support for cutting text from the current cursor position to the end of the line
Meta+m Esc+m Toggles mouse support for cursor placement, marking and shortcut execution
Meta+x 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 to use 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.

Setting the EDITOR environment variable will work for many applications, for example:

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