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

It's Not bug report. Evil delete without yank #6977

Closed
qx opened this issue Sep 1, 2016 · 17 comments
Closed

It's Not bug report. Evil delete without yank #6977

qx opened this issue Sep 1, 2016 · 17 comments

Comments

@qx
Copy link

qx commented Sep 1, 2016

It's Not bug report. I just want to know is there any way to delete some words without yank last deleted when I press dd,or x.
I really annoyed by this yank too much.

@chrisbarrett
Copy link

I doubt you can override this behaviour, but if there's something in your kill-ring that you need to preserve, I would either:

  1. Use helm-show-kill-ring (SPC r y) when I want to paste something recent in the kill-ring, or
  2. Yank the important text into a register first with " a Y, so that I can later paste with " a p.

@NJBS
Copy link
Contributor

NJBS commented Sep 1, 2016

You can specify a register before issuing a command to have the contents be moved to that register. For example, "2yy will yank the current line to register 2. You can view all of your registers and their contents at any time by using SPC r e.

In your case, you can specify the register as _ (known as the black-hole register) and your deletion will not overwrite any previous registers. For example, to delete the current line you can use "_dd.

P.S. I would recommend enabling the paste-transient-state by setting dotspacemacs-enable-paste-transient-state to t in your .spacemacs file. This will allow you to select through previous yanks using C-j whenever you paste something.

@qx
Copy link
Author

qx commented Sep 1, 2016

@NJBS @chrisbarrett I rarely use register list, so I just want override dd && x that by the evil/vim default, and it seems hard to find a usefull answer. Spacemacs is wonderfull startkit,so I want make sure I was not missing something important

@TheBB
Copy link
Collaborator

TheBB commented Sep 1, 2016

I'm not sure how to apply it to just those operations but you can make evil-delete always use the black hole register with advices.

(defun bb/evil-delete (orig-fn beg end &optional type _ &rest args)
  (apply orig-fn beg end type ?_ args))
(advice-add 'evil-delete :around 'bb/evil-delete)

@qx
Copy link
Author

qx commented Sep 1, 2016

@TheBB thanks a lot, 5 Stars! That's I wantted, I find it nearlly 1 month..

@deb0ch
Copy link
Contributor

deb0ch commented Sep 1, 2016

Just to say that @qx is not the only one feeling that way, this specific behaviour has been one of the only things that annoyed me when I switched to hybrid mode.
When you delete code you don't usually want to paste it later.
Even when using <DEL>, every single character forms a separate entry in the register.

Is this a wanted behaviour that exist for a reason that I (we) didn't get ? With even single character entries ?

Anyways, thanks for this piece of code @TheBB, this is really useful 😄

@qx
Copy link
Author

qx commented Sep 1, 2016

@deb0ch I also want to know , WHY evil/vim dd or x will yank to register first?

@TheBB
Copy link
Collaborator

TheBB commented Sep 1, 2016

I can't speak for the original rationale but as a vimmer for 10 years I use it a lot, basically whenever I move stuff around. xp is a handy shortcut to swap two characters for when you type too quickly, for instance.

When you delete code you don't usually want to paste it later.

It's even more rare that I want to paste something that I didn't copy immediately before, so it's usually not a problem to me that deleted stuff hangs around in the registers. In the cases where I do need it, the paste transient state that @NJBS mentioned handles everything gracefully.

@deb0ch
Copy link
Contributor

deb0ch commented Sep 1, 2016

Being new to vim / evil style I find that the cut / delete distinction that exist in nearly all other editor makes sense and is convenient.

Would there be a way of having separate cut and delete keys without breaking evil users workflow ?

@qx
Copy link
Author

qx commented Sep 1, 2016

@NJBS your advise is useful
@TheBB ,may be default yank is more efficiently, I'll try. thanks again

@TheBB
Copy link
Collaborator

TheBB commented Sep 1, 2016

Would there be a way of having separate cut and delete keys without breaking evil users workflow?

Yeah, if <whatever> is cut then "_<whatever> is delete!

However it shouldn't be a big deal to make a PR to evil to change the default register. It'd be more flexible than my solution.

@TheBB
Copy link
Collaborator

TheBB commented Sep 1, 2016

https://bitbucket.org/lyro/evil/pull-requests/70/add-default-register-option/diff

@deb0ch
Copy link
Contributor

deb0ch commented Sep 1, 2016

Yep that's a good idea because it would be kind of tedious to add two extra steps every time you want to delete something (" and _), especially you even have to press shift for the both of them.

I was also thinking of using the prefix argument, like either providing it to choose the register or providing a negative one to choose the _ register. I don't know if it is already used for copy/cutting/deleting/pasting or if it would not be too "emacsy" for evil users, but maybe the two solutions would be compatible.

I really like the idea of being able to choose the default register though.

@qx qx closed this as completed Sep 15, 2016
@dre-hh
Copy link

dre-hh commented May 30, 2017

This is how it can be achieved in vim https://github.com/pazams/d-is-for-delete
Should be possible to apply the same technique in evil by remapping keys.

@TheBB if you add this advice around the default evil-delete, how would you cut then? (delete and yank)

@fiveNinePlusR
Copy link
Contributor

I think having a command to switch the default register would be nice to have or even just a toggle from the unnamed yank register to the black hole register.

@juacala
Copy link

juacala commented Oct 21, 2019

In insert mode, using does not add to the kill ring. That's how I get around this.

@chuckmasterson
Copy link

chuckmasterson commented Oct 10, 2023

@TheBB I'm trying to use this snippet you gave on Sep. 1, 2016, but encountering a weird interaction with evil-surround:

Without this code, using the standard behavior of d, I can go to the middle of something like (parenthesize|d words) (| marks point) and do ds), and I get back p|arenthesized words. (Moves the cursor backward, which is annoying but not relevant here.)

But with this code, when I do ds), it deletes the parentheses as well as everything up to the character before point: I get back ed words. Stranger still, cs)] works too (gives back [p|arenthesized words]), even though I think it should be using the same function under the hood.

Running Emacs 27.1 with Doom. I've only been looking at Elisp for 2 weeks, so my debugging capability is pretty limited. Obviously this is code you tossed out 7 years ago so I won't expect exhaustive tech support on it! If you do have an idea I can try to figure it out from wherever you might lose the trail. Otherwise I suppose I can mostly work around it by just using cs) (change surrounding parentheses into spaces) and then cleaning the whitespace up later if it turns out to be necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants