Emacs: how to delete text without kill ring?

后端 未结 15 1062
旧巷少年郎
旧巷少年郎 2020-12-04 14:00

I\'d like to just delete some text so I can yank some other text instead of it. How can I do that? C-w cuts the selected text to kill ring and I end up with

15条回答
  •  北海茫月
    2020-12-04 14:38

    Add a delete equivalent of kill-region and kill-line keys C-w and C-k as follows. Bound to keys C-v and C-z.

    ;; A keybinding to delete-region gives a good "Windows CUT Ctrl-x equivalent".
    ;; What keybinding to use is awkward to choose.
    ;; using C-v "Windows PASTE Ctrl-v" is quite a subversive option.
    ;;  C-v = scroll up in emacs which I have no use for.
    (global-set-key (kbd "C-v") 'delete-region)
    
    ;; To have also a "Windows CUT" alternative to C-k (kill-line) this can be done:
    (defun delete-line () "delete line, take it out of kill ring. bind this func to C-z"
     (interactive)
     (setq last-command 'delete-line)
     (kill-line)
     (setq kill-ring (cdr kill-ring))
     (setq kill-ring-yank-pointer kill-ring)
     (setq last-command 'delete-line)
    )
    (global-set-key (kbd "C-z") 'delete-line)
    ;; without setting of last-command 2+ C-zs mess up kill-ring
    

提交回复
热议问题