InsertFromAround : Insert mode mappings to fetch text or indent from surrounding lines.
| script karma
Downloaded by 34
Comments, bugs, improvements
script versions (upload new version)
With the proper indent settings, Vim will mostly supply the correct amount of
indent when creating new lines. But sometimes, one needs a special amount of
indent, and it is cumbersome to manually create that by repeatedly pressing
<Tab>, <Space>, and <BS>.
This plugin defines insert mode mappings that indent a new line exactly at the
current cursor position, or insert the indent used in adjacent lines, or align
the text to the right of the cursor to text fragments in surrounding lines.
To duplicate the text of adjacent lines, Vim has the i_CTRL-E / i_CTRL-Y
commands. But these only work character for character (which makes it slow to
copy longer fragments), and fail when empty / shorter lines surround the
This plugin supercharges these commands, making them look beyond the immediate
lines. With a separate mapping, the scope of completion can be toggled between
single characters and whole words, speeding up larger text grabs while still
allowing the fine-grained completion.
- The i_CTRL-E / i_CTRL-Y mappings are based on
- The prev_indent plugin (vimscript #4575) provides an insert mode mapping and
:PrevIndent to move the current line to the previous indentation level.
CTRL-Enter Insert newline and indent the new line to the current
cursor column. This takes into account indent-
expressions and insertion of the comment leader.
CTRL-E / CTRL-Y Insert the character from unfolded lines below / above
the cursor; if the adjacent line is not that long,
look beyond. The command beeps and suspends insert
once if the current target line has been exhausted.
CTRL-G CTRL-E / CTRL-G CTRL-Y
Insert an entire word from unfolded lines below /
above the cursor and toggle the behavior of i_CTRL-E
/ i_CTRL-Y to continue inserting words. The behavior
reverts itself when inserting in another line or by
using this mapping a second time.
CTRL-G CTRL-U Insert the indent from the next nearby unfolded line
that has at least as much indent as the current cursor
position. If the indent before and after the current
line differs, the smaller amount is inserted; repeat
the mapping to get the larger amount.
(Mnemonic: Undo the effect of i_CTRL-U.)
CTRL-G CTRL-D Remove whitespace before the cursor so that the
current cursor position aligns with the start of
preceding non-whitespace text in the previous unfolded
CTRL-G CTRL-T Insert whitespace so that the text after the cursor
aligns with the start of following non-whitespace text
in the previous unfolded line.
This script is 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.
To uninstall, use the :RmVimball command.
- Requires Vim 7.0 or higher.
- Requires the ingo-library.vim plugin (vimscript #4433), version 1.005 or
For a permanent configuration, put the following commands into your vimrc:
If you want to use different mappings, map your keys to the
<Plug>(InsertFrom...) mapping targets _before_ sourcing the script
(e.g. in your vimrc):
imap <C-CR> <Plug>(InsertFromEnterAndIndent)
imap <C-e> <Plug>(InsertFromTextBelow)
imap <C-y> <Plug>(InsertFromTextAbove)
imap <C-g><C-e> <Plug>(InsertFromTextBelowToggle)
imap <C-g><C-y> <Plug>(InsertFromTextAboveToggle)
imap <C-g><C-u> <Plug>(InsertFromIndent)
imap <C-g><C-d> <Plug>(InsertFromAlignToPrevious)
imap <C-g><C-t> <Plug>(InsertFromAlignToNext)
Click on the package to download.
ip used for rating: 188.8.131.52