LoginSignup
3
3

More than 5 years have passed since last update.

Emacs で M-backspace で kill-ring に追加したくない

Last updated at Posted at 2014-04-28

環境

Macbook Air (US keyboard)

elisp

Meta-backspace で1単語を消してくれるのは便利なんですけど、いちいち kill-ring に入ってほしくない。用途としては、ただ消したいのであって後からその文字列をペースト(ヤンク)したいわけではないからです。こういう人は多いと思います。

結論から言うと、http://www.emacswiki.org/emacs/BackwardDeleteWord でおk.

上記URLからLispを転記すると、以下のとおり。

(defun delete-word (arg)
  "Delete characters forward until encountering the end of a word.
With argument, do this that many times."
  (interactive "p")
  (delete-region (point) (progn (forward-word arg) (point))))

(defun backward-delete-word (arg)
  "Delete characters backward until encountering the end of a word.
With argument, do this that many times."
  (interactive "p")
  (delete-word (- arg)))

(global-set-key (read-kbd-macro "<M-DEL>") 'backward-delete-word)

を init.el に追加するだけでOK。注意してほしいのは、

(global-set-key [(meta backspace)] 'backward-delete-word) ;; doesn't work

これだと何故かうまくいかないということ。もしかしたら Windows ではちゃんと動くかも。

また、上記に定義されている delete-word がキーマップに割あたっていないので、 M-d に割り当てるようにします。

(global-set-key [(meta d)] 'delete-word) ;; works fine!

こちらはちゃんと動きます。

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3