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

How can I remap vim black hole register? #5288

Closed
czhang03 opened this issue Feb 28, 2016 · 12 comments
Closed

How can I remap vim black hole register? #5288

czhang03 opened this issue Feb 28, 2016 · 12 comments

Comments

@czhang03
Copy link

nnoremap d "_d
nnoremap dd "_dd

I don't know how to set that up in evil...

@TheBB
Copy link
Collaborator

TheBB commented Feb 28, 2016

It's not so simple. Maybe this will work?

(evil-define-operator my-delete (beg end type)
  (interactive "<R><x><y>")
  (evil-delete beg end type ?_))

(define-key normal-state-map "d" 'my-delete)
(define-key visual-state-map "d" 'my-delete)

@StreakyCobra
Copy link
Contributor

@TheBB "interactive"

@czhang03
Copy link
Author

I have tried, I don't think this is working ...

@StreakyCobra
Copy link
Contributor

What about:

(define-key evil-normal-state-map (kbd "d") (lambda ()
                                              (interactive)
                                              (evil-use-register ?_)
                                              (call-interactively 'evil-delete)))

@czhang03
Copy link
Author

I am sorry, but no, they all perform the same with nothing set...

@StreakyCobra
Copy link
Contributor

As far as I understood what your code is supposed to do, the one I proposed is doing the same. Maybe I didn't understood it correctly, so can you provide us more information:

  • Some reproduction steps
  • The expected behaviour

@dvzubarev
Copy link
Contributor

If you would like to remap more operators, you may find my config to be useful.

@TheBB
Copy link
Collaborator

TheBB commented Feb 28, 2016

It might be more fruitful for you to ask this at the evil repo instead of here.

@czhang03
Copy link
Author

i will try to ask the question there!

katusk referenced this issue in katusk/dotfiles Jul 12, 2016
@katusk
Copy link

katusk commented Jul 12, 2016

@chantisnake, did you manage to get an answer?

I have tried the "evil-define-operator" approach in the above for the bindings with keys "-d", but deleting lines with "-dd" does not work. In more detail:

  • If I hit "-df)", text gets deleted as expected ending up in the black hole register.
  • If I hit "-dd", nothing happens, and the message "Quit" appears at the bottom where the Ex command line is. I would expect "-dd" to delete the current line into the black hole register, just as normally the default "dd" would delete (and additonally yank) the current line.

Guys, is the latter behaviour expected, am I missing something?

EDIT: The "lambda ()" approach in the above with "-d" binding behaves exactly the same way.

@katusk
Copy link

katusk commented Jul 15, 2016

With my "-d" mapping:

  • Strangely, if I hit "-d-", the whole line is deleted into the black hole register, which I would expect when hitting "-dd".

Maybe this has something to do with the following? Purely brainstorming here, I have truly no idea really. At How do I change only what “dd” does in evil-mode's normal-state in a minor mode, I have found the following comment:

It's probably because evil hardcodes repetition of the operator as a line-wise operation

The next comment there points to the evil-macros.el file. I looked at it at bitbucket.org; if you search for "dd", you are going to find the following comments:

        ;; Make linewise operator shortcuts. E.g., "d" yields the
        ;; shortcut "dd", and "g?" yields shortcuts "g??" and "g?g?".

Unfortunately, I cannot make sense of the code below the comments, as I do not know Emacs Lisp at all.

@czhang03
Copy link
Author

I found the solution:

https://bitbucket.org/lyro/evil/issues/468/how-delete-to-the-register-in-a-keymap

  ;; delete without register
  (evil-define-operator evil-delete-without-register (beg end type yank-handler)
    (interactive "<R><y>")
    (evil-delete beg end type ?_ yank-handler))
  (define-key evil-normal-state-map (kbd "d") 'evil-delete-without-register)
  (define-key evil-visual-state-map (kbd "d") 'evil-delete-without-register)
  (define-key evil-normal-state-map (kbd "D") 'evil-delete)
  (define-key evil-visual-state-map (kbd "D") 'evil-delete)

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

5 participants