Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Fetching contributors…
Cannot retrieve contributors at this time
98 lines (80 sloc) 3.87 KB
" Vim plug-in
" Author: Peter Odding <>
" Last Change: September 4, 2011
" URL:
" Support for automatic update using the GLVS plug-in.
" GetLatestVimScripts: 3375 1 :AutoInstall:
" Don't source the plug-in when it's already been loaded or &compatible is set.
if &cp || exists('g:loaded_notes')
" Make sure the default paths below are compatible with Pathogen.
let s:plugindir = expand('<sfile>:p:h') . '/../misc/notes'
" Define the default location where the user's notes are saved?
if !exists('g:notes_directory')
let g:notes_directory = s:plugindir . '/user'
" Define the default location of the shadow directory with predefined notes?
if !exists('g:notes_shadowdir')
let g:notes_shadowdir = s:plugindir . '/shadow'
" Define the default location for the full text index.
if !exists('g:notes_indexfile')
let g:notes_indexfile = s:plugindir . '/index.sqlite3'
" Define the default location for the keyword scanner script.
if !exists('g:notes_indexscript')
let g:notes_indexscript = s:plugindir . '/'
" Define the default suffix for note filenames.
if !exists('g:notes_suffix')
let g:notes_suffix = ''
" Define the default location for the tag name index (used for completion).
if !exists('g:notes_tagsindex')
let g:notes_tagsindex = s:plugindir . '/tags.txt'
" User commands to create, delete and search notes.
command! -bar -bang -nargs=? -complete=customlist,xolox#notes#cmd_complete Note call xolox#notes#edit(<q-bang>, <q-args>)
command! -bar -bang -range NoteFromSelectedText call xolox#notes#from_selection(<q-bang>)
command! -bar -bang DeleteNote call xolox#notes#delete(<q-bang>)
command! -bang -nargs=? SearchNotes call xolox#notes#search(<q-bang>, <q-args>)
command! -bar -bang RelatedNotes call xolox#notes#related(<q-bang>)
command! -bar -bang -nargs=? RecentNotes call xolox#notes#recent(<q-bang>, <q-args>)
command! -bar -bang IndexTaggedNotes call xolox#notes#index_tagged_notes(<q-bang> == '!')
" Automatic commands to enable the :edit note:… shortcut and load the notes file type.
function! s:DAC(events, directory, command)
" Define automatic command for {events} in {directory} with {command}.
" Resolve the path to the directory with notes so that the automatic command
" also applies to symbolic links pointing to notes (Vim matches filename
" patterns in automatic commands after resolving filenames).
let directory = xolox#misc#path#absolute(a:directory)
" On Windows we have to replace backslashes with forward slashes.
if xolox#misc#os#is_win()
let directory = substitute(directory, '\\', '/', 'g')
let pattern = fnameescape(directory) . '/*'
" On Windows the pattern won't match if it contains repeating slashes.
let pattern = substitute(pattern, '/\+', '/', 'g')
execute 'autocmd' a:events pattern a:command
augroup PluginNotes
" NB: "nested" is used here so that SwapExists automatic commands apply
" to notes (which is IMHO better than always showing the E325 prompt).
au BufReadCmd note:* nested call xolox#notes#shortcut()
call s:DAC('BufReadCmd', g:notes_shadowdir, 'call xolox#notes#edit_shadow()')
call s:DAC('BufWriteCmd', g:notes_directory, 'call xolox#notes#save()')
au SwapExists * call xolox#notes#swaphack()
au WinEnter * if &ft == 'notes' | call xolox#notes#highlight_names(0) | endif
au BufReadPost * if &ft == 'notes' | unlet! b:notes_names_last_highlighted | endif
au BufUnload * if &ft == 'notes' | call xolox#notes#unload_from_cache() | endif
augroup END
augroup filetypedetect
call s:DAC('BufNewFile,BufRead', g:notes_directory, 'if &bt == "" | setl ft=notes | endif')
call s:DAC('BufNewFile,BufRead', g:notes_shadowdir, 'if &bt == "" | setl ft=notes | endif')
augroup END
delfunction s:DAC
" Make sure the plug-in is only loaded once.
let g:loaded_notes = 1
" vim: ts=2 sw=2 et
Jump to Line
Something went wrong with that request. Please try again.