To install this package, run in Emacs:
M-x package-install RET evil-numbers RET
C-a
/ C-x
in VIM, i.e. searches for number up to eol
and then
increments or decrements.g C-a
/ g C-x
in VIM.0b0101
, 0B0101
.0o755
, 0O700
.0xDEADBEEF
, 0XCAFE
.²
and ₁
.
Once this package is installed, all you need to do is bind keys to
evil-numbers/inc-at-pt
and evil-numbers/dec-at-pt
.
Position cursor over or before the literal and play with your numbers!
You may also want to bind keys to the incremental versions of these functions.
evil-numbers-pad-default
t
if you want numbers to be padded with zeros (numbers with a leading zero are always padded).
If you want both behaviors, all commands take an optional argument padded
.evil-numbers-separator-chars
This option to support separator characters, set to "_" or "," to support numeric literals such as:
16_777_216
or 4,294,967,296
.
You may wish to set this as a buffer local variable to enable this only for languages that support separators.
evil-numbers-case
nil
Current case (default).upcase
Always upper case.downcase
Always lower case.evil-numbers-use-cursor-at-end-of-number
Support matching numbers directly before the cursor.
This is off by default as it doesn't follow VIM's behavior.
Example key bindings:
(global-set-key (kbd "C-c +") 'evil-numbers/inc-at-pt) (global-set-key (kbd "C-c -") 'evil-numbers/dec-at-pt) (global-set-key (kbd "C-c C-+") 'evil-numbers/inc-at-pt-incremental) (global-set-key (kbd "C-c C--") 'evil-numbers/dec-at-pt-incremental)
or only in evil's normal
& visual
states:
(evil-define-key '(normal visual) 'global (kbd "C-c +") 'evil-numbers/inc-at-pt) (evil-define-key '(normal visual) 'global (kbd "C-c -") 'evil-numbers/dec-at-pt) (evil-define-key '(normal visual) 'global (kbd "C-c C-+") 'evil-numbers/inc-at-pt-incremental) (evil-define-key '(normal visual) 'global (kbd "C-c C--") 'evil-numbers/dec-at-pt-incremental)
Keypad +
and -
present an alternative that can be directly bound without shadowing the regular +
and -
:
(evil-define-key '(normal visual) 'global (kbd "<kp-add>") 'evil-numbers/inc-at-pt) (evil-define-key '(normal visual) 'global (kbd "<kp-subtract>") 'evil-numbers/dec-at-pt) (evil-define-key '(normal visual) 'global (kbd "C-<kp-add>") 'evil-numbers/inc-at-pt-incremental) (evil-define-key '(normal visual) 'global (kbd "C-<kp-subtract>") 'evil-numbers/dec-at-pt-incremental)
Put in load-path
, (require 'evil-numbers)
and set key bindings.
Assuming you have the melpa
repository enabled, use-package
can be used as follows.
(use-package evil-numbers)
evil-numbers-0.6.tar.lz | 2022-Jan-06 | 7.82 KiB |
evil-numbers-use-cursor-at-end-of-number
option to match numbers directly before the cursor
(diverging from VIM's default behavior).message
instead of error
when no number is found
(don't error since VIM doesn't use an error in this case).evil-numbers-separator-chars
option to support separator characters,
such as 16_777_216
or 4,294,967,296
.evil-numbers-case
option for the case to use for hexadecimal values (defaults to the current case).Fix numbers being pushed out of selections.
(e.g. calling inc-at-pt on ^9 9$
where ^$
denote the start and end of the selection would result in 10 9
).