3

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?

mtk
  • 13,221
  • 16
  • 72
  • 112
Olly
  • 31
  • 2
  • 1
    Can you clarify what you're trying to achieve? Do you want Ctrl/Alt to act as Caps Lock toggles? Or to act as Shift? Or to upcase/downcase text under the cursor or elsewhere in the buffer? If you could provide a concrete example of the sort of behavior you'd prefer, that would be helpful. – Greg E. Jun 18 '12 at 19:26
  • thanks for your quick response. for example, in emacs, when vimpulse not enabled, i'd like c-y as copying to kill ring(as y in vim), c-d c-d as deleting one line(as dd in vim), m-g as going to end of buffer(as G in vim). In this way, I hope keys to be similar both when I turn on/off vimpulse mode in Emacs. – Olly Jun 19 '12 at 01:26

2 Answers2

2

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.

Greg E.
  • 2,722
  • 1
  • 16
  • 22
0

I try to add key bindings in .Emacs file before "require 'vimpulse'". But it is not working. So I add key bindings after "require 'vimpulse'". It then replaces everything no matter vimpulse is on or off. It is not an elegant solution at all. But I think I can live with that.(btw, if there is c-d, "\C-d \C-d" would not work)

Bindings as below:

;;remap keys like vim
(global-set-key (kbd "M-3") 'server-edit)                    ;; #
(global-set-key (kbd "M-4") 'move-end-of-line)               ;; $
(global-set-key (kbd "M-5") 'query-replace-regexp)           ;; % 
(global-set-key (kbd "M-6") 'move-beginning-of-line)         ;; ^
(global-set-key (kbd "C-w") 'forward-word)
(global-set-key (kbd "C-t") 'set-mark-command)
(global-set-key (kbd "C-y") 'kill-ring-save)
(global-set-key (kbd "C-u") 'undo)
(delete-selection-mode 1)                               ;; delete selection before yank
(global-set-key (kbd "C-p") 'yank)
(global-set-key (kbd "M-y") 'kill-region)
(global-set-key (kbd "C-x y") 'quick-copy-line)

(global-set-key (kbd "C-d") 'delete-forward-char)
(global-set-key (kbd "C-h") 'left-char)
(global-set-key (kbd "C-j") 'next-line)
(global-set-key (kbd "C-k") 'previous-line)
(global-set-key (kbd "C-l") 'right-char)
(global-set-key (kbd "M-g") 'end-of-buffer)
(global-set-key (kbd "M-j") 'delete-indentation)
(global-set-key (kbd "C-x d") 'kill-whole-line)
(global-set-key (kbd "C-x g") 'beginning-of-buffer)

(global-set-key (kbd "C-b") 'backward-word)
(global-set-key (kbd "C-`") 'bookmark-set)
(global-set-key (kbd "C-.") 'repeat)
(global-set-key (kbd "C-/") 'isearch-forward-regexp)
(global-set-key (kbd "M-m") 'bookmark-jump)
(global-set-key (kbd "M-/") 'isearch-backward-regexp)
(global-set-key (kbd "C-x m") 'bookmark-bmenu-list)
Olly
  • 31
  • 2