• Stars
    star
    287
  • Rank 139,569 (Top 3 %)
  • Language
    Vim Script
  • Created over 8 years ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Reorder delimited items.

vim-swap

Build Status Build status

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 nth item, u/<C-r> to undo/redo, g/G to group/ungroup items, s/S to sort, r to reverse, and as you know <Esc> 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<Esc>, then swaps the first line and the second line.

bar
foo
baz

Text objects

The following configuration enables text objects to select "swappable" items.

omap i, <Plug>(swap-textobject-i)
xmap i, <Plug>(swap-textobject-i)
omap a, <Plug>(swap-textobject-a)
xmap a, <Plug>(swap-textobject-a)

These text objects work well with [count] prefix.

Demo

swap.vim

More Repositories

1

vim-sandwich

Set of operators and textobjects to search/select/edit sandwiched texts.
Vim Script
1,386
star
2

vim-highlightedyank

Make the yanked region apparent!
Vim Script
831
star
3

vim-columnmove

Move cursor along a column.
Vim Script
53
star
4

vim-textobj-delimited

A textobject plugin to do well with each delimited part of a string.
Vim Script
50
star
5

vim-Verdin

An omni completion function for Vim script
Vim Script
36
star
6

vim-vimhelplint

A lint tool for vim help files.
Vim Script
35
star
7

vim-colorscheme-imas

Vimmerさん!colorschemeですよ、colorscheme!
Vim Script
29
star
8

vim-multiselect

A library plugin to handle multiple visual selections
Vim Script
28
star
9

vim-highlightedundo

Make the undo region apparent!
Vim Script
26
star
10

vim-colorscheme-kemonofriends

ようこそジャパリパークへ!
Vim Script
25
star
11

vim-textobj-functioncall

The vim textobject plugin to treat function-call regions.
Vim Script
22
star
12

asyncomplete-ezfilter.vim

Helper functions to build a custom preprocessor for asyncomplete.vim
Vim Script
18
star
13

vim-colorscheme-tatami

A green colorscheme for Vim text editor.
Vim Script
16
star
14

DoubleExponentialFormulas.jl

One-dimensional numerical integration using the double exponential formula
Julia
16
star
15

vim-masquerade

Tools to edit multiple selections
Vim Script
14
star
16

vim-colorscheme-snowtrek

A light colorscheme for vim text editor
Vim Script
13
star
17

vim-patternjump

Move cursor as you like.
Vim Script
13
star
18

vim-fim

"f" imitated; not improved.
Vim Script
8
star
19

asyncomplete-unicodesymbol.vim

A completion source for asyncomplete.vim to convert a LaTeX-like sequence to a unicode symbol
Vim Script
5
star
20

vim-lsp-julia

The Julia programming language support for vim-lsp using LanguageServer.jl
Vim Script
5
star
21

vim-operator-jerk

Indent inside lines.
Vim Script
4
star
22

vital-Schedule

Handling tasks
Vim Script
4
star
23

vim-colorscheme-reki

A desolate colorscheme for vim.
Vim Script
4
star
24

vim-textobj-char

The vim textobject plugin to select a character.
Vim Script
4
star
25

vimrc

my vimrc
Vim Script
3
star
26

vim-textobj-equation

The vim textobject plugin to selet a equation like text block.
Vim Script
3
star
27

vim-multitarget-gn

Yet another gn command taking a count as a number of operation
Vim Script
2
star
28

vim-scilabcomplete

The omni completion function of scilab for vim.
Vim Script
1
star
29

vim-event-DotCommandPre

Add an autocmd event 'DotCommandPre'
Vim Script
1
star
30

look

I just want to use look command in windows os.
C
1
star
31

vim-colorscheme-franchouchou

よかったい、よかったい
Vim Script
1
star