Delete, add 16, and insert

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

Delete, add 16, and insert

Colin Beighley
Hello,

I am wondering if there is a way, using some (range)s/// command, to take

0 : blah blah blah
1 : blah blah blah
2 : blah blah blah
 .
 .
 .
15 : blah blah blah

and, line by line, delete the number and replace it with itself plus 16.

Thanks,
Colin

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Delete, add 16, and insert

Israel Chauca Fuentes

On Jan 29, 2011, at 9:55 PM, Colin Beighley wrote:

> Hello,
>
> I am wondering if there is a way, using some (range)s/// command, to take
>
> 0 : blah blah blah
> 1 : blah blah blah
> 2 : blah blah blah
> .
> .
> .
> 15 : blah blah blah
>
> and, line by line, delete the number and replace it with itself plus 16.

:%s/^\d\+/\=submatch(0)+16/

See :h sub-replace-\=

Israel

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Delete, add 16, and insert

Adam-281
I'm curious why this doesn't work:

:g/^\d/norm 16(press control-a)  I tried just going :norm 16^A but that also doesn't work (they both just increment the number by 1).  I know that pressing 16^a in normal mode works correctly so that isn't the problem.

~Adam~

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Delete, add 16, and insert

Tim Chase
On 01/30/11 12:46, Adam wrote:
> :g/^\d/norm 16(press control-a)  I tried just going :norm 16^A but that also
> doesn't work (they both just increment the number by 1).  I know that
> pressing 16^a in normal mode works correctly so that isn't the problem.

If you only pressed ^A then it wasn't part of the command, but
rather an instruction to vim to auto-complete with all matching
patterns:

   :help c_CTRL-A

What you want is to enter the ^A literally which can be done by
prefixing it with control+V:

   :g/^\d/norm 16^V^A

which will appear as

   :g/^\d/norm 16^A

as detailed at

   :help c_CTRL-V

Hope that makes sense,

-tim



--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Delete, add 16, and insert

Adam-281
What you want is to enter the ^A literally which can be done by prefixing it with control+V:

Oh sorry yeah that's what I did do (^V^A) I guess I left it out.  When you do that it appears that it's only incrementing by 1 though instead of the prefix that you give it (16 in this case)

~Adam~

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Delete, add 16, and insert

Tim Chase
On 01/30/11 14:26, Adam wrote:
>> What you want is to enter the ^A literally which can be done
>> by prefixing it with control+V:
>
> Oh sorry yeah that's what I did do (^V^A) I guess I left it
> out.  When you do that it appears that it's only incrementing
> by 1 though instead of the prefix that you give it (16 in this
> case)

Good then, just wanted to make sure you weren't being surprised
by the behavior...I just tested it with a simple file with rows
of numbers and it worked with the [count] prefix:

   :g/^\d/norm 16^A

(with the ^A as described).  I also tested against the OP's data
and it worked for me.

Additionally, in my test case (with numbers on each line), you
can just use the :norm command with the range as detailed at

   :help :normal-range

and just issue

   :%norm 16^A

(if any lines shouldn't be incremented, using a smarter :g
command would be better)

-tim


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
Reply | Threaded
Open this post in threaded view
|

Re: Delete, add 16, and insert

Nikolay Aleksandrovich Pavlov
In reply to this post by Adam-281
Reply to message «Re: Delete, add 16, and insert»,
sent 23:26:19 30 January 2011, Sunday
by Adam:

Then you may have some plugin remapping <C-a>? Try doing
    execute "normal! 16\<C-a>"
and see whether it helps. There is a known (and fixed in vim-7.3.100) bug that
count is not passed to plugins in normal commands.

Original message:
> > What you want is to enter the ^A literally which can be done by prefixing
>
> > it with control+V:
> Oh sorry yeah that's what I did do (^V^A) I guess I left it out.  When you
> do that it appears that it's only incrementing by 1 though instead of the
> prefix that you give it (16 in this case)
>
> ~Adam~

signature.asc (205 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Delete, add 16, and insert

Adam-281
Then you may have some plugin remapping <C-a>? Try doing
   execute "normal! 16\<C-a>"
and see whether it helps. There is a known (and fixed in vim-7.3.100) bug that
count is not passed to plugins in normal commands.

Yup I must have some plugin that is doing that (the execute worked just fine).  I updated to a newer build of 7.3 and it worked as expected.  Much appreciated!

~Adam~

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php