Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rename :NewNote to :Note, make it edit existing notes

  • Loading branch information...
commit 8274b26e48212cb75577b3a166afbe12c250d47e 1 parent 94e10b3
@xolox authored
View
30 README.md
@@ -1,30 +1,42 @@
# Easy note taking in Vim
-The `notes.vim` plug-in for the [Vim text editor](http://www.vim.org/) makes it easy to manage your notes in Vim:
+The `notes.vim` plug-in for the [Vim text editor] [vim] makes it easy to manage your notes in Vim:
- * **Starting a new note:** Execute the `:NewNote` command to create a new buffer and load the appropriate file type and syntax
- * **Saving notes:** Just use Vim's [:write](http://vimdoc.sourceforge.net/htmldoc/editing.html#:write) and [:update](http://vimdoc.sourceforge.net/htmldoc/editing.html#:update) commands, you don't need to provide a filename because it will already have been set based on the title (first line) of your note (you also don't need to worry about special characters, they'll be escaped)
+ * **Starting a new note:** Execute the `:Note` command to create a new buffer and load the appropriate file type and syntax
+ * **Editing existing notes:** Execute `:Note keyword` to edit a note containing `keyword` in its title (if no notes are found a new one is created with `anything` as its title)
+ * **Saving notes:** Just use Vim's [:write] [write] and [:update] [update] commands, you don't need to provide a filename because it will already have been set based on the title (first line) of your note (you also don't need to worry about special characters, they'll be escaped)
* **Deleting notes:** The `:DeleteNote` command enables you to delete the current or given note
* **Searching notes:** `:SearchNotes keyword …` searches for keywords and `:SearchNotes /pattern/` searches for regular expressions
* **Back-references:** The `:RelatedNotes` command find all notes referencing the current file
- * A [Python](http://python.org/) script is included that accelerates keyword searches using an [SQLite](http://sqlite.org/) database
- * **Navigating between notes:** The included file type plug-in redefines [gf](http://vimdoc.sourceforge.net/htmldoc/editing.html#gf) to jump between notes and the syntax script highlights note names as hyper links
+ * A [Python] [python] script is included that accelerates keyword searches using an [SQLite] [sqlite] database
+ * **Navigating between notes:** The included file type plug-in redefines [gf] [gf] to jump between notes and the syntax script highlights note names as hyper links
* **Writing aids:** The included file type plug-in contains mappings for automatic curly quotes, arrows and list bullets
* **Embedded file types:** The included syntax script supports embedded highlighting using blocks marked with `{{{type … }}}` which allows you to embed highlighted code and configuration snippets in your notes
-Here's a screen shot of the syntax mode using the [slate](http://code.google.com/p/vim/source/browse/runtime/colors/slate.vim) color scheme:
+Here's a screen shot of the syntax mode using the [slate] [slate] color scheme:
![Syntax mode screen shot](http://peterodding.com/code/vim/notes/syntax.png)
## Install & usage
-Unzip the most recent [ZIP archive](http://peterodding.com/code/vim/downloads/notes) file inside your Vim profile directory (usually this is `~/.vim` on UNIX and `%USERPROFILE%\vimfiles` on Windows), restart Vim and execute the command `:helptags ~/.vim/doc` (use `:helptags ~\vimfiles\doc` instead on Windows). To get started execute `:NewNote` or `:edit note:`.
+Unzip the most recent [ZIP archive] [download] file inside your Vim profile directory (usually this is `~/.vim` on UNIX and `%USERPROFILE%\vimfiles` on Windows), restart Vim and execute the command `:helptags ~/.vim/doc` (use `:helptags ~\vimfiles\doc` instead on Windows). To get started execute `:Note` or `:edit note:`, this will start a new note that contains instructions on how to continue from there (and how to use the plug-in in general).
## Contact
-If you have questions, bug reports, suggestions, etc. the author can be contacted at <peter@peterodding.com>. The latest version is available at <http://peterodding.com/code/vim/notes/> and <http://github.com/xolox/vim-notes>. If you like the script please vote for it on [Vim Online](http://www.vim.org/scripts/script.php?script_id=3375).
+If you have questions, bug reports, suggestions, etc. the author can be contacted at <peter@peterodding.com>. The latest version is available at <http://peterodding.com/code/vim/notes/> and <http://github.com/xolox/vim-notes>. If you like the script please vote for it on [Vim Online] [vim_online].
## License
-This software is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License).
+This software is licensed under the [MIT license] [mit].
© 2010 Peter Odding &lt;<peter@peterodding.com>&gt;.
+
+[vim]: http://www.vim.org/
+[write]: http://vimdoc.sourceforge.net/htmldoc/editing.html#:write
+[update]: http://vimdoc.sourceforge.net/htmldoc/editing.html#:update
+[python]: http://python.org/
+[sqlite]: http://sqlite.org/
+[gf]: http://vimdoc.sourceforge.net/htmldoc/editing.html#gf
+[slate]: http://code.google.com/p/vim/source/browse/runtime/colors/slate.vim
+[download]: http://peterodding.com/code/vim/downloads/notes
+[vim_online]: http://www.vim.org/scripts/script.php?script_id=3375
+mit: http://en.wikipedia.org/wiki/MIT_License
View
119 autoload.vim
@@ -1,6 +1,6 @@
" Vim auto-load script
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: December 28, 2010
+" Last Change: January 7, 2011
" URL: http://peterodding.com/code/vim/notes/
" Note: This file is encoded in UTF-8 including a byte order mark so
@@ -8,20 +8,69 @@
let s:script = expand('<sfile>:p:~')
-function! xolox#notes#new(bang, name) " {{{1
- " Create a new note using the :NewNote command.
- if !s:is_empty_buffer()
- execute 'enew' . a:bang
+function! xolox#notes#shortcut() " {{{1
+ " The "note:" pseudo protocol is just a shortcut for the :Note command.
+ let name = matchstr(expand('<afile>'), 'note:\zs.*')
+ call xolox#notes#edit(v:cmdbang ? '!' : '', name)
+endfunction
+
+function! xolox#notes#edit(bang, title) abort " {{{1
+ " Edit an existing note or create a new one with the :Note command.
+ let starttime = xolox#timer#start()
+ let title = xolox#trim(a:title)
+ if title != ''
+ let fname = xolox#notes#select(title)
+ if fname != ''
+ execute 'edit' . a:bang fnameescape(fname)
+ setlocal filetype=notes
+ call xolox#timer#stop('%s: Opened note in %s.', s:script, starttime)
+ return
+ endif
+ else
+ let title = 'New note'
endif
+ let fname = xolox#notes#title_to_fname(title)
+ execute 'edit' . a:bang fnameescape(fname)
setlocal filetype=notes
- execute 'silent read' fnameescape(xolox#path#merge(g:notes_shadowdir, 'New note'))
- 1delete
- if a:name =~ '\S'
- call setline(1, xolox#trim(a:name))
- else
+ if line('$') == 1 && getline(1) == ''
+ let fname = xolox#path#merge(g:notes_shadowdir, 'New note')
+ execute 'silent read' fnameescape(fname)
+ 1delete
setlocal nomodified
endif
+ if title != 'New note'
+ call setline(1, title)
+ endif
doautocmd BufReadPost
+ call xolox#timer#stop('%s: Started new note in %s.', s:script, starttime)
+endfunction
+
+function! xolox#notes#select(filter) " {{{1
+ " Interactively select an existing note whose title contains {filter}.
+ let notes = {}
+ let filter = xolox#trim(a:filter)
+ for [fname, title] in items(xolox#notes#get_fnames_and_titles())
+ if title ==? filter
+ return fname
+ elseif title =~? filter
+ let notes[fname] = title
+ endif
+ endfor
+ if len(notes) == 1
+ return keys(notes)[0]
+ elseif !empty(notes)
+ let choices = ['Please select a note:']
+ let values = ['']
+ for fname in sort(keys(notes))
+ call add(choices, ' ' . len(choices) . ') ' . notes[fname])
+ call add(values, fname)
+ endfor
+ let choice = inputlist(choices)
+ if choice > 0 && choice < len(choices)
+ return values[choice]
+ endif
+ endif
+ return ''
endfunction
function! xolox#notes#rename() " {{{1
@@ -55,56 +104,6 @@ function! xolox#notes#cleanup() " {{{1
endif
endfunction
-function! xolox#notes#shortcut() " {{{1
- " Edit existing notes using commands such as :edit note:keyword.
- let starttime = xolox#timer#start()
- let notes = {}
- let bang = v:cmdbang ? '!' : ''
- let filename = ''
- let arguments = xolox#trim(matchstr(expand('<afile>'), 'note:\zs.*'))
- if arguments == ''
- call xolox#notes#new(bang, '')
- return
- endif
- for [fname, title] in items(xolox#notes#get_fnames_and_titles())
- " Prefer case insensitive but exact matches.
- if title ==? arguments
- let filename = fname
- break
- elseif title =~? arguments
- " Also check for substring or regex match.
- let notes[title] = fname
- endif
- endfor
- if filename == ''
- if len(notes) == 1
- " Only matched one file using substring or regex match?
- let filename = values(notes)[0]
- elseif !empty(notes)
- " More than one file matched: ask user which to edit.
- let choices = ['Please select a note:']
- let values = ['']
- for title in sort(keys(notes))
- call add(choices, ' ' . len(choices) . ') ' . title)
- call add(values, notes[title])
- endfor
- let choice = inputlist(choices)
- if choice <= 0 || choice >= len(choices)
- " User did not select a valid note.
- return
- endif
- let filename = values[choice]
- endif
- endif
- if empty(filename)
- call xolox#warning("No matching notes!")
- else
- execute 'edit' . bang v:cmdarg fnameescape(filename)
- setlocal filetype=notes
- call xolox#timer#stop('%s: Opened note in %s.', s:script, starttime)
- endif
-endfunction
-
function! xolox#notes#delete(bang) " {{{1
" Delete the current note, close the associated buffer & window.
let filename = expand('%:p')
View
6 notes.vim
@@ -1,9 +1,9 @@
" Vim plug-in
" Author: Peter Odding <peter@peterodding.com>
-" Last Change: December 28, 2010
+" Last Change: January 7, 2011
" URL: http://peterodding.com/code/vim/notes/
" License: MIT
-" Version: 0.7.21
+" Version: 0.8
" Support for automatic update using the GLVS plug-in.
" GetLatestVimScripts: 3375 1 :AutoInstall: session.zip
@@ -37,7 +37,7 @@ if !exists('g:notes_indexscript')
endif
" User commands to create, delete and search notes.
-command! -bar -bang -nargs=? NewNote call xolox#notes#new(<q-bang>, <q-args>)
+command! -bar -bang -nargs=? Note call xolox#notes#edit(<q-bang>, <q-args>)
command! -bar -bang DeleteNote call xolox#notes#delete(<q-bang>)
command! -bar -bang -nargs=1 SearchNotes call xolox#notes#search(<q-bang>, <q-args>)
command! -bar -bang RelatedNotes call xolox#notes#related(<q-bang>)
View
16 shadow-notes/Note taking commands
@@ -6,15 +6,17 @@ title of one of your notes, e.g.:
{{{vim
:edit note:todo
}}}
-When you don’t follow ‘note:’ with anything, the :NewNote command will be
-executed. The following commands can be used to manage your notes:
+When you don’t follow ‘note:’ with anything a new note is created.
+The following commands can be used to manage your notes:
-# :NewNote starts editing a new note
+# :Note starts new notes and edits existing ones
-This command creates a new buffer in the current window, sets the appropriate
-file type and syntax and reads in the new note template. This fails when
-changes have been made to the current buffer, unless you use :NewNote! which
-discards any changes.
+If you don’t pass any arguments to the :Note command it will start editing a
+new note. If you pass (part of) of the title of one of your existing notes that
+note will be edited. If no notes match the given argument then a new note is
+created with its title set to the text you passed to :Note. This command will
+fail when changes have been made to the current buffer, unless you use :Note!
+which discards any changes.
# :DeleteNote deletes the current note
Please sign in to comment.
Something went wrong with that request. Please try again.