From d43f9c78a942cf3f327192c400624937642d8a40 Mon Sep 17 00:00:00 2001 From: Peter Odding Date: Thu, 1 Dec 2011 21:43:46 +0100 Subject: [PATCH] :TabNoteFromSelectedText and \en, \sn, \tn mappings (:edit, :split, :tabnew) --- README.md | 17 +++++++++++------ autoload/xolox/notes.vim | 4 ++-- doc/notes.txt | 28 +++++++++++++++++++--------- ftplugin/notes.vim | 14 +++++++++++++- plugin/notes.vim | 9 ++++++--- 5 files changed, 51 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 51343c7..fa49d08 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ The notes.vim plug-in for the [Vim text editor] [vim] makes it easy to manage yo * **Starting a new note:** Execute the `:Note` command to create a new buffer and load the appropriate file type and syntax * 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) - * 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) + * 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) * **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) * **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`) * 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 ### The `:NoteFromSelectedText` command -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: - - " Map \ns in visual mode to start new note with selected text as title. - vmap ns :NoteFromSelectedText +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). ### The `:SplitNoteFromSelectedText` command -Same as `:NoteFromSelectedText` but opens the new note in a vertical split window. +Same as `:NoteFromSelectedText` but opens the new note in a vertical split window. The default mapping for this command is `\sn`. + +### The `:TabNoteFromSelectedText` command + +Same as `:NoteFromSelectedText` but opens the new note in a new tab page. The default mapping for this command is `\tn`. ### The `:DeleteNote` command @@ -192,6 +193,9 @@ The following key mappings are defined inside notes. * `Tab` and `Alt-Right` increase indentation of list items (works on the current line and selected lines) * `Shift-Tab` and `Alt-Left` decrease indentation of list items * `Enter` on a line with only a list bullet removes the bullet and starts a new line below the current line + * `\en` executes `:NoteFromSelectedText` + * `\sn` executes `:SplitNoteFromSelectedText` + * `\tn` executes `:TabNoteFromSelectedText` ## Customizing the syntax highlighting of notes @@ -273,6 +277,7 @@ This software is licensed under the [MIT license] [mit]. [gf]: http://vimdoc.sourceforge.net/htmldoc/editing.html#gf [highlight]: http://vimdoc.sourceforge.net/htmldoc/syntax.html#:highlight [levenshtein]: http://en.wikipedia.org/wiki/Levenshtein_distance +[mapleader]: http://vimdoc.sourceforge.net/htmldoc/map.html#mapleader [mit]: http://en.wikipedia.org/wiki/MIT_License [modeline]: http://vimdoc.sourceforge.net/htmldoc/options.html#modeline [python]: http://python.org/ diff --git a/autoload/xolox/notes.vim b/autoload/xolox/notes.vim index c3e4cea..e0befb2 100644 --- a/autoload/xolox/notes.vim +++ b/autoload/xolox/notes.vim @@ -1,12 +1,12 @@ " Vim auto-load script " Author: Peter Odding -" Last Change: November 30, 2011 +" Last Change: December 1, 2011 " URL: http://peterodding.com/code/vim/notes/ " Note: This file is encoded in UTF-8 including a byte order mark so " that Vim loads the script using the right encoding transparently. -let g:xolox#notes#version = '0.16.13' +let g:xolox#notes#version = '0.16.14' let s:scriptdir = expand(':p:h') function! xolox#notes#init() " {{{1 diff --git a/doc/notes.txt b/doc/notes.txt index f725cde..b551d49 100644 --- a/doc/notes.txt +++ b/doc/notes.txt @@ -12,8 +12,8 @@ notes in Vim: it's empty a new note will be created) - 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) + window using the '\en' mapping or |:NoteFromSelectedText| command (there + are similar mappings and commands for opening split windows and tab pages) - Saving notes: Just use Vim's |:write| and |:update| commands, you don't need to provide a filename because it will be set based on the title (first line) @@ -225,18 +225,22 @@ note title and nothing more. The *:NoteFromSelectedText* command 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: -> - " Map \ns in visual mode to start new note with selected text as title. - vmap ns :NoteFromSelectedText +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| variable). ------------------------------------------------------------------------------- The *:SplitNoteFromSelectedText* command Same as |:NoteFromSelectedText| but opens the new note in a vertical split -window. +window. The default mapping for this command is '\sn'. + +------------------------------------------------------------------------------- +The *:TabNoteFromSelectedText* command + +Same as |:NoteFromSelectedText| but opens the new note in a new tab page. The +default mapping for this command is '\tn'. ------------------------------------------------------------------------------- The *:DeleteNote* command @@ -379,6 +383,12 @@ Insert mode mappings ~ - 'Enter' on a line with only a list bullet removes the bullet and starts a new line below the current line + - '\en' executes |:NoteFromSelectedText| + + - '\sn' executes |:SplitNoteFromSelectedText| + + - '\tn' executes |:TabNoteFromSelectedText| + =============================================================================== Customizing the syntax highlighting of notes ~ diff --git a/ftplugin/notes.vim b/ftplugin/notes.vim index d5f3564..d9ba32d 100644 --- a/ftplugin/notes.vim +++ b/ftplugin/notes.vim @@ -1,6 +1,6 @@ " Vim file type plug-in " Author: Peter Odding -" Last Change: November 25, 2011 +" Last Change: December 1, 2011 " URL: http://peterodding.com/code/vim/notes/ if exists('b:did_ftplugin') @@ -113,6 +113,18 @@ let b:undo_ftplugin .= ' | execute "sunmap "' " Automatically remove empty list items on Enter. {{{1 inoremap xolox#notes#cleanup_list() +let b:undo_ftplugin .= ' | execute "iunmap "' + +" Shortcuts to create new notes from the selected text. {{{1 + +vmap en :NoteFromSelectedText +let b:undo_ftplugin .= ' | execute "vunmap en"' + +vmap sn :SplitNoteFromSelectedText +let b:undo_ftplugin .= ' | execute "vunmap sn"' + +vmap tn :TabNoteFromSelectedText +let b:undo_ftplugin .= ' | execute "vunmap tn"' " }}}1 diff --git a/plugin/notes.vim b/plugin/notes.vim index 0cd6e8f..d9875b1 100644 --- a/plugin/notes.vim +++ b/plugin/notes.vim @@ -1,6 +1,6 @@ " Vim plug-in " Author: Peter Odding -" Last Change: November 26, 2011 +" Last Change: November 28, 2011 " URL: http://peterodding.com/code/vim/notes/ " Support for automatic update using the GLVS plug-in. @@ -16,8 +16,6 @@ call xolox#notes#init() " User commands to create, delete and search notes. command! -bar -bang -nargs=? -complete=customlist,xolox#notes#cmd_complete Note call xolox#notes#edit(, ) -command! -bar -bang -range NoteFromSelectedText call xolox#notes#from_selection(, 'edit') -command! -bar -bang -range SplitNoteFromSelectedText call xolox#notes#from_selection(, 'vsplit') command! -bar -bang -nargs=? -complete=customlist,xolox#notes#cmd_complete DeleteNote call xolox#notes#delete(, ) command! -bang -nargs=? -complete=customlist,xolox#notes#keyword_complete SearchNotes call xolox#notes#search(, ) command! -bar -bang RelatedNotes call xolox#notes#related() @@ -25,6 +23,11 @@ command! -bar -bang -nargs=? RecentNotes call xolox#notes#recent(, ) command! -bar IndexTaggedNotes call xolox#notes#tags#create_index() +" TODO Generalize this so we have one command + modifiers (like :tab)? +command! -bar -bang -range NoteFromSelectedText call xolox#notes#from_selection(, 'edit') +command! -bar -bang -range SplitNoteFromSelectedText call xolox#notes#from_selection(, 'vsplit') +command! -bar -bang -range TabNoteFromSelectedText call xolox#notes#from_selection(, 'tabnew') + " Automatic commands to enable the :edit note:… shortcut and load the notes file type. augroup PluginNotes