swap : Easy swapping of text
script karma |
Rating 12/7,
Downloaded by 2605 |
Comments, bugs, improvements
|
Vim wiki
|
created by |
Dimitar Dimitrov |
|
script type |
utility |
|
description |
1. Visual mode
1.1 \x
First select some text ([] represents the highlighted area). Then press \x
[a == 123] [ a == 123 ] [a==123]
| | |
V V V
123 == a 123 == a 123==a
Note: Your selection can be loose and include white spaces at both ends.
1.2 \\x
By default the plugin acts on comparison operators
You are however allowed to specify any pivot for the swapping.
First select some text. Then press \\x
You will be asked to give a pattern (% used here)
Just testing % a percentage as a pivot
|
V
a percentage as a pivot % Just testing
1.3
You can also use V, v or ^v to select several lines (v used), then press \x
a == [123
user !~ unknown
0]!=#1
|
V
123 == a
unknown !~ user
1!=#0
--------------------------------------------------
2. Normal mode
Swap with WORD on the right \x
========================
# indicates the cursor position in the examples below.
#
zero one a_longer_word three
|
V
zero a_longer_word one three
Swap with WORD on the left \X
========================
zero one two three
let's have some more fun
# |
V
zero one two let's
three have some more fun
2.1 Repeat
This plugin integrates with Tim Pope's repeat plugin. It means that you can
use . to repeat any normal mode (for now) swap mapping you just used!
For more information see: http://github.com/tpope/vim-repeat
--------------------------------------------------
3. Supported comparison operators
Comparison operators
=== !== <> ==# !=# >#
>=# <# <=# =~# !~# ==?
!=? >? >=? <? <=? =~?
!~? == != >= =~ <=
!~ ~=
Logical operators
&& ||
Assignment operators
+= -= *= /= %= &=
|= ^= <<= >>=
Scope operators
::
Pointer operators
->* -> .*
Bitwise operators
<< >>
Misc operators
> < = + - *
/ % & | ^ .
? : , '= '< '>
!< !>
3.1 Custom operators
You can define your own operators by putting a similar line in your vimrc:
let g:swap_custom_ops = ['first_operator', 'second_operator', ...]
4. Custom mappings
You have the possibility to define your own custom mappings in your .vimrc:
vmap <leader>x <plug>SwapSwapOperands
vmap <leader><leader>x <plug>SwapSwapOperandsPivot
nmap <leader>x <plug>SwapSwapWithR_WORD
nmap <leader>X <plug>SwapSwapWithL_WORD
Note: You can replace \x, \\x, \X with whatever you like. |
|
install details |
swap.vim -> ~/.vim/plugin
swap.txt -> ~/.vim/doc
Latest version at:
https://github.com/kurkale6ka/vim-swap |
|
script versions (upload new version)
Click on the package to download.
swap.zip |
3.3 |
2010-10-06 |
7.0 |
Dimitar Dimitrov |
Made the plugin mappings more flexible: you could redefine them in your .vimrc
but you don't have to |
swap.zip |
3.2 |
2010-10-06 |
7.0 |
Dimitar Dimitrov |
Changed <plug>SwapSwapOperandsPivot to <plug>SwapSwapPivotOperands
because this map name caused <plug>SwapSwapOperands to wait and be very slow! |
swap.zip |
3.1 |
2010-10-06 |
7.0 |
Dimitar Dimitrov |
- Fixed a bug when selection goes beyond $ (using ve=all for instance)
- Made in sort that / history is kept clean (unchanged) after using swap.vim |
swap.zip |
3.0 |
2010-10-05 |
7.0 |
Dimitar Dimitrov |
- Added support for more operators (+ custom ones)
- Added partial support for the repeat.vim plugin
- Allowed all mappings to be customized
- Simplified the code |
swap.zip |
2.1 |
2010-09-25 |
7.0 |
Dimitar Dimitrov |
Changed \<left>x to \X + fixed a bug when trying to swap at BOF or EOF |
swap.zip |
2.0 |
2010-09-24 |
7.0 |
Dimitar Dimitrov |
Swapping of words works a treat now.
Swapping is stricter now, it is only about swapping:
Ex: a== b was transformed to b == a. In the new version it becomes:
b== a
Changed the mappings too: \x, \\x and \<left>x are used now.
think of them as of ^w x in Vim. |
swap.zip |
1.0 |
2010-09-23 |
7.0 |
Dimitar Dimitrov |
Initial upload |
ip used for rating: 142.132.191.50
|