sponsor Vim development Vim logo Vim Book Ad

InsertFromAround : Insert mode mappings to fetch text or indent from surrounding lines.

 script karma  Rating 1/1, Downloaded by 95    Comments, bugs, improvements  Vim wiki

created by
Ingo Karkat
 
script type
utility
 
description
DESCRIPTION
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
current line.

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.

SOURCE
- The i_CTRL-E / i_CTRL-Y mappings are based on
    http://www.ibm.com/developerworks/linux/library/l-vim-script-1/index.html

RELATED WORKS
- The prev_indent plugin (vimscript #4575) provides an insert mode mapping and
  :PrevIndent to move the current line to the previous indentation level.

USAGE
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           Replace the text before the cursor with 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
                        line.

CTRL-G CTRL-T           Insert whitespace so that the text after the cursor
                        aligns with the start of following non-whitespace text
                        (and the end of the text) in the previous unfolded
                        line.

CTRL-G CTRL-V           Insert whitespace so that the text after the cursor
                        aligns with the closest match of the (non-whitespace)
                        character after the cursor found after the cursor
                        column in adjacent unfolded lines.

CTRL-G V{char}          Insert whitespace so that the text after the cursor
                        aligns the next match of {char} in the current line
                        with the closest match of {char} found after that
                        column in adjacent unfolded lines.
                        Note: This won't work correctly when there are <Tab>
                        characters between the cursor and the next match of
                        {char}.
 
install details
INSTALLATION
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.
    vim InsertFromAround*.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.005 or
  higher.

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

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
InsertFromAround-1.10.vmb.gz 1.10 2014-04-03 7.0 Ingo Karkat - ENH: The i_CTRL-G_CTRL-D / i_CTRL-G_CTRL-T mappings also align to non-whitespace text in preceding lines when the line immediately above is shorter than the cursor column.
- Add CTRL-G CTRL-V mapping that aligns to the current character found in adjacent lines.
- Add CTRL-G V{char} mapping that aligns to the queried character.
InsertFromAround-1.00.vmb.gz 1.00 2014-01-23 7.0 Ingo Karkat Initial upload
ip used for rating: 54.197.168.49

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.
   
SourceForge.net Logo