Skip to content

Commit d43f9c7

Browse files
committed
:TabNoteFromSelectedText and \en, \sn, \tn mappings (:edit, :split, :tabnew)
1 parent 5636ceb commit d43f9c7

File tree

5 files changed

+51
-21
lines changed

5 files changed

+51
-21
lines changed

README.md

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ The notes.vim plug-in for the [Vim text editor] [vim] makes it easy to manage yo
44

55
* **Starting a new note:** Execute the `:Note` command to create a new buffer and load the appropriate file type and syntax
66
* You can also start a note with Vim commands like `:edit`, `:tabedit` and `:split` by starting the filename with `note:`, as in `:edit note:todo` (the part after `note:` doesn't have to be the complete note title and if it's empty a new note will be created)
7-
* You can start a new note with the selected text as title in the current window using the `:NoteFromSelectedText` command (the `:SplitNoteFromSelectedText` command opens the new note in a split window)
7+
* You can start a new note with the selected text as title in the current window using the `\en` mapping or `:NoteFromSelectedText` command (there are similar mappings and commands for opening split windows and tab pages)
88
* **Saving notes:** Just use Vim's [:write] [write] and [:update] [update] commands, you don't need to provide a filename because it will be set based on the title (first line) of your note (you also don't need to worry about special characters, they'll be escaped)
99
* **Editing existing notes:** Execute `:Note anything` to edit a note containing `anything` in its title (if no notes are found a new one is created with its title set to `anything`)
1010
* The `:Note` and `:DeleteNote` commands support tab completion of note titles
@@ -107,14 +107,15 @@ This command will fail when changes have been made to the current buffer, unless
107107

108108
### The `:NoteFromSelectedText` command
109109

110-
Start a new note in the current window with the selected text as the title of the note. The name of this command isn't very well suited to daily use, however the idea is that users will define their own mapping to invoke this command. For example:
111-
112-
" Map \ns in visual mode to start new note with selected text as title.
113-
vmap <Leader>ns :NoteFromSelectedText<CR>
110+
Start a new note in the current window with the selected text as the title of the note. The name of this command isn't very well suited to daily use, that's because it's intended to be executed from a mapping. The default mapping for this command is `\en` (the backslash is actually the character defined by the [mapleader] [mapleader] variable).
114111

115112
### The `:SplitNoteFromSelectedText` command
116113

117-
Same as `:NoteFromSelectedText` but opens the new note in a vertical split window.
114+
Same as `:NoteFromSelectedText` but opens the new note in a vertical split window. The default mapping for this command is `\sn`.
115+
116+
### The `:TabNoteFromSelectedText` command
117+
118+
Same as `:NoteFromSelectedText` but opens the new note in a new tab page. The default mapping for this command is `\tn`.
118119

119120
### The `:DeleteNote` command
120121

@@ -192,6 +193,9 @@ The following key mappings are defined inside notes.
192193
* `Tab` and `Alt-Right` increase indentation of list items (works on the current line and selected lines)
193194
* `Shift-Tab` and `Alt-Left` decrease indentation of list items
194195
* `Enter` on a line with only a list bullet removes the bullet and starts a new line below the current line
196+
* `\en` executes `:NoteFromSelectedText`
197+
* `\sn` executes `:SplitNoteFromSelectedText`
198+
* `\tn` executes `:TabNoteFromSelectedText`
195199

196200
## Customizing the syntax highlighting of notes
197201

@@ -273,6 +277,7 @@ This software is licensed under the [MIT license] [mit].
273277
[gf]: http://vimdoc.sourceforge.net/htmldoc/editing.html#gf
274278
[highlight]: http://vimdoc.sourceforge.net/htmldoc/syntax.html#:highlight
275279
[levenshtein]: http://en.wikipedia.org/wiki/Levenshtein_distance
280+
[mapleader]: http://vimdoc.sourceforge.net/htmldoc/map.html#mapleader
276281
[mit]: http://en.wikipedia.org/wiki/MIT_License
277282
[modeline]: http://vimdoc.sourceforge.net/htmldoc/options.html#modeline
278283
[python]: http://python.org/

autoload/xolox/notes.vim

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
" Vim auto-load script
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: November 30, 2011
3+
" Last Change: December 1, 2011
44
" URL: http://peterodding.com/code/vim/notes/
55

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.16.13'
9+
let g:xolox#notes#version = '0.16.14'
1010
let s:scriptdir = expand('<sfile>:p:h')
1111

1212
function! xolox#notes#init() " {{{1

doc/notes.txt

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ notes in Vim:
1212
it's empty a new note will be created)
1313

1414
- You can start a new note with the selected text as title in the current
15-
window using the |:NoteFromSelectedText| command (the |:SplitNoteFromSelectedText|
16-
command opens the new note in a split window)
15+
window using the '\en' mapping or |:NoteFromSelectedText| command (there
16+
are similar mappings and commands for opening split windows and tab pages)
1717

1818
- Saving notes: Just use Vim's |:write| and |:update| commands, you don't need to
1919
provide a filename because it will be set based on the title (first line)
@@ -225,18 +225,22 @@ note title and nothing more.
225225
The *:NoteFromSelectedText* command
226226

227227
Start a new note in the current window with the selected text as the title of
228-
the note. The name of this command isn't very well suited to daily use,
229-
however the idea is that users will define their own mapping to invoke this
230-
command. For example:
231-
>
232-
" Map \ns in visual mode to start new note with selected text as title.
233-
vmap <Leader>ns :NoteFromSelectedText<CR>
228+
the note. The name of this command isn't very well suited to daily use, that's
229+
because it's intended to be executed from a mapping. The default mapping for
230+
this command is '\en' (the backslash is actually the character defined by the
231+
|mapleader| variable).
234232

235233
-------------------------------------------------------------------------------
236234
The *:SplitNoteFromSelectedText* command
237235

238236
Same as |:NoteFromSelectedText| but opens the new note in a vertical split
239-
window.
237+
window. The default mapping for this command is '\sn'.
238+
239+
-------------------------------------------------------------------------------
240+
The *:TabNoteFromSelectedText* command
241+
242+
Same as |:NoteFromSelectedText| but opens the new note in a new tab page. The
243+
default mapping for this command is '\tn'.
240244

241245
-------------------------------------------------------------------------------
242246
The *:DeleteNote* command
@@ -379,6 +383,12 @@ Insert mode mappings ~
379383
- 'Enter' on a line with only a list bullet removes the bullet and starts a
380384
new line below the current line
381385

386+
- '\en' executes |:NoteFromSelectedText|
387+
388+
- '\sn' executes |:SplitNoteFromSelectedText|
389+
390+
- '\tn' executes |:TabNoteFromSelectedText|
391+
382392
===============================================================================
383393
Customizing the syntax highlighting of notes ~
384394

ftplugin/notes.vim

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim file type plug-in
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: November 25, 2011
3+
" Last Change: December 1, 2011
44
" URL: http://peterodding.com/code/vim/notes/
55

66
if exists('b:did_ftplugin')
@@ -113,6 +113,18 @@ let b:undo_ftplugin .= ' | execute "sunmap <buffer> <A-Left>"'
113113

114114
" Automatically remove empty list items on Enter. {{{1
115115
inoremap <buffer> <silent> <expr> <CR> xolox#notes#cleanup_list()
116+
let b:undo_ftplugin .= ' | execute "iunmap <buffer> <CR>"'
117+
118+
" Shortcuts to create new notes from the selected text. {{{1
119+
120+
vmap <buffer> <silent> <Leader>en :NoteFromSelectedText<CR>
121+
let b:undo_ftplugin .= ' | execute "vunmap <buffer> <Leader>en"'
122+
123+
vmap <buffer> <silent> <Leader>sn :SplitNoteFromSelectedText<CR>
124+
let b:undo_ftplugin .= ' | execute "vunmap <buffer> <Leader>sn"'
125+
126+
vmap <buffer> <silent> <Leader>tn :TabNoteFromSelectedText<CR>
127+
let b:undo_ftplugin .= ' | execute "vunmap <buffer> <Leader>tn"'
116128

117129
" }}}1
118130

plugin/notes.vim

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
" Vim plug-in
22
" Author: Peter Odding <peter@peterodding.com>
3-
" Last Change: November 26, 2011
3+
" Last Change: November 28, 2011
44
" URL: http://peterodding.com/code/vim/notes/
55

66
" Support for automatic update using the GLVS plug-in.
@@ -16,15 +16,18 @@ call xolox#notes#init()
1616

1717
" User commands to create, delete and search notes.
1818
command! -bar -bang -nargs=? -complete=customlist,xolox#notes#cmd_complete Note call xolox#notes#edit(<q-bang>, <q-args>)
19-
command! -bar -bang -range NoteFromSelectedText call xolox#notes#from_selection(<q-bang>, 'edit')
20-
command! -bar -bang -range SplitNoteFromSelectedText call xolox#notes#from_selection(<q-bang>, 'vsplit')
2119
command! -bar -bang -nargs=? -complete=customlist,xolox#notes#cmd_complete DeleteNote call xolox#notes#delete(<q-bang>, <q-args>)
2220
command! -bang -nargs=? -complete=customlist,xolox#notes#keyword_complete SearchNotes call xolox#notes#search(<q-bang>, <q-args>)
2321
command! -bar -bang RelatedNotes call xolox#notes#related(<q-bang>)
2422
command! -bar -bang -nargs=? RecentNotes call xolox#notes#recent(<q-bang>, <q-args>)
2523
command! -bar -count=1 ShowTaggedNotes call xolox#notes#tags#show_tags(<count>)
2624
command! -bar IndexTaggedNotes call xolox#notes#tags#create_index()
2725

26+
" TODO Generalize this so we have one command + modifiers (like :tab)?
27+
command! -bar -bang -range NoteFromSelectedText call xolox#notes#from_selection(<q-bang>, 'edit')
28+
command! -bar -bang -range SplitNoteFromSelectedText call xolox#notes#from_selection(<q-bang>, 'vsplit')
29+
command! -bar -bang -range TabNoteFromSelectedText call xolox#notes#from_selection(<q-bang>, 'tabnew')
30+
2831
" Automatic commands to enable the :edit note:… shortcut and load the notes file type.
2932

3033
augroup PluginNotes

0 commit comments

Comments
 (0)