increment_new.vim : Subsitute a pattern with incremented values ENHANCED
script karma |
Rating 34/10,
Downloaded by 1393 |
Comments, bugs, improvements
|
Vim wiki
|
created by |
Ely Schoenfeld |
|
script type |
utility |
|
description |
This is a great (I think) improvement of the plugin increment.vim made by William Natter (natter at magma.ca) (vimscript #842).
I tried to contact William, but his mailbox does not exist... So here it goes.
As William wrote:
"This is a handy plugin that makes easy replacing your favorite pattern ("@" by default) with a sequence of incremented values using the "Inc" command. "
Besides what the original script can do, it has two new features:
a) Now you are able to search for a pattern and replace the Nth word from the beginning of the line with the incremental number.
b) And also you can get a confirmation message before change.
The help file is also greatly improved.
Here is an example:
You have: (beginning with spaces only)
----- cut -----
LMsgInstall6 = 7; // @
LMsgInstall7 = 8; // @
LMsgInstall8 = 9; // @
{STANDALONE}
LErrConnectionStandAlone1 = 10; //THIS
LErrConnectionStandAlone3 = 7; //THIS
LErrConnectionStandAlone5 = 12; //THIS
{some text}
LMsgExitConfirm = 30;
...
----- cut -----
You do: (with confirmation)
:'<,'>Inc p^\ *\\\<\[A-Za-z0-9_]*\\\>\ =\ [0-9]* w3 i25 s100 c
(Note that I had to use tree "\" before the "<" sign. Since Vim 7 the "<" and ">" have to be skiped by a "\")
You get:
----- cut -----
LMsgInstall6 = 100; // @
LMsgInstall7 = 125; // @
LMsgInstall8 = 150; // @
{STANDALONE}
LErrConnectionStandAlone1 = 175; //THIS
LErrConnectionStandAlone3 = 200; //THIS
LErrConnectionStandAlone5 = 225; //THIS
{some text}
LMsgExitConfirm = 250;
...
----- cut -----
Then you do: (without confirmation)
:'<,'>Inc pTHIS w3 i3 s5
You get:
----- cut -----
LMsgInstall6 = 100; // @
LMsgInstall7 = 125; // @
LMsgInstall8 = 150; // @
{STANDALONE}
LErrConnectionStandAlone1 = 5; //THIS
LErrConnectionStandAlone3 = 8; //THIS
LErrConnectionStandAlone5 = 11; //THIS
{some text}
LMsgExitConfirm = 250;
...
----- cut -----
Then you do: (without confirmation)
:'<,'>Inc
You get:
----- cut -----
LMsgInstall6 = 100; // 0
LMsgInstall7 = 125; // 1
LMsgInstall8 = 150; // 2
{STANDALONE}
LErrConnectionStandAlone1 = 5; //THIS
LErrConnectionStandAlone3 = 8; //THIS
LErrConnectionStandAlone5 = 11; //THIS
{some text}
LMsgExitConfirm = 250;
...
----- cut -----
Hope it helps.
Keywords: Inc Increment increment increment.vimnumber numbers num replace substitute subst pattern regex |
|
install details |
- Put increment_new.vim into a plugin directory.
- Put increment_new.txt into a doc directory.
(see :set runtimepath)
For example in *nix OS:
- The plugin directory should be: ~/.vim/plugin
- The doc directory should be: ~/.vim/doc
Something like:
mkdir ~/.vim
cd ~/.vim
tar -zxvf increment_new.tar.gz
For example in Windows:
- The plugin directory should be: %PROGRAMFILES%\Vim\vimfiles\plugin
- The doc directory should be: %PROGRAMFILES%\Vim\vimfiles\doc
(To extract the files from a tar.gz in windows, I use a great program called 7Zip (http://www.7-zip.org)
-Install Help
To be able to do:
:help Inc
in vim, you have to do, for example:
:helptags ~/.vim/doc
or
:helptags C:\Program Files\Vim\vimfiles\doc
|
|
script versions (upload new version)
Click on the package to download.
ip used for rating: 3.147.46.129
|