Giter Site home page Giter Site logo

evil-numbers's Introduction

Evil Numbers

  • Increment / Decrement binary, octal, decimal and hex literals
  • works like C-a/C-x in vim, i.e. searches for number up to eol and then increments or decrements and keep zero padding up (unlike in vim)
  • When a region is active, as in evil’s visual mode, all the numbers within that region will be incremented/decremented (unlike in vim)

Detected Literals

  • binary, e.g. 0b0101, 0B0101
  • octal, e.g. 0o755, 0O700
  • hexadecimal, e.g. 0xDEADBEEF, 0XCAFE

Install

Put in load-path, (require 'evil-numbers) and bind, for example:

(global-set-key (kbd "C-c +") 'evil-numbers/inc-at-pt)
(global-set-key (kbd "C-c -") 'evil-numbers/dec-at-pt)

or only in evil’s normal state:

(define-key evil-normal-state-map (kbd "C-c +") 'evil-numbers/inc-at-pt)
(define-key evil-normal-state-map (kbd "C-c -") 'evil-numbers/dec-at-pt)

For window system users the keypad + and - present an alternative that can be directly bound without shadowing the regular + and -:

(define-key evil-normal-state-map (kbd "<kp-add>") 'evil-numbers/inc-at-pt)
(define-key evil-normal-state-map (kbd "<kp-subtract>") 'evil-numbers/dec-at-pt)

Usage

Position cursor on literal and play with your numbers!

Known Bugs

See http://github.com/cofi/evil-numbers/issues

Contributors

evil-numbers's People

Contributors

cofi avatar mattfidler avatar yorkz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

evil-numbers's Issues

This repository seems to be unmaintained, Melpa redirects to a maintained fork

Since this repository seems to be unmaintained.

Melpa has been updated:
Switch authoritative source of evil-numbers melpa/melpa@00d26e9

It now points to the maintained fork of evil-numbers:
https://github.com/juliapath/evil-numbers

The transfer was discussed here:
evil-numbers: unmaintained, policy for taking ownership? melpa/melpa#7559

@cofi
Since this repository comes up first when searching for evil-numbers

It would probably be helpful to archive this repository,
and add a note in the readme, stating that this repository isn't maintained.

And redirecting people to the maintained fork.
https://github.com/juliapath/evil-numbers

tip: bind to CTRL+ and CTRL-

Hi,

This is not a bug report, just a comment. Thanks a lot for this package. I use the following binding:

(define-key evil-normal-state-map (kbd "C-<kp-add>") 'evil-numbers/inc-at-pt)
(define-key evil-normal-state-map (kbd "C-<kp-subtract>") 'evil-numbers/dec-at-pt)

kp-add and kp-subtract are the "+" and "-" keys on the keypad on the right side. I find it more intuitive. First I added to C-a and C-x but then I realized that Emacs uses C-x a lot.

Best,

Laszlo

Rectangle region

A quick glance at the code indicates evil-numbers does not yet support rectangle regions. Adding this would make the library FAR more handy for data manipulation since it could be applied to columns of data tables. Is this in the works, or can anyone take a stab at adding this feature?

Suggestion for doc: combine evil-numbers and speeddating

Cool thing! Coming from vim, I'm used to having the functionality of evil-numbers and speeddating combined in one key mapping.

I achieved it like this:

(defun my-increment-at-pt nil
  "Increment number or date (speeddating) at point"
  (interactive)
  (condition-case nil
    (speeddating-increase 1)
    (error (evil-numbers/inc-at-pt 1))))
(defun my-decrease-at-pt nil
  "Decrease number or date (speeddating) at point"
  (interactive)
  (condition-case nil
    (speeddating-decrease 1)
    (error (evil-numbers/dec-at-pt 1))))
(evil-define-key 'normal 'global "C-c +" 'my-increment-at-pt)
(evil-define-key 'normal 'global "C-c -" 'my-decrease-at-pt)

Maybe you want to add the snippet to the README (or even integrate this combination in the source, if that dependency on speeddating makes sense?).

Increment characters too?

Hi there!

Thanks for sharing this package! It's appreciated.

However, I noticed one feature of Vim is missing.
When your cursor is on the letter A and you increment it in Vim, it will change the A into a B.

But this is not the case for this package. And I miss that a lot, especially when I record a macro to edit preformatted code for spreadsheets (like A1, B1, C1, etc.).

Would this Vim feature be available too?

0xB not recognized as a number

0xB or any hexadecimal number with 'B' in it is not recognized, if the cursor is on the 'B'.

evil-numbers probably mistakes the B for the start of a binary number.

Implement 2 pairs of inc/dec commands: one shall pad with zeros, another shall not

searches for number up to eol and then increments or decrements and keep zero padding up (unlike in vim)

@cofi, out of curiosity, what was the rationale behind this decision?

I'm sure there are pros and cons in both approaches, and padding doesn't always suit as well (see @mlf176f2's PR for just one of many examples).

I think it makes sense to have 2 pairs of commands, one shall pad with zeros, another shall not.
And no need to implement fancy rules to determine, when to use padding.


P.S. This may be better discussed in a separate thread, but currently padding works only for positive numbers, e.g. decrement from 10 gives 09, while increment from -10 gives -9.

Support 'g CTRL-A'

'g CTRL-A' is very useful for creating lines of increasing numbers.

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

                                                        v_CTRL-A
{Visual}CTRL-A          Add [count] to the number or alphabetic character in
                        the highlighted text.  {not in Vi}

                                                        v_g_CTRL-A
{Visual}g CTRL-A        Add [count] to the number or alphabetic character in
                        the highlighted text. If several lines are
                        highlighted, each one will be incremented by an
                        additional [count] (so effectively creating a
                        [count] incrementing sequence).  {not in Vi}
                        For Example, if you have this list of numbers:
                                1.
                                1.
                                1.
                                1.
                        Move to the second "1." and Visually select three
                        lines, pressing g CTRL-A results in:
                                1.
                                2.
                                3.
                                4.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.