0

I want to use the <delete> key (C-d, I think) for forward-deletion in viper-mode.

Before starting viper-mode, <delete> works correctly. In viper-mode, <delete> jumps to the buffer's last line.

I have added (setq viper-ex-style-editing nil) to .viper and <backspace> works in all modes.

Natan Yellin
  • 6,063
  • 5
  • 38
  • 57
  • Since you're using viper-mode we need more information. Do you want this to be bound in insertion mode? Or command mode? Both? What level of viper user are you (1-5)? – Trey Jackson Jun 01 '11 at 16:09
  • I'm using viper on level 5. I want to use `` in both insertion and command mode. – Natan Yellin Jun 01 '11 at 16:15

3 Answers3

2

Try this:

(define-key viper-vi-basic-map "\C-d" 'viper-delete-char)
(define-key viper-insert-basic-map "\C-d" 'viper-delete-char)

Now, that uses the viper-delete-char command to be consistent with viper. If you want the regular emacs deletion behavior, use delete-char instead.

viper is implemented using a bunch of different keymaps, and figuring out which ones to modify is tricky. The easiest way (usually) is to just look at the source code. So you could start with M-x find-library viper. Note: Most keymaps are actually defined in the library viper-cmd.

Trey Jackson
  • 73,529
  • 11
  • 197
  • 229
1

The \ key will switch back to Emacs mode for a single key stroke, so you can do what you are seeking with "\<delete>" without making any changes or adding any code to your .emacs file.

Howard West
  • 381
  • 3
  • 6
0

Okay, here's what you do.

(1) In viper mode, use C-h k to find out what <delete> is bound to. Just in case you want it attached to some other key.

(2) In some other mode, use C-h k to find out what the name of the function is that does what you want. I think it's delete-forward but don't trust me, check. RMS has an annoying tendency to rename things.

(3) Back in a viper-mode buffer use M-x local-set-key to set to what you want. Try it.

(4) If you're happy add this code to your .emacs

(defun fix-del-key-in-viper-mode ()
  (define-key viper-mode-map "<delete>" your-desired-function))
(add-hook viper-mode-hooks fix-del-key-in-viper-mode)

Warning, you may have to mess about with this a bit as I haven't tested it. In particular make sure it's really viper-mode-map and not something else, as the naming conventino isn't consistently followed.

Charlie Martin
  • 110,348
  • 25
  • 193
  • 263