Incrementing and decrementing numbers

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Incrementing and decrementing numbers

Ven Tadipatri
I like the ctrl+a and ctrl+x shortcuts for increasing and decreasing numbers, but I noticed
some peculiar behaviors with dashes (Vim 7.2). If I have a string
  data-2-4
When I go to the '2' and hit ctrl a, it seems to treats it as a negative number, so incrementing it
results in data-1-4 (so apparently -2 became -1)
  But if I have the string
  data.2.4
Now, when I go to the '2' and hit ctrl a, the behavior is as expected, result in data.3.4

Is there some flag to allow ctrl+a to always increment a number and not treat the numbers as positive and negative values, and likewise for ctrl+x?

Thanks,
Ven

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Incrementing and decrementing numbers

Arun Easi-2
Looks like it is signed operation always, you can try these mappings instead:

"Keeping cursor on a number, hit these
nn <c-a> ciw<c-r>=@"+1<cr><esc>
nn <c-x> ciw<c-r>=@"-1<cr><esc>

You can, maybe, write a function to move to the nearest number to mimic native ctrl-a behavior.

Regards,
-Arun

On Thu, Jun 4, 2015 at 6:54 AM Ven Tadipatri <[hidden email]> wrote:
I like the ctrl+a and ctrl+x shortcuts for increasing and decreasing numbers, but I noticed
some peculiar behaviors with dashes (Vim 7.2). If I have a string
  data-2-4
When I go to the '2' and hit ctrl a, it seems to treats it as a negative number, so incrementing it
results in data-1-4 (so apparently -2 became -1)
  But if I have the string
  data.2.4
Now, when I go to the '2' and hit ctrl a, the behavior is as expected, result in data.3.4

Is there some flag to allow ctrl+a to always increment a number and not treat the numbers as positive and negative values, and likewise for ctrl+x?

Thanks,
Ven

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Incrementing and decrementing numbers

Tim Chase
On 2015-06-04 16:12, Arun wrote:
> Looks like it is signed operation always, you can try these mappings
> instead:
>
> "Keeping cursor on a number, hit these
> nn <c-a> ciw<c-r>=@"+1<cr><esc>
> nn <c-x> ciw<c-r>=@"-1<cr><esc>
>
> You can, maybe, write a function to move to the nearest number to
> mimic native ctrl-a behavior.

You can do a ^A followed by an undoing ^X to move the cursor to the
right place before Arun's suggestion:

  nnoremap <c-a> <c-a><c-x>ciw<c-r>=@"+1<cr><esc>
  nnoremap <c-x> <c-a><c-x>ciw<c-r>=@"-1<cr><esc>

-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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Incrementing and decrementing numbers

Christian Brabandt
On Do, 04 Jun 2015, Tim Chase wrote:

> On 2015-06-04 16:12, Arun wrote:
> > Looks like it is signed operation always, you can try these mappings
> > instead:
> >
> > "Keeping cursor on a number, hit these
> > nn <c-a> ciw<c-r>=@"+1<cr><esc>
> > nn <c-x> ciw<c-r>=@"-1<cr><esc>
> >
> > You can, maybe, write a function to move to the nearest number to
> > mimic native ctrl-a behavior.
>
> You can do a ^A followed by an undoing ^X to move the cursor to the
> right place before Arun's suggestion:
>
>   nnoremap <c-a> <c-a><c-x>ciw<c-r>=@"+1<cr><esc>
>   nnoremap <c-x> <c-a><c-x>ciw<c-r>=@"-1<cr><esc>

If only <c-a>/<c-x> would work in visual mode, one could simply visually
select the number and use <c-a>/<c-x>

Best,
Christian
--
Was ist weiß und steht hinter'm Baum?
Eine schüchterne Milch!

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Incrementing and decrementing numbers

Ben Fritz
That sounds like a fantastic idea!

--
--
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

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.