taking notes with bash + vim

01 Apr 2008

Posted by acrollet

A co-worker sold me on the utility of having a program like Yojimbo. However, I'm too cheap to shell out the $39 for a license, and I prefer to have vi key bindings, and complete keyboard control. I found an excellent post at make-believe.org which describes a system for note-taking using a little bash magic for searching and command line tab completion, and vim for editing. I liked it a lot, but decided to add tagging to the system. Read on to find out how I did it.

host:~ $ note testnote

(:xa will save all buffers and quit in one swell foop)

host:~ $ findnote note
/Users/acrollet/.notes/test note.note
1:This is a test note.
host:~ $ findtag bash
/Users/acrollet/.notes/test note.tags
1:bash vi note-taking

The bash file to do the above looks like this:

  1. note() {
  2.   if [ -n "$*" ]; then
  3.     mvim -o2 "$HOME/.notes/$*.note" "$HOME/.notes/$*.tags"
  4.   else
  5.     printf "Name of note is a required argument.\n"
  6.   fi
  7. }
  9. findnote() {
  10.   ack -ia $1 ~/.notes/*.note
  11. }
  13. shownote() {
  14.   cat "$HOME/.notes/$*.note"
  15. }
  17. findtag() {
  18.   ack -ia $1 ~/.notes/*.tags
  19. }
  21. copynote() {
  22.   cat "$HOME/.notes/$*.note" | pbcopy
  23. }
  25. alias note:='note'
  26. alias shownote:='shownote'
  27. alias notes="mvim -c \"let g:netrw_list_hide='\.tags$,^\..*'\" -c \"let g:netrw_hide=1\" $HOME/.notes"
  29. _notes() {
  30.   local cur names IFS
  32.   cur="${COMP_WORDS[COMP_CWORD]}"
  33.   names=`ls $HOME/.notes | sed 's/.note$//g'`
  34.   IFS=$'\t\n'
  36.   COMPREPLY=( $(compgen -W "${names}" -- ${cur}) )
  37.   return 0
  38. }
  39. complete -o nospace -F _notes note
  40. complete -o nospace -F _notes note:
  41. complete -o nospace -F _notes copynote

Now, here's the other piece. Put this in your .vimrc:

let g:netrw_hide=1
let g:netrw_list_hide='\.tags$,^\..*'

And this in netrwFileHandlers.vim: (you may need a more recent version than came with your distribution, v98 did not work for me)

" ---------------------------------------------------------------------
" s:NFH_note: handles note file when the user hits "x" when the {{{1
"                        cursor is atop a *.note file
fun! s:NFH_note(notefile)
"  call Dfunc("s:NFH_note(".a:notefile.")")

  let note= substitute(a:notefile,'\ ','\\\ ','g')
  let tags= substitute(a:notefile,'\.note$','\.tags','')
  let tag= substitute(tags,'\ ','\\\ ','g')

   " call Decho("opening "page)
   execute "e "tag
   execute "sp "note
   return 0

Now, when you type 'notes' at the prompt, you'll get this view:

Place the cursor over the note you wish to edit, press 'x', and it will open up the split-pane view with the note and tag files. I welcome suggestions for improvements!

Blog Tags: 

Add new comment

The content of this field is kept private and will not be shown publicly.
By submitting this form, you accept the Mollom privacy policy.