Getting my shit together …with vimwiki



At a certain age you start feeling that it’s time to start thinking. My main goal in my attempts to organize my thoughts has always been to stay focused. (On the level to at least not forget the last New Year resolutions, heh). My first approach to put more thoughts in choosing my activities was the usage of mind maps. Mind maps are perfect for visualising concepts, knowledge, wishes and goals. Being herirachical and visual they tremendeously help not only to stay focused around the things you put in the center but also to keep the eye on the whole picture. But I did not find a software that would allow me to edit mind maps as conviniently as editing of plain text files.

Then I discovered Org-mode. If you don’t know Org-mode, then check it out. In short it allows you to do magic in plain text. After seeing this and starting actively using it you can’t return. You simply can’t exchange the convenience and power of editing plain text to the visual appeal of any GUI software. Org-mode alone can replace interactive python notebook, spreadsheet calculator(though I would recommend sc-im), and many more. So I ultimately migrated my brain dump from mind maps to plain text files using org-mode. Org-mode is great, Org-mode is magnificent, Org-mode is superior … and it requires Emacs. I’d been searching for alternatives in vim for quite a while. Using Emacs for only one plugin (with evil-mode and all the stuff), tolerating slower start up time just did not feel right to me. Finally, I think, I can say thanks to org-mode (for introducing text outliners concept to me) and move on to tweaking vim plugins.

vimwiki minimal setup

At the core of my new knowledge base setup I ended up using vimwiki vim plugin. It allows you to create a personal plain text wiki (it can be exported to various formats though, including html) . The first thing you’ll love when try this - is the convenience of creating links and navigating between the pages (files). It’s just pressing Enter and Backspace keys. This feature worked well for me out of the box, other things however required adjustments.

Format

First you have to choose the format for the text files - it can be either native vimwiki format or markdown. I choose markdown because it’s widespread (this website for example is statically generated from markdown files). It’s even better now that I don’t need to keep Org-mode syntax in my head anymore:

let g:vimwiki_list = [{'path': '~/vimwiki/', 'syntax': 'markdown', 'ext': '.md'}]    " path to personal wiki and syntax
let g:vimwiki_global_ext = 0  " dont treat other .md files as wiki    
autocmd FileType vimwiki setlocal syntax=markdown " this is to use the standard md highlighting, but 'vimwiki' would work too

Folding

The most vital part for me, however, is folding. I found that using the example of folding function VimwikiFoldLevelCustom(lnum) from vimwiki documentation and changing folding settings accordingly serves pretty well for my needs. However I find It’s distracting how vim shows folded lines by default. It’s difficult for me to keep the context if the header text changes position within the line after folding, so I have a custom fold-text function in my .vimrc, it preserves the text position of the header, just adds ellipsis at the end:

function! MyFoldText()
    return substitute(getline(v:foldstart),"^ *","",1). '...             ' 
endfunction
set foldtext=MyFoldText()

Now za should nicely toggle folding of the text related to the current header. I like when the text related to the second level headers in my wiki is folded by default so I have:

autocmd FileType vimwiki setlocal foldlevel=1  " Fold ##-level headers

No autosaving

The last thing, vimwiki wants to autosave files, I prefer not to:

let g:vimwiki_autowriteall = 0
set hidden                        " Allow change buffer without saving

Note taking

Our wiki is ready for adding the content. One approach could be to start doing it from top to bottom - by adding files that you feel are important to have (for example you can store your bookmarks in vimwiki to consolidate your text assets).

Another approach could be to do this from bottom to top - by adding random notes and later sorting them out, finding common patterns and making hierarchy out of them.

Here is my shell script for note taking that I have bound to a hot key in my wm:

dt=`date +"%Y-%B-%d"`
vi -c 'execute "normal Go"' -c "execute \"normal 0i\n# ${dt}:\n\    \""  ~/vimwiki/RandomNotes.md

It just opens the notes page in vim and writes the current date to the new line, so your note will have the date when it was made.

Conclusion

It’s just a minimal setup to start getting things together, on the Internet you will find more information. One interesting thing is the integration of vimwiki with other productivity tools.