Sunday, March 6, 2016

Re: Odd vim bug with Ctrl-A?

Thanks Bee.  I should have known better and used: help ctrl-a as you suggested. Thanks again for the prompt response.

On Sat, Mar 5, 2016 at 8:26 PM, Bee <beeyawned@gmail.com> wrote:
On Saturday, March 5, 2016 at 7:55:47 PM UTC-8, Sonny Chee wrote:
> Hey Guys,
>
> I'm attempting to use Ctrl-A to autoincrement a number.  However, it has some odd behavior that I hope someone can shed some light on.
>
> 1) When it is a number that is not prefixed by a 0, it works as expected.
>
> 2) When there is a 0 prefix, the autoincrement jumps from 07 to 010
>
>
> 06 -- Ctrl-A --> 07 -- Ctrl-A --> 010
>
> Any idea what's going on?

Use the help command and note that a leading '0' is considered an octal number.

The following is from help in the change.txt file.

I have added to the .vimrc:

set nrformats=hex,alpha

That way hex numbers and alphabetic characters will be incremented or decremented.

If you want ONLY decimal numbers changed use:

set nrformats=

:help ctrl-a

Adding and subtracting
                                                        *CTRL-A*
CTRL-A                  Add [count] to the number or alphabetic character at
                        or after the cursor.  {not in Vi}

                                                        *CTRL-X*
CTRL-X                  Subtract [count] from the number or alphabetic
                        character at or after the cursor.  {not in Vi}

The CTRL-A and CTRL-X commands work for (signed) decimal numbers, unsigned
octal and hexadecimal numbers and alphabetic characters.  This depends on the
'nrformats' option.
- When 'nrformats' includes "octal", Vim considers numbers starting with a '0'
  to be octal, unless the number includes a '8' or '9'.  Other numbers are
  decimal and may have a preceding minus sign.
  If the cursor is on a number, the commands apply to that number; otherwise
  Vim uses the number to the right of the cursor.
- When 'nrformats' includes "hex", Vim assumes numbers starting with '0x' or
  '0X' are hexadecimal.  The case of the rightmost letter in the number
  determines the case of the resulting hexadecimal number.  If there is no
  letter in the current number, Vim uses the previously detected case.
- When 'nrformats' includes "alpha", Vim will change the alphabetic character
  under or after the cursor.  This is useful to make lists with an alphabetic
  index.

For numbers with leading zeros (including all octal and hexadecimal numbers),
Vim preserves the number of characters in the number when possible.  CTRL-A on
"0077" results in "0100", CTRL-X on "0x100" results in "0x0ff".
There is one exception: When a number that starts with a zero is found not to
be octal (it contains a '8' or '9'), but 'nrformats' does include "octal",
leading zeros are removed to avoid that the result may be recognized as an
octal number.

Note that when 'nrformats' includes "octal", decimal numbers with leading
zeros cause mistakes, because they can be confused with octal numbers.

--
--
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 a topic in the Google Groups "vim_use" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/vim_use/rJtIOtiGlSo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Sonny.
----------------------------------------------------------------------------
Be true to your work, your word, and your friend. Henry David Thoreau.

--
--
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 vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment