Skip to content

Commit d306012

Browse files
committed
Easy customization of new note template (also from command line)
This was added to enable simple integration with tools like sup (https://github.com/ceocoder/sup)
1 parent ed6d6e7 commit d306012

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ This shortcut also works from the command line:
139139

140140
$ gvim note:todo
141141

142-
When you don't follow *note:* with anything a new note is created like when you execute `:Note` without any arguments.
142+
When you don't follow *note:* with anything a new note is created like when you execute `:Note` without any arguments. If the *note:* shortcut is used from the command line, the environment variable `$VIM_NOTES_TEMPLATE` can be set to the filename of a template for new notes (this will override the default template).
143143

144144
### The `:Note` command
145145

autoload/xolox/notes.vim

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
" Note: This file is encoded in UTF-8 including a byte order mark so
77
" that Vim loads the script using the right encoding transparently.
88

9-
let g:xolox#notes#version = '0.30'
9+
let g:xolox#notes#version = '0.31'
1010
let g:xolox#notes#url_pattern = '\<\(mailto:\|javascript:\|\w\{3,}://\)\(\S*\w\)\+/\?'
1111
let s:scriptdir = expand('<sfile>:p:h')
1212

@@ -61,6 +61,15 @@ function! xolox#notes#init() " {{{1
6161
if !exists('g:notes_recentindex')
6262
let g:notes_recentindex = xolox#misc#path#merge(localdir, 'recent.txt')
6363
endif
64+
" Define the default location of the template for new notes.
65+
if !exists('g:notes_new_note_template')
66+
if !empty($VIM_NOTES_TEMPLATE)
67+
" Command line override.
68+
let g:notes_new_note_template = xolox#misc#path#absolute($VIM_NOTES_TEMPLATE)
69+
else
70+
let g:notes_new_note_template = xolox#misc#path#merge(g:notes_shadowdir, 'New note')
71+
endif
72+
endif
6473
" Define the default location of the template for HTML conversion.
6574
if !exists('g:notes_html_template')
6675
let g:notes_html_template = xolox#misc#path#merge(localdir, 'template.html')
@@ -158,8 +167,7 @@ function! xolox#notes#edit(bang, title) abort " {{{1
158167
let fname = xolox#notes#title_to_fname(title)
159168
noautocmd execute 'edit' . a:bang fnameescape(fname)
160169
if line('$') == 1 && getline(1) == ''
161-
let fname = xolox#misc#path#merge(g:notes_shadowdir, 'New note')
162-
execute 'silent read' fnameescape(fname)
170+
execute 'silent read' fnameescape(g:notes_new_note_template)
163171
1delete
164172
if !xolox#notes#unicode_enabled()
165173
call s:transcode_utf8_latin1()

doc/notes.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,9 @@ This shortcut also works from the command line:
347347
$ gvim note:todo
348348
<
349349
When you don't follow _note:_ with anything a new note is created like when you
350-
execute |:Note| without any arguments.
350+
execute |:Note| without any arguments. If the _note:_ shortcut is used from the
351+
command line, the environment variable '$VIM_NOTES_TEMPLATE' can be set to the
352+
filename of a template for new notes (this will override the default template).
351353

352354
-------------------------------------------------------------------------------
353355
The *:Note* command

0 commit comments

Comments
 (0)