Blog: vimwiki

VimWiki outside of Vim Revisted

Since me last post about VimWiki on the command line I have created a new script. I have also decided to run it as a function rather than an alias.

The new function is as follows

#!/bin/sh

function notesfind(){

wordfind=$1

/bin/grep -rwi "$wordfind" /home/frrobert/Nextcloud/vimwiki | fzf |cut -f1 -d":" | xargs cat

}

The function searchs within VimWiki documents to find a word match based on the word given. They syntax is notesfind followed by the word you are searching for. The results from grep are sent to fzf where a menu is presented with all the files that include the word along with the line of the file where the word is found. Once you select the file you are interested in, the file is displayed on the command line.

To the use the script simply copy the text of the script to an empty file and change the path to the location of your VimWiki files.. The way it is written is it can be used as a shell function or a shell script.

Remember this is not designed to replace the search VimWiki but a way to access a VimWiki document without having to switch to Vim when you are doing other work on the command line.

Bibliography

VimWiki https://github.com/vimwiki/vimwiki

cheat.sh https://github.com/chubin/cheat.sh

fzf https://github.com/junegunn/fzf

Luke Smith's fzf Video https://www.youtube.com/watch?v=vt33Hp-4RXg

VimWiki outside of Vim

I am a big fan of Vim. I use it to do my general word processing, to keep a diary, and to keep general notes. A plugin called VimWiki helps me to the last two. VimWiki allows you to keep notes and a diary. The notes in my Wiki are varied but one thing I keep in the wiki is little notes about commands I use in the shell. Often I forgot the syntax of a command while I am working on the command line but I know I have notes in my wiki on how to do what I want. So I have to go to Vim find the entry I want then go back to command line and type the command. This is assuming I haven't forgotten what the wiki said by the time I get back to the command line.

I found a neat little utility call cheat.sh. It will bring up an abbreviated cheat sheet for the command you typed in. I wanted to do something similarly but with my VimWiki entries. If I know the wiki entry file name I could just use the cat command to show it on the screen. I am too old for that. I remember coming across a YouTube Video by Luke Smith about fzf.

So between the video and fzf I came up with an alias to allow me to find wiki entries.

alias notes='du -a /home/frrobert/Nextcloud/vimwiki/* |awk "{print$2}" | fzf | xargs -r cat'

I type notes and hit enter and a list of wiki entries come up and I type what I think may be the file name and fzf finds it for me. One more strike of the enter key and the article is there on the command line.

Bibliography

VimWiki https://github.com/vimwiki/vimwiki

cheat.sh https://github.com/chubin/cheat.sh

fzf https://github.com/junegunn/fzf

Luke Smith's fzf Video https://www.youtube.com/watch?v=vt33Hp-4RXg