by Ingo Karkat
This plugin automatically persists (parts of) buffers used for the editing of commit (or other) messages, where Vim is invoked as the editor from an external tool. In these buffers, it sets up mappings and commands to iterate through stored past messages, and recall the contents for use in the currently edited message. This way, you automatically collect a history of (committed or aborted) past messages, and can quickly base your current message on contents recalled from that history.
This plugin is used by:
- VcsMessageRecall.vim (vimscript #4117): Browse and re-insert previous VCS commit messages.
The plugin is completely inactive until you set it up for a particular
buffer through the following function; you'll find the details directly in the
.vim/autoload/MessageRecall.vim implementation file.
MessageRecall#Setup( messageStoreDirspec, ... )
After setup, the following mappings and commands are available in the current
message buffer:
CTRL-P, CTRL-N When the buffer has had no changes yet: Replace with a
[count]'th previous / next stored message.
When the buffer has been modified: Open the [count]'th
previous / first stored message in the preview window.
When the buffer is modified and a stored message has
already been inserted: Replace it with the [count]'th
previous / next stored message there.
:[count]MessageView View the [count]'th previous stored message in the
preview-window.
:MessageView {message}|{filespec}
View {message} (auto-completed from the message store
directory) or any arbitrary {filespec} contents
in the preview-window.
:[count]MessageRecall[!]
Insert the [count]'th previous stored message below
the current line.
:MessageRecall[!] {message}|{filespec}
Insert {message} (auto-completed from the message
store directory) or any arbitrary {filespec} contents
below the current line.
When the existing message consists of just empty (or
ignored boilerplate) lines (originating from the
message template that the tool invoking Vim has put
there), the inserted message replaces those empty
lines.
With [!]: Replace an existing message with the
inserted one.
:[range]MessageWrite Persist the current message / specified lines in
[range]; normally, this is done automatically when Vim
is done editing the buffer, but it can be useful to
store an intermediate state (e.g. before a complete
rewrite or before aborting the current edit).
CTRL-P, CTRL-N Go to the previous / next stored message.
:MessageRecall Insert the previewed stored message below the current
line in the buffer from which the message preview was
opened.
:[N]MessageList Show all / the last [N] messages in the
location-list-window; most recent first. (So the
line number directly corresponds to {count} in
:{count}MessageRecall.)
:[N]MessageGrep [arguments]
Search for [arguments] in all / the last [N] stored
messages, and set the location-list to the matches.
:[N]MessageVimGrep [/]{pattern}[/]
Search for {pattern} in all / the last [N] stored
messages, and set the location-list to the matches.
:MessageStore[!] {dirspec}| {identifier}|N
Add the directory {dirspec} as a source (with [!]: set
as the sole source) for recalled messages.
If message stores have been preconfigured (cp.
g:MessageRecall_ConfiguredMessageStores), these can
be referenced via their short {identifier} instead, or
by the N'th last accessed message store .
:MessageStore List all message store directories for the current
buffer.
:[N]MessagePrune[!] Remove all / the oldest [N] messages from the message
store, with [!] without confirmation.
:MessagePrune[!] {fileglob}
Remove all files matching {fileglob} from the message
store, with [!] without confirmation.
The code is hosted in a Git repo at https://github.com/inkarkat/vim-MessageRecall You can use your favorite plugin manager, or "git clone" into a directory used for Vim packages. Releases are on the "stable" branch, the latest unstable development snapshot on "master".
This script is also packaged as a vimball. If you have the "gunzip" decompressor in your PATH, simply edit the *.vmb.gz package in Vim; otherwise, decompress the archive first, e.g. using WinZip. Inside Vim, install by sourcing the vimball or via the :UseVimball command.
vim MessageRecall*.vmb.gz
:so %
To uninstall, use the :RmVimball command.
- Requires Vim 7.0 or higher.
- Requires the ingo-library.vim plugin (vimscript #4433), version 1.043 or higher.
- Requires the BufferPersist.vim plugin (vimscript #4115), version 1.11 or higher.
For a permanent configuration, put the following commands into your vimrc:
When you have multiple, related repositories, you may wish to recall messages from other message stores. Though this is possible via :MessageRecall path/to/other/message-store, it is tedious, and you cannot browse / preview them as easily as the ones from the current message store. For this, you can define additional message stores via:
let b:MessageRecall_MessageStores = ['', 'path/to/other/message-store']
The empty string stands for the current message store; by omitting it, its messages won't be offered any more. Note that this only affects recall and preview; the edited messages are still exclusively persisted to the current message store.
If you don't want to directly add more message stores, but enable the user to quickly do so, you can configure additional message stores together with short identifying names:
let g:MessageRecall_ConfiguredMessageStores = {
\ 'repo1': '/path/to/repo1/.svn/commit-msgs',
\ 'repo2': '/path/to/repo2/.git/commit-msgs',
\]
If you want to use different mappings, first disable the default key mappings in your vimrc:
map <Plug>DisableMessageRecallPreviewPrev <Plug>(MessageRecallPreviewPrev)
map <Plug>DisableMessageRecallPreviewNext <Plug>(MessageRecallPreviewNext)
map <Plug>DisableMessageRecallGoPrev <Plug>(MessageRecallGoPrev)
map <Plug>DisableMessageRecallGoNext <Plug>(MessageRecallGoNext)
Since there's no common filetype for this plugin, User events are fired for each message buffer. You can hook into these events to define alternative mappings:
autocmd User MessageRecallBuffer map <buffer> <Leader>P <Plug>(MessageRecallGoPrev)
autocmd User MessageRecallBuffer map <buffer> <Leader>N <Plug>(MessageRecallGoNext)
autocmd User MessageRecallPreview map <buffer> <Leader>P <Plug>(MessageRecallPreviewPrev)
autocmd User MessageRecallPreview map <buffer> <Leader>N <Plug>(MessageRecallPreviewNext)
Report any bugs, send patches, or suggest features via the issue tracker at https://github.com/inkarkat/vim-MessageRecall/issues or email (address below).
- ENH: Enable support for excluding Git message trailers (and similar): a:options.range can also be a List of range expressions; the first matching range will be used. A range of a single empty line will not be deleted.
You need to update to BufferPersist.vim (vimscript #4115) version 1.11!
- ENH: Add a:options.subDirForUserProvidedDirspec so that the user can pass the base directory instead of remembering where exactly the messages are stored internally.
- ENH: Add a:options.ignorePattern to be able to skip persisting boilerplate messages and discard and replace them with a recalled message instead of opening in the preview window. Useful e.g. for "Merge branch 'foo'".
- BUG: Need to escape more arguments in the defined mappings.
- ENH: Add a:options.replacedMessageRegister to save the original edited message when it is replaced (via :MessageRecall! or when it matches a:options.ignorePattern).
- ENH: Define :MessageWrite command to store an intermediate message state on demand.
You need to update to BufferPersist.vim (vimscript #4115) version 1.10 to get that!
- Don't add the range to the search history (if it consists of a :/{pattern}/).
You need to update to ingo-library (vimscript #4433) version 1.043!
- ENH: Sort the :MessageStore completion candidates for configured message stores by last modification time (instead of alphabetically by identifier), so stores that were recently updated come first.
- ENH: Allow :MessageStore referencing via N count of configured stores, too.
- ENH: Add :MessageList, :MessageGrep, and :MessageVimGrep commands.
- ENH: Add :MessagePrune.
- Refactoring.
You need to update to ingo-library (vimscript #4433) version 1.023!
- ENH: For :MessageRecall command completion, return the messages from other message stores also in reverse order, so that the latest one comes first.
- ENH: Allow to override / extend the message store(s) via b:MessageRecall_MessageStores configuration.
- Get rid of the dependency to the EditSimilar.vim plugin.
- ENH: Add :MessageStore command that allows to add / replace message stores. Presets can be configured via the new b:MessageRecall_ConfiguredMessageStores variable.
- Use ingo#compat#glob() and ingo#compat#globpath().
You need to update to ingo-library (vimscript #4433) version 1.022! The dependency to the EditSimilar.vim plugin has been dropped.
- Adapt to changed EditSimilar.vim interface that returns the success status now. Abort on error for own plugin commands.
You need to update to EditSimilar.vim (vimscript #2544) version 2.40!
- CHG: Only replace on <C-p> / <C-n> in the message buffer when the considered range is just empty lines. I came to dislike the previous replacement also when the message had been persisted.
- CHG: On <C-p> / <C-n> in the original message buffer: When the buffer is modified and a stored message is already being previewed, change the semantics of count to be interpreted relative to the currently previewed stored message. Beforehand, one had to use increasing <C-p>, 2<C-p>, 3<C-p>, etc. to iterate through stored messages (or go to the preview window and invoke the mapping there).
- ENH: Allow to override the default <C-p> / <C-n> mappings.
- Add dependency to ingo-library (vimscript #4433).
You need to separately install ingo-library (vimscript #4433) version 1.012 (or higher)!
- BUG: Script error E486 when replacing a non-matching commit message buffer.
- First published version.
- Started development.
Copyright: (C) 2012-2025 Ingo Karkat - The VIM LICENSE applies to this plugin.
Maintainer: Ingo Karkat <ingo@karkat.de>