diff options
Diffstat (limited to 'src/Note-taking_with_Vim.adoc')
-rw-r--r-- | src/Note-taking_with_Vim.adoc | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/src/Note-taking_with_Vim.adoc b/src/Note-taking_with_Vim.adoc new file mode 100644 index 0000000..4aea378 --- /dev/null +++ b/src/Note-taking_with_Vim.adoc @@ -0,0 +1,115 @@ +Note-taking with Vim +==================== +:author: Aaron Ball +:email: nullspoon@iohq.net + + +== {doctitle} + +Two vim posts in one day! + +My task list at work has recently become so large (it's probably well over a +year's worth of work now) that I now need to track my tasks somewhere other +than in my head (documentation is always better than tribal knowledge anyways). +I realy don't like task tracking becuase most of the applications out there are +just so heavy for what note-taking actually is. I use vim almost all day, every +day though, so why not use that (plus it's command line!)? + +I spent about thirty minutes writing this up today. It's inspired a bit by the +LifeHacker article, +http://lifehacker.com/5592047/turn-your-command-line-into-a-fast-and-simple-note+taking-tool[Turn +Your Command Line into a Fast and Simple Note Taking Tool] (thanks +http://mottr.am/[Jack Mottram]). + +This will automagically give all of your notes a .wiki extension, telling vim +to use the mediawiki text syntax highlighter (I use MediaWiki a lot to so I +figured I'd use that syntax for markup). This can be found +http://en.wikipedia.org/wiki/Wikipedia:Text_editor_support#Vim[here]. If you +want to use something else like markdown, just change the $noteExt variable at +the top to the extension associated with the highlighter you want. + +This addition will give you six new commands. + +* +**note** [NoteName]+: Opens a note for editing or creates +a new note. If no note is specified, opens the most recent note. +* +**mknote** NoteName "Note to append"+: Appends text to the +requested note. +* +**catnote** [NoteName]+: Prints the contents of the +specified note. +* +**lsnotes**+: Lists all notes by date modified +* +**findnote** SearchTerm+: Searches all notes for the +search term (case insensitive) and prints the results along with note +title and line number on which the term was found. +* +**mvnote** OldName NewName+: Renames a note +* +**rmnote** NoteName+: Deletes the specified note. + +Add the following to your .bash_profile (or .profile if you're a ksh user) + +---- +export base=~/Documents/Notes +export noteExt=wiki +# This would be used for markdown +# export noteExt=md +note() { + if [ ! -d $base ]; then + mkdir -p $base + fi + # If note not specified, open most recent + if [[ -z "$1" ]]; then + vim $(ls -t $(find $base/ -type f) | head -n 1) + else + vim $base/$1.$noteExt + fi +} + +mknote() { + echo $2 >> $base/$1.$noteExt +} + +catnote() { + # If note not specified, cat most recent + if [[ -z "$1" ]]; then + cat $(ls -t $(find $base/ -type f) | head -n 1) + else + cat $base/$1.$noteExt + fi +} + +lsnotes() { + #ls -1 $base/ | sed "s/\(.*\).$noteExt/* \1/" + echo + echo -e "Last Modified\tName" + ls -lt $base/ | tr -s ' ' | cut -d ' ' -f 6,7,8,9 | sed "s/^\(\w\+\) \(\w\w\) \(\w\w:\w\w\) \(.*\).wiki/\1 \2 \3\t\4/" + echo +} + +findnote() { + if [[ -n "$1" ]]; then + contents="Note:Line:Text\n\n" + contents=$contents$(find $base/ -type f | xargs grep -n -i "$1" | sed "s/.*\/\(.*\)\.$noteExt:\([0-9]\+\):\(.*\)/\1:\2:\3/") + echo -e "$contents" | column -s ":" -t + else + echo "Please specify a search term." + fi +} + +mvnote() { + mv $base/$1.$noteExt ~/Documents/Notes/$2.$noteExt +} + +rmnote() { + if [[ -n "$1" ]]; then + rm $base/$1.$noteExt + else + echo "Please specify a note." + fi +} +---- + + +Category:Linux +Category:Vim +Category:Productivity + + +// vim: set syntax=asciidoc: |