@@ -4863,14 +4863,18 @@ fn add_newline_impl(cx: &mut Context, open: Open) {
48634863 apply_transaction(&transaction, doc, view);
48644864}
48654865
4866+enum IncrementDirection {
4867+ Increase,
4868+ Decrease,
4869+}
48664870/// Increment object under cursor by count.
48674871fn increment(cx: &mut Context) {
4868− increment_impl(cx, cx.count() as i64);
4872+ increment_impl(cx, IncrementDirection::Increase);
48694873}
48704874
48714875/// Decrement object under cursor by count.
48724876fn decrement(cx: &mut Context) {
4873− increment_impl(cx, -(cx.count() as i64));
4877+ increment_impl(cx, IncrementDirection::Decrease);
48744878}
48754879
48764880/// This function differs from find_next_char_impl in that it stops searching at the newline, but also
@@ -4894,7 +4898,7 @@ fn find_next_char_until_newline<M: CharMatcher>(
48944898}
48954899
48964900/// Decrement object under cursor by `amount`.
4897−fn increment_impl(cx: &mut Context, amount: i64) {
4901+fn increment_impl(cx: &mut Context, increment_direction: IncrementDirection) {
48984902 // TODO: when incrementing or decrementing a number that gets a new digit or lose one, the
48994903 // selection is updated improperly.
49004904 find_char_impl(
@@ -4906,6 +4910,17 @@ fn increment_impl(cx: &mut Context, amount: i64) {
49064910 1,
49074911 );
49084912
4913+ // Increase by 1 if `IncrementDirection` is `Increase`
4914+ // Decrease by 1 if `IncrementDirection` is `Decrease`
4915+ let sign = match increment_direction {
4916+ IncrementDirection::Increase => 1,
4917+ IncrementDirection::Decrease => -1,
4918+ };
4919+ let mut amount = sign * cx.count() as i64;
4920+
4921+ // If the register is `#` then increase or decrease the `amount` by 1 per element
4922+ let increase_by = if cx.register == Some('#') { sign } else { 0 };
4923+
49094924 let (view, doc) = current!(cx.editor);
49104925 let selection = doc.selection(view.id);
49114926 let text = doc.text().slice(..);
@@ -4925,6 +4940,8 @@ fn increment_impl(cx: &mut Context, amount: i64) {
49254940
49264941 let (range, new_text) = incrementor.increment(amount);
49274942
4943+ amount += increase_by;
4944+
49284945 Some((range.from(), range.to(), Some(new_text)))
49294946 })
49304947 .collect();