sponsor Vim development Vim logo Vim Book Ad

sideways.vim : Move function arguments (and other delimited-by-something items) left and right

 script karma  Rating 11/5, Downloaded by 3022  Comments, bugs, improvements  Vim wiki

created by
Andrew Radev
 
script type
utility
 
description
Github project: https://github.com/AndrewRadev/sideways.vim

The plugin defines two commands, ":SidewaysLeft" and ":SidewaysRight", which move the item under the cursor left or right, where an "item" is defined by a delimiter. As an example:

    def function(one, two, three):
        pass

Placing the cursor on "two" and executing `:SidewaysLeft`, the "one" and "two" arguments will switch their places, resulting in this:

    def function(two, one, three):
        pass

In this case, the delimiter is a comma. The plugin currently works with various other cases and it's intended to make the process configurable. While this particular example is in python, this should work for arguments in many different languages that use round braces to denote function calls.

For ruby and eruby, it detects method calls without braces as well:

    link_to user_registration_path, 'Something'
    # changes to:
    link_to 'Something', user_registration_path

Apart from functions, it works for square-bracket lists in dynamic languages:

    list = [one, [two, four, five], three]

Notice that, if you experiment with this example, you'll find that you can move the entire second list around. The plugin takes into consideration nested structures.

It also works for multiline lists. Try experimenting with this example:

    <div class="example"
         style="color: red;"
         something="other">
      Example
    </div>

Apart from functions, it works for a lot of other things, but it's recommended to look at the github project or the help files for additional details. The plugin also provides:

- A text object to change/delete/yank items in lists
- A mapping to add new items forwards or backwards in the list
 
install details
The easiest way to install the plugin is with a plugin manager:

- vim-plug: https://github.com/junegunn/vim-plug
- Vundle:   https://github.com/VundleVim/Vundle.vim

If you use one, just follow the instructions in its documentation.

You can install the plugin yourself using Vim's |packages| functionality by cloning the project (or adding it as a submodule) under `~/.vim/pack/<any-name>/start/`. For example:

    git clone https://github.com/AndrewRadev/sideways.vim ~/.vim/pack/_/start/sideways

This should automatically load the plugin for you on Vim start. Alternatively, you can add it to `~/.vim/pack/<any-name>/opt/` instead and load it in your .vimrc manually with:

    packadd sideways

If you'd rather not use git, you can download the files from this page and unzip them in the relevant directory.
 

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
sideways.zip 0.4.0 2020-08-31 7.0 Andrew Radev - JSX support
- Rust support
- Support for items that span multiple lines
- Mappings for adding new items
- Lots of bugfixes
sideways.zip 0.3.0 2016-07-03 7.0 Andrew Radev - Multiline lists
- Support for handlebars templates
- Various bugfixes
sideways.zip 0.2.0 2015-01-27 7.0 Andrew Radev - Coffeescript methods
- Ruby methods in haml
- Haml classes
- HTML attributes
- Various bugfixes
sideways.zip 0.1.0 2014-01-18 7.0 Andrew Radev - Ruby methods without brackets
- Go lists
- Argument text object
- Various bugfixes
sideways.zip 0.0.2 2012-10-06 7.0 Andrew Radev - Single-line CSS declarations
- Various bugfixes and refactoring
sideways.zip 0.0.1 2012-08-15 7.0 Andrew Radev Initial upload
ip used for rating: 18.97.14.85

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