LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Blogs > linux-related notes
User Name
Password

Notices


Just annotations of little "how to's", so I know I can find how to do something I've already done when I need to do it again, in case I don't remember anymore, which is not unlikely. Hopefully they can be useful to others, but I can't guarantee that it will work, or that it won't even make things worse.
Rate this Entry

Somewhat handier editing of Zim wiki files with Nano (with zim markup highlighting) + Ranger

Posted 06-20-2025 at 10:56 PM by the dsc
Updated 06-20-2025 at 11:02 PM by the dsc
Tags nano, ranger, zim

Or perhaps "the vim-inept person's fake vim-wiki, nano-ranger-zim-wiki". It's really nothing but the literal use of the command-line file manager "ranger" to open the zim's text files in nano, plus a nano highlighting config file for nano's markup syntax. Which is really the crux of this excuse for a blog post. Some AI generated it for me, there may be something better around created by an actual person, but while you don't find one:

Code:
## Zim Wiki syntax highlighting for nano

syntax "zim" "\.(txt|wiki|zim)$"

# Headings: lines starting with one or more = signs, e.g. == Heading ==
color brightcyan "^(=+).*(=+)$"

# Bold: **bold**
color brightyellow "\*\*[^*]+\*\*"

# Italic: //italic//
color brightmagenta "//[^/]+//"

# Underline: __underline__
color brightblue "__[^_]+__"

# Monospace/code: {{code}}
color green "\{\{[^}]+\}\}"

# Links: [[Link]] or [[Link|Text]]
color brightgreen "\[\[[^]\|]+(\|[^]]+)?\]\]"

# Bullet points: lines starting with * or -
color brightred "^\s*[\*\-]\s"

# Numbered list: lines starting with digit+.
color brightred "^\s*[0-9]+\.\s"

# Horizontal line: ----
color yellow "^----+$"

# Inline comments: {{comment}}
color magenta "\{\{[^}]*\}\}"

# TODO tags often use [ ] or [X]
color red "\[[ xX]\]"
It has to go on some place like ~/.config/nano or ~/.nano and your .nanorc needs the include line:

Code:
include ~/.nano/zim.nanorc
My nano is called by a wrap-around script (aliased as "nano") that edits the files in /tmp and only really saves to disk on exit, leaving some kind of temporary sloppy versioning trail there in /tmp/ something like ${basename}.tmp$(date %s).

But besides that there's this section that checks whether the file being opened is a zim file to automate the "-Y zim" part, which unfortunately apparently can't be done in a more elegant way like from some header information or something, or so some LLM AI has told me. But I digress:

Code:
if  head -n 1 $tempfile | grep -q "Content-Type: text/x-zim-wiki"  || [[ "$PWD" == "$HOME/Notes" ]] || [[ "$(realpath "${originalfile}")" == "$HOME/Notes" ]] ; then zim="-Y zim" ; fi

# [...]

/usr/bin/nano "$tempfile" "${@:2}" $zim
Where $tempfile and $originalfile would be the same thing for people not into the bogus-versioning thing, and likely ultimately "${@:2}" -- if there is not any other way than a wrap-around script. Maybe something with bashrc inspecting whether the command is nano and then injecting "-Y zim" when appropriate, I don't know.

Perhaps there are other command-line/curses file managers that are analog to ranger for this kind of use, it's cool that it opens the txt with zim automatically and we're back at it after closing nano. Maybe even more ideal would be curses-like menu within nano itself, which it may well have and I never knew, although I suspect it doesn't have.

With this setup, editing a zim wiki with nano is semi-almost-kind-of a quasi-adequate approximation to zim itself, sans auto-formatting with buttons and links and all that kind of stuff. But still handier than just nano and the"cd" command if for whatever reason you don't feel like grabbing the mouse and miss the good old days where the keyboard was pretty much enough to navigate through the interfaces of most programs in some sane way rather than hitting tab a thousand of times.

Likely not as good as vimwiki, though, although apparently that's not even compatible with the markup of zim, it has to be converted I guess. Which gives me an additional reason to not try to learn vim, which ends up saving me some time, I guess, at least in the time span required for climbing the steep learning curve.
Posted in Uncategorized
Views 26 Comments 0
« Prev     Main     Next »
Total Comments 0

Comments

 

  



All times are GMT -5. The time now is 04:11 PM.

Main Menu
Advertisement
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration