Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/machakann/vim-swap
Reorder delimited items.
https://github.com/machakann/vim-swap
Last synced: 1 day ago
JSON representation
Reorder delimited items.
- Host: GitHub
- URL: https://github.com/machakann/vim-swap
- Owner: machakann
- Created: 2016-01-26T11:22:01.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2023-08-26T17:52:14.000Z (over 1 year ago)
- Last Synced: 2024-11-18T02:16:20.583Z (2 months ago)
- Language: Vim script
- Size: 302 KB
- Stars: 305
- Watchers: 6
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
vim-swap
============
[![Build Status](https://travis-ci.org/machakann/vim-swap.svg?branch=master)](https://travis-ci.org/machakann/vim-swap)
[![Build status](https://ci.appveyor.com/api/projects/status/iirgmyseg2f9xam9/branch/master?svg=true)](https://ci.appveyor.com/project/machakann/vim-swap/branch/master)A Vim text editor plugin to swap delimited items.
# What for?
Sometimes I want to reorder arguments of a function:```
call func(arg1, arg2, arg3)
```Indeed, it is not difficult to swap `arg2` and `arg3`. Just cutting `, arg2` and pasting it following `arg3`. However it is annoying to swap `arg1` and `arg3` because no way to avoid repeating cut&paste. Anyway I feel bothering in both cases. It should be automated such an boring processes!
# How to use
This plugin defines three key mappings by default, **g<**, **g>**, **gs**. These all functions can be repeated by dot command.## g<
**g<** swaps the item under the cursor with the former item. Moving cursor on the `arg2` and pressing **g<**, then it swaps `arg2` and the former one, `arg1`, to get:```
call foo(arg2, arg1, arg3)
```## g>
**g>** swaps the item under the cursor with the latter item. Moving cursor on the `arg2` and pressing **g>**, then it swaps `arg2` and the latter one, `arg3`, to get:
```
call foo(arg1, arg3, arg2)
```## gs
**gs** works more interactive. It starts "swap mode", as if there was the sub-mode of vim editor. In the mode, use **h**/**l** to swap items, **j**/**k** to choose item, numbers **1** ~ **9** to select **n**th item, **u**/**\** to undo/redo, **g**/**G** to [group/ungroup items](https://imgur.com/kPJui7J.gif), **s**/**S** to [sort](https://imgur.com/TuzzV7d.gif), **r** to [reverse](https://imgur.com/WXOOPCW.gif), and as you know **\** to exit "swap mode". **gs** function can be used also in visual mode. In linewise-visual and blockwise-visual mode, this plugin always swaps in each line. For example, assume that the three lines were in a buffer:```
foo
bar
baz
```Select the three lines and press **gsl\**, then swaps the first line and the second line.
```
bar
foo
baz
```# Text objects
The following configuration enables text objects to select "swappable" items.
```vim
omap i, (swap-textobject-i)
xmap i, (swap-textobject-i)
omap a, (swap-textobject-a)
xmap a, (swap-textobject-a)
```These text objects work well with `[count]` prefix.
# Demo
![swap.vim](http://art9.photozou.jp/pub/986/3080986/photo/232868997_org.v1453815504.gif)