sponsor Vim development Vim logo Vim Book Ad

SwapIt : Extensible keyword swapper (turn yes to no, True to False and more)

 script karma  Rating 64/23, Downloaded by 3640  Comments, bugs, improvements  Vim wiki

created by
Michael Brown
 
script type
utility
 
description
swapit.vim is a vim plugin designed to make repetitive changes easier.

On a current word that is a member of a swap list use the
incrementor/decrementor keys (:he ctrl-a,ctrl-x). The script
will cycle through a list of related options.

A quick tty example is here http://ttyshare.com/rec/michael/76068689/

Swapit now offers omnicomplete based swapping on css files!
Css example plugging into omnicomplete http://ttyshare.com/rec/michael/76409608/

The repository is here http://github.com/mjbrownie/swapit/tree/master. Any list submissions would be appreciated.

The idea is to compile a list of common property swaps for various languages/frameworks

NOTE: This has been done before in a simpler vimscript#1676 script. This script differs in it's ability to handle phrase swapping eg 'int' to 'unsigned int'. It is also FileType aware.

eg. 1. Boolean

foo=true

in normal mode, pressing ctrl-a on the t will make it

foo=false

eg. 2. Multi Word Swaps.

Hello World! is a test multi word swap.

on 'Hello World!' go select in visual (vi'<ctrl-a>) to get

'GoodBye Cruel World!'

eg 3. Defining custom swaps

A custom list is defined as follows.

:SwapList datatypes bool char int float double

The first argument is the list name and following args
are members of the list.

if there is no match then the regular incrementor decrementor
function will work on numbers

At the bottom of the script I've added some generic stuff but

You can create a custom swap file for file types at

~/.vim/after/ftplugins/<filetype>_swapit.vim
with custom execs eg.
exec "SwapList function_scope private protected public"

For this alpha version multi word swap list is a bit trickier
to to define. You can add to the swap list directly using
vimscript within a after/ftplugin/<ft>_swap.vim file

call extend(g:swap_lists, [{'name':'Multi Word Example',
             \'options': ['swap with spaces',
             \'swap with  @#$@# chars in it' ,
             \'running out of ideas here...']}])

Future versions will make this cleaner with a :Command

Also if you have a spur of the moment Idea type
:SwapIdea
To get to the current filetypes swapit file

Note: This alpha version doesnt create the directory structure

To integrate with other incrementor scripts (such as
speeddating.vim vimscript #2120  or monday.vim vimscript #1046),
:nmap <Plug>SwapItFallbackIncrement and <Plug>SwapItFallbackDecrement
to the keys that should be invoked when swapit doesn't have a
proper option. For example for speeddating.vim:

nmap <Plug>SwapItFallbackIncrement <Plug>SpeedDatingUp
nmap <Plug>SwapItFallbackDecrement <Plug>SpeedDatingDown
 
install details
place swapit.vim in plugins directory

(for extending to filetypes)
mkdir ~/.vim/after/ftplugin/
 

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
swapit-0.3.5.zip 0.3.5 2015-09-07 7.0 Michael Brown Added support for repeat.vim . Thanks Hotschke
swapit-0.3.4.zip 0.3.4 2015-01-18 7.0 Michael Brown added lists for Latex file handling. thanks kiryph  
swapit-master.zip 0.3.3 2014-03-24 7.0 Michael Brown add ftplugin that cycles through interactive git rebase options.

#  p, pick = use commit
#  r, reword = use commit, but edit the commit message
#  e, edit = use commit, but stop for amending
#  s, squash = use commit, but meld into previous commit
#  f, fixup = like "squash", but discard this commit's log message
#  x, exec = run command (the rest of the line) using shell

should work when you type 'git rebase -i' on the command line.
swapit-master.zip 0.3.2 2013-10-07 7.2 Michael Brown Added step feature eg 4Ctrl-a can now jump from 'one' to 'five'
Removed some register clobbering
Thanks Ingo Karkat
mjbrownie-swapit-857ad49.zip 0.3.1 2012-03-13 7.0 Michael Brown fallback incrementors now work (eg 42<c-a> on an int). Thanks Ingo Karkat
swapit.0.3.tar.gz 0.3 2009-09-01 7.0 Michael Brown Added Direct Css omnicomplete swapping (see link in description). Added help file
swapit.0.2.tar.gz 0.2 2009-08-28 7.0 Michael Brown Added html tag swap support, support for exclusive mode and some filetype examples
swapit.vim 0.1.2 2008-07-14 7.0 Michael Brown Speed dating compatability enhancements. swap on phrases with visual mode, some bug fixes. Many thanks to Ingo Karkat
ip used for rating: 142.132.191.50

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