如何在标记区域内定义键绑定
我有一个想法,可以更轻松地标记 emacs 中的区域。
我按 C-SPC 启动。
我使用 vi 样式键来扩展选择。例如
"j" : 下一行 “k”:排队
与使用箭头键或 Cn、Cp 相比,单个字符更容易按
完成选择后,我选择一个键来做一些事情,也使用 vi 样式键
“c”:非活动区域,复制区域。 “d”删除区域 “#”评论区 “空格”只是离开而不做任何事情
我知道我可以使用“Mw”“Mk”或其他东西来做到这一点,但我认为 vi 风格键是完成这项工作的更简单的方法。
我到处搜索,但没有 elip 包可以做这样的事情。
有人可以帮我写一些函数来做到这一点吗?或者给我一些建议。
我找到了一个很好的方法来做到这一点,分享解决方案:(
现在,享受它, “
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)
active-region-mode-map”你喜欢的地图键绑定。例如:
(define-key active-region-mode-map (kbd "j") 'next-line)
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
"j" : line down "k": line up
instead of using arrow key or C-n, C-p, a singe char is easier to press
When finish selecting, I choose a key to do some thing, also use a 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以查看 viper-mode。
You can have a look at the viper-mode.