sponsor Vim development Vim logo Vim Book Ad

PrevInsertComplete : Recall and insert mode completion for previously inserted text.

 script karma  Rating 5/5, Downloaded by 1893  Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
script type
This plugin lets you quickly recall previous insertions and insert them again
at the cursor position. Essentially, it's the built-in i_CTRL-A command
souped up with history and selection.

In insert mode, you can narrow down the candidates by typing a keyword first;
then, only insertions with a match will be offered as completion candidates.
In normal mode, you can directly recall the [count]'th previous insertion, or
have it list the last 9 insertions and let you choose.
To avoid that the many minor tactical edits clobber up the history, only
significant (longer) edits are recalled.

- Check out the CompleteHelper.vim plugin page (vimscript #3914) for a full
  list of insert mode completions powered by it.

CTRL-X CTRL-A           Find previous insertions (i_CTRL-A, quote.) whose
                        contents match the keyword before the cursor. First, a
                        match at the beginning is tried; if that returns no
                        results, it may match anywhere.
                        Further use of CTRL-X CTRL-A will append insertions done
                        after the previous recall.

[count]q<CTRL-@>        Recall and append previous [count]'th insertion.

[count]q<CTRL-A>        Lists the last 9 insertions, then prompts for a number.
                        The chosen insertion is appended [count] times.
install details
The code is hosted in a Git repo at
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 PrevInsertComplete*.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.015 or
- Requires the CompleteHelper.vim plugin (vimscript #3914), version 1.11 or
- repeat.vim (vimscript #2136) plugin (optional)

For a permanent configuration, put the following commands into your vimrc:

Very short insertions are often just minor corrections and not worthwhile to
recall. The threshold number of inserted characters can be set via:
    let g:PrevInsertComplete_MinLength = 6

The number of recorded insertions can be adjusted.
    let g:PrevInsertComplete_HistorySize = 100

The recorded insertions can be kept and restored across Vim sessions, using
the viminfo file. For this to work, the "!" flag must be part of the
'viminfo' setting:
    set viminfo+=!  " Save and restore global variables.
By default, all recorded insertions are persisted. You can reduce the maximum
number of insertions to be stored via:
    let g:PrevInsertComplete_PersistSize = 10
or completely turn off persistence by setting the variable to 0.

If you want to use different mappings, map your keys to the
<Plug>(PrevInsert...) mapping targets _before_ sourcing the script (e.g. in
your vimrc):
    imap <C-a> <Plug>(PrevInsertComplete)
    nmap <Leader><C-a> <Plug>(PrevInsertRecall)
    nmap <Leader><A-a> <Plug>(PrevInsertList)

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
PrevInsertComplete-1.12.vmb.gz 1.12 2020-12-28 7.0 Ingo Karkat - BUG: "E899: Argument of insert() must be a List or Blob" in PrevInsertComplete#Record#Insertion().
PrevInsertComplete-1.11.vmb.gz 1.11 2013-11-29 7.0 Ingo Karkat - Change qa mapping default to q<C-@>; I found it confusing that I could not record macros into register a any more. To keep the previous mapping, use > :nmap qa <Plug>(PrevInsertRecall)
- Make recall of insertion (q<CTRL-@>, q<CTRL-A>) repeatable.
- Add dependency to ingo-library (vimscript #4433). *** You need to separately install ingo-library (vimscript #4433) version 1.015 (or higher)! ***
PrevInsertComplete-1.10.vmb.gz 1.10 2012-10-15 7.0 Ingo Karkat ENH: Persist recorded insertions across Vim invocations in the |viminfo| file. This can be controlled by the |g:PrevInsertComplete_PersistSize|
PrevInsertComplete-1.00.vmb.gz 1.00 2012-08-22 7.0 Ingo Karkat Initial upload
ip used for rating:

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.