最近我尝试了Emacs,发现邪恶有助于保持我的vim自定义。我习惯于键入“jj”像许多Vimers一样从插入模式返回正常模式,但不知道如何在邪恶模式下进行。如何在emacs邪恶模式下将“jj”映射到Esc
我映射像这样,但似乎不正确:
(define-key evil-insert-state-map (kbd "jj") 'evil-normal-state)
最近我尝试了Emacs,发现邪恶有助于保持我的vim自定义。我习惯于键入“jj”像许多Vimers一样从插入模式返回正常模式,但不知道如何在邪恶模式下进行。如何在emacs邪恶模式下将“jj”映射到Esc
我映射像这样,但似乎不正确:
(define-key evil-insert-state-map (kbd "jj") 'evil-normal-state)
这适用于我。它要求KeyChord库:
;;Exit insert mode by pressing j and then j quickly
(setq key-chord-two-keys-delay 0.5)
(key-chord-define evil-insert-state-map "jj" 'evil-normal-state)
(key-chord-mode 1)
它是由@phils启发答案以上,并根据Simon's Coding Blog: Emacs and Unity Every Day。
这是一个比较复杂一点 - 你必须注意的一个字符。 This should do the trick.(主旨是“jk”,你可以很容易地修改它为“jj”,但你会注意到“jk”更高效/更快)。
我发现“kj”比“jk”要好于“jj”:) – vijiboy
查看此博文:http://zuttobenkyou.wordpress.com/2011/02/15/some-thoughts-on-emacs-and-vim/并搜索“cofi”。我自己使用“kj”版本,它和Vim一样工作。
编辑:这是从博客文章的实际代码片段:
(define-key evil-insert-state-map "k" #'cofi/maybe-exit)
(evil-define-command cofi/maybe-exit()
:repeat change
(interactive)
(let ((modified (buffer-modified-p)))
(insert "k")
(let ((evt (read-event (format "Insert %c to exit insert state" ?j)
nil 0.5)))
(cond
((null evt) (message ""))
((and (integerp evt) (char-equal evt ?j))
(delete-char -1)
(set-buffer-modified-p modified)
(push 'escape unread-command-events))
(t (setq unread-command-events (append unread-command-events
(list evt))))))))
没有谎言,这比我预期的映射更混乱。 –
@opert我想使用'jk'作为转义键,但在我交换了上面的所有'j'和'k'后,我不能再输入'k'(它变成了j ??)。谢谢。 – Tony
@Tony我不确定。这听起来像你有某种输入编码问题。 –
这是我自己的解决方案,我已经使用了一段时间,但我实际上使用`jf'。
(defun xwl-jj-as-esc()
(interactive)
(if (memq evil-state '(insert replace))
(let ((changed? (buffer-modified-p)))
(insert "j")
(let* ((tm (current-time))
(ch (read-key)))
(if (and (eq ch ?j)
(< (time-to-seconds (time-since tm)) 0.5))
(save-excursion
(delete-char -1)
(evil-force-normal-state)
(set-buffer-modified-p changed?))
(insert ch))))
(call-interactively 'evil-next-line)))
(define-key evil-insert-state-map "j" 'xwl-jj-as-esc)
(define-key evil-replace-state-map "j" 'xwl-jj-as-esc)
如果你使用Spacemacs然后我就发现,此设置(添加到user-init
开头)的作品非常好,
(setq-default evil-escape-key-sequence "jj")
对于我的窗户安装,如添加的一部分使用封装邪配置init.el工作对我来说:
(use-package evil
:ensure t
:config
(evil-mode 1)
(define-key evil-insert-state-map "jj" 'evil-normal-state)
)
对于Ubuntu的,我也跟着E.三宝的答案。
不得不指定延迟来使其工作,谢谢 – jarandaf