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 2305  Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
 
script type
utility
 
description
DESCRIPTION
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, there's a direct mapping that lets you recall the [N]'th
previous insertion, one of the last recalls via "{1-9}, or a named insertion
via "{a-zA-Z}. Alternatively, another mapping shows a list of the last 9
insertions, recalled and named ones, and interactively queries one.

To avoid that the many minor tactical edits clobber up the history, only
significant (longer) edits are recalled.

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

USAGE
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.

[N]q<ALT-A>             Recall and append previous [N]'th insertion.
[count]"{1-9}q<ALT-A>   Recall and append the insertion that was recalled last
                        (1), second-to-last (2), etc. [count] times.
[count]"{a-zA-Z}q<ALT-A>
                        Recall and append the insertion named {a-zA-Z} by
                        invoking the q_CTRL-A mapping.

[count]q<CTRL-A>        Lists the last 9 insertions, last 9 recalled
                        insertions, and any named {a-zA-Z} insertions, then
                        prompts to choose one.
                        That chosen insertion is appended [count] times.
[count]"{a-zA-Z}q<CTRL-A>
                        Like above, but name the chosen insertion as {a-zA-Z}
                        for a recall.
 
install details
INSTALLATION
The code is hosted in a Git repo at
    https://github.com/inkarkat/vim-PrevInsertComplete
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.

DEPENDENCIES
- Requires Vim 7.0 or higher.
- Requires the ingo-library.vim plugin (vimscript #4433), version 1.044 or
  higher.
- Requires the CompleteHelper.vim plugin (vimscript #3914), version 1.11 or
  higher.
- repeat.vim (vimscript #2136) plugin (optional)

CONFIGURATION
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.

By default, the named ({a-zA-Z}) and recalled ({1-9}) insertions are
persisted, too. To disable that:
    let g:PrevInsertComplete_PersistNamed = 0
    let g:PrevInsertComplete_PersistRecalled = 0

Insertions are by default inserted at the beginning of the line if the cursor
is in column 1, else appended after the current character. You can change that
behavior via one of the values described at g:IngoLibrary_InsertHereStrategy
put into g:PrevInsertComplete_RecallInsertStrategy.

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-2.00.vmb.gz 2.00 2024-11-12 7.0 Ingo Karkat - CHG: q<C-@> direct recall mapping is broken in GVIM 8.2 (cp. https://github.com/vim/vim/issues/6457#issuecomment-658960270); choose different q<A-a> default to avoid these issues.
- ENH: Allow naming of (important) insertions similar to the built-in registers, and offer a shortlist of the last 9 recalls, too - previous recalls likely get recalled again.
- CHG: Insert recalled insertion before the cursor when on the first column, and allow to tweak that via g:PrevInsertComplete_RecallInsertStrategy. *** You need to update to ingo-library (vimscript #4433) version 1.044! ***
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|
configuration.
PrevInsertComplete-1.00.vmb.gz 1.00 2012-08-22 7.0 Ingo Karkat Initial upload
ip used for rating: 142.132.191.50

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.
   
Vim at Github