Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Certain "change-object" functions delete more than expected, including end of line #1407

Open
thomasheartman opened this issue Jan 12, 2021 · 1 comment · May be fixed by #1775
Open

Certain "change-object" functions delete more than expected, including end of line #1407

thomasheartman opened this issue Jan 12, 2021 · 1 comment · May be fixed by #1775

Comments

@thomasheartman
Copy link

thomasheartman commented Jan 12, 2021

Issue type

  • Question

Environment

Emacs version: GNU Emacs 28.0.50 (build 1, x86_64-apple-darwin19.6.0, NS appkit-1894.60 Version 10.15.7 (Build 19H15))
Operating System: macOS Catalina (though I'm pretty sure this is the same on NixOS)
Evil version: Evil version 1.14.0
Evil installation type: MELPA
Graphical/Terminal: Graphical
Tested in a make emacs session (see CONTRIBUTING.md): No

Reproduction steps

  • Start Emacs
  • open a scratch buffer in text-mode (or any other mode should also do)
  • use this as content:
first line
      "line in quotes"
last line
  • place cursor on second line and cc
  • the last line is joined with the second line:
first line
last line

Expected behavior

When changing an entire line or changing around an quotes at the end of a line, this should not delete the newline. Changing entire lines could place cursor at indentation.

Actual behavior

Changing an entire line or around quotes (single or double) at the end of a line also deletes the following newline.

Question

Hi! Evil deletes more than I expect it to on certain motions. I suspect that this is just a setting that I have or have not set somewhere, but I haven't been able to find it in the docs. I also have not found a way to search for it online, so this might be easily explained somewhere else.

There's a few scenarios where this comes up (outlined below), but the short form is: how do I make cc delete the content on the current line and place the cursor at indentation; and (less-importantly) how do I make da" not delete newlines in text-mode?

I suspect it's related to Evil's types (exclusive, inclusive, etc) somehow, but I don't know much about that. It might also be worth mentioning that this behavior is different from Vim.

cc

The first and most noticeable one is cc to change the current line. It deletes the entire line including the newline. In other words, this (with the cursor on the second indented line):

first line
      "line in quotes"
last line

becomes this (with the cursor at the start of the second line):

first line
last line

Ideally I'd want this to move to the first non-whitespace character and change everything from there on out (essentially act as ^ C), especially in cases where there is a 'correct' indentation. At least I'd expect the current line to remain and the buffer to look like this (with the cursor either at the start of line 2 or at the 'correct' indentation):

first line

last line

ca" / da"

EDIT: Turns out this is only in text-mode and thus might not be an issue at all. Programming modes work just fine. However, it's still unexpected to me.

The second one is when a line is encased in quotes. In this case too, the newline is included in the changing/deleting action, and I end up with the third line at the end of the second. This, with the cursor inside the quoted line:

first line
      "line in quotes"
last line

becomes

first line
      last line

I have not gone through the reproduction steps yet, as I think this is related to a setting I'm not aware of. If this turns out to be an actual problem, I'll happily see if I can reproduce it.

Thanks!

Edit

Noticed that the issue with quotes only seems to happen in text-mode, and as such isn't much of a problem (though I'm still curious as to why it happens), so deemphasized that a bit.

@thomasheartman
Copy link
Author

Update: I found that setting evil-respect-visual-line-mode to nil fixes the issue with cc. If it's set to nil it both keeps the new line and places the cursor at indentation, which is exactly what I was looking for. However, the behavior of da" and ca" in text-mode is still the same and still perplexing to me. So even if it's not a big deal, I'd love to hear whether this is intended or not and if it can be disabled. Cheers!

justbur added a commit to justbur/evil that referenced this issue Apr 4, 2023
When the type is screen-line and multiple real lines are spanned, make
evil-change behave like it does for the line type (e.g., by adding and indenting
a new line after deletion).

Partially fixes emacs-evil#1407
@justbur justbur linked a pull request Apr 4, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant