sponsor Vim development Vim logo Vim Book Ad

BlockWork : Adjust list numbering (increment) and other work with (visual) block selections

 script karma  Rating 2/6, Downloaded by 814    Comments, bugs, improvements  Vim wiki

created by
John Aldridge
 
script type
utility
 
description
Function to Work with Selected Blocks --
Includes vmap assignments for incrementing, decrementing, and re-sequencing integers in a selected block.

Purpose:
Simplifies editing numbered lists or other sequences of numbers.  
Includes function to apply most any command to a selected 'visual block' of text.

Justification:
Vim includes CTRL-A and CTRL-X to add and subtract from integers under the cursor, however neither of these works on selections.
There are search and replace techniques to handle multiple changes on a range of lines (e.g. s/-\?\d\+/\=submatch(0)+1/g').
However, this won't work on a 'visual block' selection.

Example:
The first item was deleted from the following list,
and you want to decrement all the numbers by 1.
     2) show 35
     3) show 19
     4) show 85
     ...
   134) show 12
Using this plugin, you would position the cursor on the 2,
select the column of numbers, and decrement -- i.e. type:
   <C-V>132jb<C-X>
(where <C-V> and <C-X> are CTRL-V and CTRL-X respectively)

Re-sequencing (To Automatically Correct A Sequence):
There is also a feature to re-sequence a selection of numbers (automatically eliminating all missing numbers).  Note that I've mapped the re-sequence function to <M-S-A> and <M-S-X>  (that's Alt plus Shift and A or X).  (The functional interface within the script allows easy adaptation for other scripters.)

Issues and challenges with the techniques employed are discussed in the file.

---
2005-09-02: When I created this, I had imagined that I would update it a some point, but
it has served me well since I had created it.  I mostly use this script to re-sequence numbers.

Note that there are now at least four scripts that perform this functionality.
vimscript #670 - visincr.vim - Charles E Campbell (along with vimtip #150, handles dates!!!)
vimscript #145 - increment.vim - Stanislav Sitar
vimscript #156 - increment.vim - Srinath Avadhanula
vimscript #842 - increment.vim - William Natter (sequences on a substitution character)
vimscript #189 - renumber.vim - Neil Bird (only re-sequences, but handles hex)
vimscript #821 - blockwork.vim - John Aldridge
vimscript #1046 - monday.vim - Stefan Karlsson (increments month and weekday names)

Speak up if there are others.
 
install details
To use this file as a plugin, place it in the plugin directory.
To just try it out, download it anywhere and open it with Vim.
There are only four mapping assignments, which should be un-obtrusive (but they can be easily changed).
Additional instructions are at the beginning of the file.
 

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
blockwork.vim 0.0 2003-11-13 6.0 John Aldridge Initial upload
ip used for rating: 23.21.23.126

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.
   
SourceForge.net Logo