Is there a git command to add differences within a range of line-numbers to the index?
I want to be able to select lines in my editor and run a macro to add
The closest pre-built tool that does something like this is git gui citool. It does not work directly in your editor (not all editors have useful diff views and I suspect that most people probably do not care to remember exactly which lines they have changed since the last commit, so a diff view is very useful), but seems like it is close to what you want.
git gui citool lets you review staged and unstaged changes in views that are equivalent to git diff --cached and git diff, respectively.
While reviewing unstaged changes, the context menu (right click) has options to stage the selected lines (or the clicked line if there is no selection) and an option to stage a whole hunk. Likewise when reviewing staged changes, the context menu has options to unstage lines or a hunk.
To get more context, you can use the “Show More Context” menu item (or “Show Less Context” if you want to shrink the hunks).
Once you have your new content staged, you can also compose your commit message and make the commit from inside the GUI.
I imagine that some people use git gui in a workflow like this:
git add).git gui, select “Rescan”, review the changes, stage/unstage some, and eventually commit them.