Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Emacs, how to set Ctrl-Key as LowerCaseKey does for Vim and Alt-Key as HigherCaseKey for Vim?

I use Emacs with Vimpulse installed. When writing a lot by myself, I want to do it in Ctrl/Alt - Key. But when organizing text structure or work with other applications, I prefer Vim in Emacs.

The problem is that keys for same action in each are different, which is making a lot of wrong keystrokes before I notice. So, any advice to make Ctrl-Key as LowerCaseKey does for Vim, and Alt-Key as HigherCaseKey for Vim, in Emacs?

Or if this is hard, could I find changed Vimpulse to make keys as Emacs?

like image 900
Olly Avatar asked Nov 26 '25 14:11

Olly


1 Answers

I'm not experienced with viper-mode, but something like the following appears to work based on the limited testing I've done:

(add-hook 'viper-load-hook
  #'(lambda ()
      (define-key viper-insert-basic-map (kbd "C-d") nil)
      (define-key viper-insert-basic-map (kbd "C-d C-d") 'kill-line)))

You can add whatever other definitions you require to that hook to ensure that they're evaluated upon start-up. You'll need to be careful with your chosen key bindings, however. C-y, for example, which you specifically mentioned, is normally bound to yank, and I suspect that's something you probably don't want to un-bind. Also, viper-mode appears to use a pretty complex and elaborate set of overlapping keymaps, so depending on what functionality you wish to enable, you may need to specify a different one (or, indeed, several different ones to be used in parallel), such as viper-vi-global-user-map, viper-insert-global-user-map, etc. Unfortunately, that's about the extent of my expertise w/r/t viper-mode.

Edit: Sorry, I think I may have misunderstood your request. If you want to apply these key-bindings outside of viper-mode, use global-set-key, i.e.:

(global-unset-key (kbd "C-d"))
(global-set-key (kbd "C-d C-d") 'kill-line)

And so on. Again, be careful of the bindings that you set. Use describe-key (bound by default to C-h k) to check what the key sequence you wish to remap is currently bound to.

like image 66
Greg E. Avatar answered Nov 29 '25 19:11

Greg E.