sponsor Vim development Vim logo Vim Book Ad

swapcol.vim : Swap two columns

 script karma  Rating 34/18, Downloaded by 1603  Comments, bugs, improvements  Vim wiki

created by
Tian Huixiong
 
script type
utility
 
description
         Swap columns, the columns are separated by blank.
         Column maybe is word, or maybe not:
            col1   col2   col3   col4   col5
            command!  -nargs=*  -range  -complete=command

         1. Move cursor on col1, and press  ]c  you will see:
            col2   col1   col3   col4   col5

         2. Move cursor on -range and press [c, you will see:
            command!  -range  -nargs=*  -complete=command

         3. Move cousor on column, means you can put cursor on any character
            of the column, not limit the first character.

         4. If you don't like the default map, just modify the source.
            The map code is on the bottom.

         5. You can swap columns on multiple lines.
            Swap column 1 and column 3 on five lines.

            111  222  333  444  555        333  222  111  444  555
            111  222  333  444  555        333  222  111  444  555
            111  222  333  444  555 ---> 333  222  111  444  555
            111  222  333  444  555        333  222  111  444  555
            111  222  333  444  555        333  222  111  444  555

            Step 1: select multiple lines in visual mode
                          press V (upper case)
                          and then use j or k to select lines
            Step 2: call Swapcols like:
                           :'<,'>Swapcols 1 3
                           (When you press :   '<,'> will come out automatically.)
            Setp 3: press Enter to continue, and you will get the result.

            Remember: the first column number is 1, not 0.
 
install details
         Put this file in ~/.vim/plugin on *nix
         Or put it in $vim/vimfiles/plugin on Windows
 

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
swapcol.vim 2.2 2011-08-27 7.0 Tian Huixiong Define a user command, to make easier to use.
swapcol.vim 2.1.1 2011-08-26 7.0 Tian Huixiong bug fixed
swapcol.vim 2.1 2011-08-25 7.0 Tian Huixiong Swap two columns ( on one line or multiple lines )
swapcol.vim 1.0 2011-08-25 7.0 Tian Huixiong Initial upload
ip used for rating: 3.15.221.67

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