blob: 4aea378e8fb2eab8ab7db5c82799fa25c226963f (
plain)
1 Note-taking with Vim
2 ====================
3 :author: Aaron Ball
4 :email: nullspoon@iohq.net
5
6
7 == {doctitle}
8
9 Two vim posts in one day!
10
11 My task list at work has recently become so large (it's probably well over a
12 year's worth of work now) that I now need to track my tasks somewhere other
13 than in my head (documentation is always better than tribal knowledge anyways).
14 I realy don't like task tracking becuase most of the applications out there are
15 just so heavy for what note-taking actually is. I use vim almost all day, every
16 day though, so why not use that (plus it's command line!)?
17
18 I spent about thirty minutes writing this up today. It's inspired a bit by the
19 LifeHacker article,
20 http://lifehacker.com/5592047/turn-your-command-line-into-a-fast-and-simple-note+taking-tool[Turn
21 Your Command Line into a Fast and Simple Note Taking Tool] (thanks
22 http://mottr.am/[Jack Mottram]).
23
24 This will automagically give all of your notes a .wiki extension, telling vim
25 to use the mediawiki text syntax highlighter (I use MediaWiki a lot to so I
26 figured I'd use that syntax for markup). This can be found
27 http://en.wikipedia.org/wiki/Wikipedia:Text_editor_support#Vim[here]. If you
28 want to use something else like markdown, just change the $noteExt variable at
29 the top to the extension associated with the highlighter you want.
30
31 This addition will give you six new commands.
32
33 * +**note** [NoteName]+: Opens a note for editing or creates
34 a new note. If no note is specified, opens the most recent note.
35 * +**mknote** NoteName "Note to append"+: Appends text to the
36 requested note.
37 * +**catnote** [NoteName]+: Prints the contents of the
38 specified note.
39 * +**lsnotes**+: Lists all notes by date modified
40 * +**findnote** SearchTerm+: Searches all notes for the
41 search term (case insensitive) and prints the results along with note
42 title and line number on which the term was found.
43 * +**mvnote** OldName NewName+: Renames a note
44 * +**rmnote** NoteName+: Deletes the specified note.
45
46 Add the following to your .bash_profile (or .profile if you're a ksh user)
47
48 ----
49 export base=~/Documents/Notes
50 export noteExt=wiki
51 # This would be used for markdown
52 # export noteExt=md
53 note() {
54 if [ ! -d $base ]; then
55 mkdir -p $base
56 fi
57 # If note not specified, open most recent
58 if [[ -z "$1" ]]; then
59 vim $(ls -t $(find $base/ -type f) | head -n 1)
60 else
61 vim $base/$1.$noteExt
62 fi
63 }
64
65 mknote() {
66 echo $2 >> $base/$1.$noteExt
67 }
68
69 catnote() {
70 # If note not specified, cat most recent
71 if [[ -z "$1" ]]; then
72 cat $(ls -t $(find $base/ -type f) | head -n 1)
73 else
74 cat $base/$1.$noteExt
75 fi
76 }
77
78 lsnotes() {
79 #ls -1 $base/ | sed "s/\(.*\).$noteExt/* \1/"
80 echo
81 echo -e "Last Modified\tName"
82 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/"
83 echo
84 }
85
86 findnote() {
87 if [[ -n "$1" ]]; then
88 contents="Note:Line:Text\n\n"
89 contents=$contents$(find $base/ -type f | xargs grep -n -i "$1" | sed "s/.*\/\(.*\)\.$noteExt:\([0-9]\+\):\(.*\)/\1:\2:\3/")
90 echo -e "$contents" | column -s ":" -t
91 else
92 echo "Please specify a search term."
93 fi
94 }
95
96 mvnote() {
97 mv $base/$1.$noteExt ~/Documents/Notes/$2.$noteExt
98 }
99
100 rmnote() {
101 if [[ -n "$1" ]]; then
102 rm $base/$1.$noteExt
103 else
104 echo "Please specify a note."
105 fi
106 }
107 ----
108
109
110 Category:Linux
111 Category:Vim
112 Category:Productivity
113
114
115 // vim: set syntax=asciidoc:
|