Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Duplicate and move around lines.

branch: master

Fetching latest commit…

Octocat-spinner-32-eaf2f5

Cannot retrieve the latest commit at this time

Octocat-spinner-32 autoload
Octocat-spinner-32 doc
Octocat-spinner-32 plugin
Octocat-spinner-32 README
README
This is a mirror of http://www.vim.org/scripts/script.php?script_id=4140

DESCRIPTION
This plugin offers mappings to quickly duplicate and move lines to above /
below the current line. A [count] either specifies the number of lines, or the
relative visible target line, therefore it's especially easy to clone lines
when 'relativenumber' is set.
The mappings can save you several keystrokes over an explicit dd/
yy[{motion}, ...]p sequence in cases where the other lines are nearby and
visible in the current window.

Oftentimes, duplication in source code is a code smell. Please use this plugin
responsibly ;-)

SEE ALSO
- The swap functionality of the plugin's [E / ]E mappings are also
  available as an Ex :Swap command, provided by the companion
  LineJugglerCommands.vim plugin (vimscript #4465).

RELATED WORKS
- Idea, design and implementation of the [<Space> and [e mappings are based on
  Tim Pope's unimpaired.vim plugin (vimscript #1590). In addition, unimpaired
  provides other, unrelated functionality (all via [... / ]... mappings), but
  doesn't offer customization of the mappings.
- textmanip.vim (vimscript #3491) provides mappings to move and duplicate
  (selected / current) line(s).

USAGE
[<Space>                Add [count] blank lines above the current line / above
                        the start of the selection.
                        In a single-line characterwise-visual selection:
                        Add [count] spaces before the start of the selection.

]<Space>                Add [count] blank lines below the current line / below
                        the end of the selection.
                        In a single-line characterwise-visual selection:
                        Add [count] spaces after the end of the selection.

[e                      Move the current line / selection [count] lines above.

]e                      Move the current line / selection [count] lines below.
                        In a single-line characterwise-visual selection:
                        Move the selected text to the same start column
                        [count] lines above / below (regardless of whether the
                        target line is that long already; missing columns are
                        filled up with spaces).

[E                      Exchange the current line with the line / closed fold
                        [count] lines above.
                        Exchange the current closed fold with the same amount
                        of visible lines as are in the fold, [count] lines
                        above.
{Visual}[E              Exchange the selection with the same amount of visible
                        lines located [count] lines above.
                        In a single-line characterwise-visual selection:
                        Exchange the selected text with the same-sized
                        area [count] lines above.
]E                      Exchange the current line with the line / closed fold
                        [count] lines below.
                        Exchange the current closed fold with the same amount
                        of visible lines as are in the fold, [count] lines
                        below.
{Visual}]E              Exchange the selection with the same amount of visible
                        lines located [count] lines below.
                        In a single-line characterwise-visual selection:
                        Exchange the selected text with the same-sized
                        area [count] lines below.

[d                      Duplicate the current line / selection directly
                        above / across [count] lines above the current line /
                        above the start of the selection.
                        In a single-line characterwise-visual selection:
                        Duplicate before the selection (to [count] characters
                        before the start of the selection).
]d                      Duplicate the current line / selection directly
                        below / across [count] lines below the current line /
                        below the end of the selection.
                        In a single-line characterwise-visual selection:
                        Duplicate after the selection (to [count] characters
                        after the end of the selection).

[D                      Duplicate the current  / [count] lines to above the
                        current line.
{Visual}[D              Duplicate the selection [count] times above the
                        selection.
                        In a single-line characterwise-visual selection:
                        Duplicate before the selection [count] times.
]D                      Duplicate the current  / [count] lines to below that
                        range.
{Visual}]D              Duplicate the selection [count] times below the
                        selection.
                        In a single-line characterwise-visual selection:
                        Duplicate after the selection [count] times.

[f                      Fetch the line [count] visible lines below the current
                        line and duplicate it below the current line.
]f                      Fetch the line [count] visible lines above the current
                        line and duplicate it below the current line.
{Visual}[f              Fetch the same number of visible lines starting from
                        the line [count] lines below the current line and
                        duplicate them above the start of the selection.
{Visual}]f              Fetch the same number of visible lines starting from
                        the line [count] lines above the current line and
                        duplicate them below the end of the selection.

[r                      Fetch the line [count] visible lines below the current
                        line and replace the current line with it.
]r                      Fetch the line [count] visible lines above the current
                        line and replace the current line with it.
{Visual}[r              Replace the selection with the same number of visible
                        lines fetched starting from the line [count] lines
                        below the current line.
{Visual}]r              Replace the selection with the same number of visible
                        lines fetched starting from the line [count] lines
                        above the current line.
                        In a single-line characterwise-visual selection:
                        Replace the selected text with the same-sized
                        area [count] lines below / above.

                        When the cursor is on a closed fold or the selection
                        contains a closed fold, the entire set of folded lines
                        is used. All mappings treat closed folds as a fixed
                        entity, so they will never move / duplicate into a
                        closed fold, always over it.
                        A [count] specifies visible lines, closed folds are
                        counted as one line, so you can use the
                        'relativenumber' column to easily reach a target.
                        (Except for v_[d and v_]d when at the opposite
                        side of the selection.)
Something went wrong with that request. Please try again.