

Github GitHub - machakann/vim-swap: Reorder delimited items.
source link: https://github.com/machakann/vim-swap
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

vim-swap
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 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.
Recommend
-
57
vim-highlightedyank Make the yanked region apparent! Usage If you are using Vim 8.0.1394 (or later version), there is no need for configuration, as the highlight event is automatically triggered by the TextY...
-
52
vim-sandwich sandwich.vim is a set of operator and textobject plugins to add/delete/replace surroundings of a sandwiched textobject, like (foo), "bar". Quick start Press
-
116
GitHub is where people build software. More than 28 million people use GitHub to discover, fork, and contribute to over 80 million projects.
-
63
README.md evil-args Motions and text objects for delimited arguments in Evil, the extensible vi layer for Emacs. Setup Installing from...
-
32
GitHub is where people build software. More than 28 million people use GitHub to discover, fork, and contribute to over 85 million projects.
-
51
README.md Parse CSV with JavaScript Papa Parse is the fastest in-browser CSV (or delimited tex...
-
14
Kicking the habit of WM_CONCAT for a delimited list of rows, with LISTAGG Posted on May 2...
-
50
Drag and Drop Reorder Images in CodeIgniter The draggable feature is very useful to integrate Drag and Drop functionality in the web application. jQuery UI provides an easy way to enable the draggable feature on a...
-
5
Listview React native expo module to create a list that you can drag and reorder items ...
-
11
JVM continuations This library is yet another implementation of delimited continuations for JVM using bytecode instrumentation. It primarily implements resumable exceptions. And there is also a classical multi-prompt delimited continuatio...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK