bind emacs evil window commands to g prefix

强颜欢笑 提交于 2019-12-13 04:46:44

问题


I'm new to Emacs. I have Emacs 24.3.1 with evil mode installed. I'm trying to bind gw as a prefix to the various evil-window functions. For example, I would like gwl to focus the window to the right, and gwh the window to the left. Of course, this is done in vim like so: nnoremap gw <c-w>.

In .emacs.d/config/init-bindings.el, I added:

  (define-key evil-normal-state-map (kbd "g w h") 'evil-window-left)
  (define-key evil-normal-state-map (kbd "g w j") 'evil-window-down)
  (define-key evil-normal-state-map (kbd "g w k") 'evil-window-up)
  (define-key evil-normal-state-map (kbd "g w l") 'evil-window-right)
  (define-key evil-normal-state-map (kbd "g w v") 'evil-window-vnew)

And emacs reports this error:

error: Key sequence g w h starts with non-prefix key g w
  • How do I make gw a prefix key?
  • Is there any reason this might be a bad idea (conflicts with important emacs defaults)?

回答1:


Reading your question (and not your answer), I managed to map gwh to evil-window-left doing the following:

  • is gw bound to an action ? Asking the help with C-h-k gw told me yes.
  • gz isn't, so using gzh worked out of the box:

    (define-key evil-normal-state-map (kbd "gzh") 'evil-window-left)
    
  • so un-mapping gw allowed to use gwh:

    (define-key evil-normal-state-map "gw" nil)
    (define-key evil-normal-state-map (kbd "gwh") 'evil-window-left)
    

ps: you still can fill paragraphs with M-q

pps: I myself like windmove with Super key more :)

    (require 'windmove)
    (windmove-default-keybindings 'super)


来源:https://stackoverflow.com/questions/19483278/bind-emacs-evil-window-commands-to-g-prefix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!