# Micro text editor

**URL:** <https://forum.openwrt.org/t/micro-text-editor/107764>\
**Category:** Installing and Using OpenWrt\
**Created:** [September 29, 2021, 9:41am UTC](https://forum.openwrt.org/t/micro-text-editor/107764 "2021-09-29T09:41:18Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![oslyak](https://forum.openwrt.org/user_avatar/forum.openwrt.org/oslyak/32/5586_2.png) [@oslyak](https://forum.openwrt.org/u/oslyak)\
**Post date:** [September 29, 2021, 9:41am UTC](https://forum.openwrt.org/t/micro-text-editor/107764/1 "2021-09-29T09:41:18Z")

</div>

Hi!

Recently I found awesome text editor called **micro**.  
After some time of using it want to say Goodbye to **vim** and **nano**.  
There is any way to run it under **OpenWRT**?

---

<div class="post-metadata">

**Author:** ![Random3](https://forum.openwrt.org/letter_avatar/random3/32/5_5575768a8748004e209b776fc1b2916d.png) [@Random3](https://forum.openwrt.org/u/Random3)\
**Post date:** [February 14, 2022, 7:03am UTC](https://forum.openwrt.org/t/micro-text-editor/107764/2 "2022-02-14T07:03:38Z")

</div>

I would prefer micro to other editors if it works on openwrt. Is there any progress in this direction?

---

<div class="post-metadata">

**Author:** ![okibcn](https://forum.openwrt.org/user_avatar/forum.openwrt.org/okibcn/32/48262_2.png) [@okibcn](https://forum.openwrt.org/u/okibcn)\
**Post date:** [March 12, 2022, 3:32am UTC](https://forum.openwrt.org/t/micro-text-editor/107764/3 "2022-03-12T03:32:00Z")

</div>

The big problem of micro is the size. Compared to vim, nano or even the integrated editor in mc, it is huge!  
Anyway, I am sure there are ways to make it smaller. It would be a matter of time until someone makes a tiny version of micro editor for embedded systems.

---

<div class="post-metadata">

**Author:** ![okibcn](https://forum.openwrt.org/user_avatar/forum.openwrt.org/okibcn/32/48262_2.png) [@okibcn](https://forum.openwrt.org/u/okibcn)\
**Post date:** [March 12, 2022, 7:44am UTC](https://forum.openwrt.org/t/micro-text-editor/107764/4 "2022-03-12T07:44:17Z")

</div>

You don't need a package to use micro if your router has a standard processor architecture.

For instance for the E8450 (ARM64 architecture), I just download the file into /usr/bin using the command in my router:

```nohighlight
wget https://github.com/zyedidia/micro/releases/download/v2.0.10/micro-2.0.10-linux-
arm64.tar.gz -qO- |tar xz && mv ./*/micro /usr/bin

```

If your router uses a different architecture, golang compiler can quickly generate code for linux in these architectures: `386`,`amd64`,`arm`,`arm64`,`ppc64`,`ppc64le`,`mips`,`mipsle`,`mips64` and `mips64le`.  
Just [install the golang compiler](https://go.dev/doc/install) (`go version` over 1.16) and do something like this in your build PC:

```nohighlight
git clone https://github.com/zyedidia/micro
cd micro
GOOS=linux GOARCH=mips make build
sudo apt install upx
upx --lzma --best micro
scp micro root@192.168.1.1:/usr/bin

```

Obviously use the GOARCH according yo your router's architecture and use the right IP of your router for the scp command.

Please note that the size of the optimized binary is around 2.6MB!!!! so, micro is not by any means a small program, and can only be an option for routers with enough storage. Just check your available storage in your router.

regarding the size, there are [ways to optimize](https://prog.world/optimizing-the-size-of-the-go-binary/) it. I use UPX as it is more efficient than the gzip-like algorithm squashfs uses.

---

<div class="post-metadata">

**Author:** ![okibcn](https://forum.openwrt.org/user_avatar/forum.openwrt.org/okibcn/32/48262_2.png) [@okibcn](https://forum.openwrt.org/u/okibcn)\
**Post date:** [March 14, 2022, 5:02am UTC](https://forum.openwrt.org/t/micro-text-editor/107764/5 "2022-03-14T05:02:02Z")

</div>

By the way, there is another way of having a modern CLI text editor in OpenWrt. Instead of using the `nano` package, use the package `nano-plus`. It allows for extra configuration features while keeping a tiny footprint.

With this new plus version we can customize it using the `~/.nanorc` config file. If you create it with the following configuration, then you won't miss the micro editor:

```nohighlight
bind ^X cut main # CTRL+X - Cut
bind ^C copy main # CTRC+C - Copy
bind ^V paste all # CTRL+V - Past
bind ^Q exit all # CTRL+Q - Quit program
bind ^S savefile main # CTRL+S - Save
bind ^Z undo all # CTRL+Z - Undo
bind ^Y redo all # CTRL+Y - Redo
bind ^H replace main # CTRL+H - Replace
bind ^F whereis main # CTRL+F - Find
bind F3 findnext main # F3 - Find next
#bind ^/ comment main # CTRL+/ - Comment

set atblanks # don't cut words when doing line wrap.
set nohelp # don't display help messages
set softwrap # don't break lines
set suspend # don't suspend the shell
set tabsize 4 # tab stops every 4 spaces
set tabstospaces # convert tabs to spaces
set constantshow # show constants
set linenumbers # show line numbers Alt+N to toggle
set casesensitive # case sensitive
set zap # zap to the end of the line
set autoindent # auto indent
set indicator # show the cursor position
set minibar # show the minibar
set nonewlines # don't insert newlines
#set backup # don't make backups
#set backupdir "/tmp" # where to put the backups

include /usr/share/nano/*

```

---

<div class="post-metadata">

**Author:** ![Random3](https://forum.openwrt.org/letter_avatar/random3/32/5_5575768a8748004e209b776fc1b2916d.png) [@Random3](https://forum.openwrt.org/u/Random3)\
**Post date:** [March 16, 2022, 2:19am UTC](https://forum.openwrt.org/t/micro-text-editor/107764/6 "2022-03-16T02:19:07Z")

</div>

Does nano-plus support syntax highlighting?

---

<div class="post-metadata">

**Author:** ![okibcn](https://forum.openwrt.org/user_avatar/forum.openwrt.org/okibcn/32/48262_2.png) [@okibcn](https://forum.openwrt.org/u/okibcn)\
**Post date:** [March 16, 2022, 3:39am UTC](https://forum.openwrt.org/t/micro-text-editor/107764/7 "2022-03-16T03:39:32Z")

</div>

The standard nano-plus doesn't support it, but with a small patch it can generate a nano-plusplus. The ipk of this nano++ package is 156 KB, so it could be used in any device with small size. It is about 49 KB more than the standard nano-plus.  
This is how it looks using SSH:

 ![Screenshot 2022-03-15 203421](https://forum.openwrt.org/uploads/default/original/3X/6/a/6a321f540915c49f600483c6817dc7928cb46402.jpeg)

And this is using the integrated TTY:

 ![Untitled](https://forum.openwrt.org/uploads/default/original/3X/7/0/70b1563c9003e7bba53e856ae21af6e6f9c303d4.png)

And it highlights these languages:  
autoconf elisp java nanohelp php tcl awk email javascript nanorc po tex c json nftables python texinfo changelog go lua objc ruby xml cmake groff makefile ocaml rust yaml css guile man patch sh ada fortran haskell povray spec.

Who needs a 10 MB micro editor when nano can do pretty much the same with a 156 KB package?

---

<div class="post-metadata">

**Author:** ![Random3](https://forum.openwrt.org/letter_avatar/random3/32/5_5575768a8748004e209b776fc1b2916d.png) [@Random3](https://forum.openwrt.org/u/Random3)\
**Post date:** [March 17, 2022, 7:44am UTC](https://forum.openwrt.org/t/micro-text-editor/107764/8 "2022-03-17T07:44:34Z")

</div>

Hmm, I guess I could give it a try. Where to get and how to apply this patch? By the way, will the syntax highlighting work for .conf files?

---

<div class="post-metadata">

**Author:** ![okibcn](https://forum.openwrt.org/user_avatar/forum.openwrt.org/okibcn/32/48262_2.png) [@okibcn](https://forum.openwrt.org/u/okibcn)\
**Post date:** [March 18, 2022, 12:17am UTC](https://forum.openwrt.org/t/micro-text-editor/107764/9 "2022-03-18T00:17:03Z")

</div>

Sure, just use this `conf.nanorc` file and place it into `/usr/share/nano/`

```bash
syntax "\conf$" "conf" "bash_profile" "bash_history" "\rc$" "(\.|/|)control$" "(\.(repo|conf|config|cfg|cnf|rc|lst|list|defs|ini|desktop|mime|types|preset|cache|seat|service|htaccess)$|(^|/)(\w*crontab|mirrorlist|group|hosts|passwd|rpc|netconfig|shadow|fstab|inittab|inputrc|protocols|sudoers)$|conf.d/|.config/|config/)"

# default text
color white "^.*$"

# special values
icolor brightblue "(^|\s|=)(default|true|false|on|off|yes|no)(\s|$)"

# keys
icolor cyan "^\s*(set\s+)?[A-Z0-9_\/\.\%\@+-]+\s*([:]|\>)"

# commands
color blue "^\s*set\s+\<"

# punctuation
color blue "[.]"

# numbers
color red "(^|\s|[[/:|<>(){}=,]|\])[-+]?[0-9](\.?[0-9])*%?($|\>)"

# keys
icolor cyan "^\s*(\$if )?([A-Z0-9_\/\.\%\@+-]|\s)+="

# punctuation
color blue "/"
color brightwhite "(\]|[()<>[{},;:=])"
color brightwhite "(^|\[|\{|\:)\s*-(\s|$)"

# section headings
icolor brightyellow "^\s*(\[([A-Z0-9_\.-]|\s)+\])+\s*$"
color brightcyan "^\s*((Sub)?Section\s*(=|\>)|End(Sub)?Section\s*$)"
color brightcyan "^\s*\$(end)?if(\s|$)"

# URLs
icolor green "\b(([A-Z]+://|www[.])[A-Z0-9/:#?&$=_\.\-]+)(\b|$| )"

# XML-like tags
icolor brightcyan "</?\w+((\s*\w+\s*=)?\s*("[^"]*"|'[^']*'|!?[A-Z0-9_:/]))*(\s*/)?>"

color green "\<(break|case|continue|do|done|elif|else|esac|exit|fi|for|function|if|in|read|return|select|shift|then|time|until|while)\>"
color green "\<(declare|eval|exec|export|let|local)\>"
color green "[{}():;|`$<>!=&\\]" "(\]|\[)"
color green "-[Ldefgruwx]\>"
color green "-(eq|ne|gt|lt|ge|le|s|n|z)\>"
color brightblue "\<(awk|cat|cd|ch(grp|mod|own)|cp|echo|env|grep|install|ln|make|mkdir|mv|popd|printf|pushd|rm|rmdir|sed|set|tar|touch|umask|unset)\>"

# Basic variable names (no braces).
color brightred "\$[-0-9@*#?$!]" "\$[[:alpha:]_][[:alnum:]_]*"
# More complicated variable names; handles braces and replacements and arrays.
color brightred "\$\{[#!]?([-@*#?$!]|[0-9]+|[[:alpha:]_][[:alnum:]_]*)(\[([[:space:]]*[[:alnum:]_]+[[:space:]]*|@)\])?(([#%/]|:?[-=?+])[^}]*\}|\[|\})"

# Comments.
color brightblack "(^|[[:space:]])#.*$"

# Strings.
color brightyellow ""(\\.|[^"])*"" "'(\\.|[^'])*'"

# Trailing whitespace.
color ,green "[[:space:]]+$"

```

A full featured nano-full package doesn't exsist yet, but it is in the oven. You can build it yourself by modifying the Makefile of the nano package, and then build the image. The details on the nano-full package are being discussed here too:

> <https://github.com/openwrt/packages/pull/18049>
>
> nano-plus was a very welcome addition, something similar to what I had used for …years already; since I do some development natively, I really enjoy c/c++ syntax colouring. And why not some other added features as well, not maybe suitable for devices with minimal flash, but for those cases where \_size does not matter\_ ... So I integrated my personal version of package to nano package.
> 
> So here's nano-full with nearly all the bells and whistles, but still - biggest and most visible change to nano-plus, is syntax colouring.
> 
> Some features for quite obvious reasons (from my point of view) were left out, like mouse support. This PR is not critically important; not so sure if it's that useful either, could be just me who wants more of his favourite editor, well anyway, here it is, incase that there is some interest..
> 
> Signed-off-by: Oskari Rauta \<oskari.rauta@gmail.com\>
> 
> Maintainer: Hannu Nyman / @hnyman 
> Compile tested: x86\_64, master
> Run tested: x86\_64, master

For the instructions on how to install the full version with all the features enabled, I have posted the instructions here:

> [@NANO editor, how to get all the juice from it (mouse, syntax highlight and more)](https://forum.openwrt.org/t/nano-editor-how-to-get-all-the-juice-from-it/123008):
>
> In a few threads, people are writing in this forum about the need for a user friendly editor. GNU Nano should be that one, but not in its default state. A lot of people, including myself, are not used to the vi or emacs editor framework. And nano, using the default settings, is not quite friendly as the keybindings are not familiar to most. A few weeks ago I opened an [issue](https://github.com/openwrt/packages/issues/17710) asking for nanorc configuration support. @hnyman closed it with the release of the [nano-plus package](https://openwrt.org/packages/pkgdata/nano-plus). However, despite th…
