Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Vim plugin to automatically rewrap argument lists to multiple 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 README.rst
README.rst

ArgumentRewrap for VIM

About

ArgumentRewrap is a plugin for the VIM editor to split arbitrary calls with multiple arguments into multiple lines.

Examples

Think of a function call like this one:

foo( bar, baz, blub );

Calling ArgumentRewrap on this function will split it into multiple lines with correct indentation:

foo(
    bar,
    baz,
    blub
);

In a real world scenario you will most likely have to handle more complex arguments, which might contain comma separated lists themselves:

foo( [1,2,3], {a:"A", b:"B", c:"C"}, bar( some, other, function ) );

ArgumentWrap handles nested elements correctly and only rewraps the top level:

foo(
    [1,2,3],
    {a:"A", b:"B", c:"C"},
    bar( some, other, function )
);

If you want to rewrap nested elements simply select the corresponding line with the cursor and rerun the ArgumentWrap function:

foo(
    [1,2,3],
    {
        a:"A",
        b:"B",
        c:"C"
    },
    bar(
        some,
        other,
        function
    )
);

The plugin function scans for the first occurrence of an opening parenthesis "(", "[" and "{" which is followed by a comma. Therefore it is possible to split entries with parenthesis preceding the actual argument list:

foo["bar"] = someFunction( [1,2,3], arg2, arg3, arg4 );

The first brackets used for array access ["bar"] are ignored, as they do not contain a comma separated argument list:

foo["bar"] = someFunction(
    [1,2,3],
    arg2,
    arg3,
    arg4
);

Installation

Installing this plugin is realized by simply copying its files into the equally named folders inside your .vim directory. If you are using Pathogen just copy the folders of this plugin to a directory inside your bundle directory.

Keybinding

To simplify usage, you should bind a key to the argumentrewrap#RewrapArguments function. As an example:

nnoremap <silent> <leader>s :call argumentrewrap#RewrapArguments()<CR>

would bind to <leader>s.

Something went wrong with that request. Please try again.