开发者

How to define keybinding inside a marked region

开发者 https://www.devze.com 2023-02-25 11:45 出处:网络
I have a idea to mark regions in emacs easier. I press C-SPC to start. I use a vi style key to extend selection. such as

I have a idea to mark regions in emacs easier.

  1. I press C-SPC to start.

  2. I use a vi style key to extend selection. such as

"j" : line down
"k": line up

instead of using arrow key or C-n, C-p, a singe char is easier to press

  1. When finish selecting, I choose a key to do some thing, also use a开发者_StackOverflow社区 vi style key

    "c": deactive region, copy region. "d" delete region "#" comment region "space" just leaving without do anything

I know I can use "M-w" "M-k" or something to do it, but I think vi style key is a easier way to do the job.

I search everywhere, but there is no elip package can do such thing.

Can someone help me to write some functions to do it? Or give me some suggestions.

I found a nice way to do it, share the solution:

(

defvar active-region-mode-map
  (let ((map (make-sparse-keymap)))
    map)
  )

(define-minor-mode active-region-mode
  "Active Region minor mode."
  :init-value nil
  :lighter " Region"
  :keymap active-region-mode-map
  :group 'active-region
  )

(defun active-region-on ()
  (active-region-mode 1))
(defun active-region-off ()
  (active-region-mode -1))
(add-hook 'activate-mark-hook 'active-region-on)
(add-hook 'deactivate-mark-hook 'active-region-off)

Now, enjoy it, "active-region-mode-map" map keybinding you like. For example:

(define-key active-region-mode-map (kbd "j") 'next-line)


You can have a look at the viper-mode.

0

精彩评论

暂无评论...
验证码 换一张
取 消