이블 모드 모범 사례? [닫은]
저는 수년간 Vim을 기본 편집기로 사용해 왔으며 그 기간 동안 Emacs를 여러 번 사용해 보았습니다. 그러다가 Evil을 발견 하고 마침내 Emacs로 넘어갈 수있을만큼 빠른 움직임에 대한 나의 요구를 충족 시키기로 결정했습니다.
그렇다면 모든 Evil 사용자에게 일반 Emacs 기능과 어떻게 통합합니까? 이 모드와 다른 모드간에 충돌이 발생 했습니까? 이 주제에 대한 공유 가치있는 경험 / 팁은 무엇입니까?
나는 고도로 맞춤화 된 vim을 사용했고 이제는 훨씬 더 맞춤화 된 emacs를 사용합니다. 내 키 매핑 구성 파일 https://github.com/mbriggs/.emacs.d-oldv2/blob/master/init/init-keymaps.el 에서 모든 키 매핑 인스턴스를 찾을 수 있다고 생각합니다.
명심하세요, 저는 실제 emacs 사용자들이 이단이라고 생각하는 것들을 리 바인딩하고 있습니다. 그래서 만약 당신이 "진짜"emacs를 배우고 싶다면 YMMV (정말 그렇지 않습니다).
제가 전직 비머에게 추천하고 싶은 것은
;;; esc quits
(defun minibuffer-keyboard-quit ()
"Abort recursive edit.
In Delete Selection mode, if the mark is active, just deactivate it;
then it takes a second \\[keyboard-quit] to abort the minibuffer."
(interactive)
(if (and delete-selection-mode transient-mark-mode mark-active)
(setq deactivate-mark t)
(when (get-buffer "*Completions*") (delete-windows-on "*Completions*"))
(abort-recursive-edit)))
(define-key evil-normal-state-map [escape] 'keyboard-quit)
(define-key evil-visual-state-map [escape] 'keyboard-quit)
(define-key minibuffer-local-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-ns-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-completion-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-must-match-map [escape] 'minibuffer-keyboard-quit)
(define-key minibuffer-local-isearch-map [escape] 'minibuffer-keyboard-quit)
esc는 실제로 거의 모든 것을 종료합니다 (미니 버퍼의 보류중인 프롬프트와 같은)
emacs에서 왔고, vim을 사용해 보았고, 얻을 것이 엄청나게 많다는 것을 깨달은 사람으로서 저는 처음에 악을 사용하기 시작했을 때 많은 실험을했습니다. 다음은 논란의 여지가 있지만 터미널, 파이어 폭스, 코코아 등에서 더 보편적으로 사용되는 emacs 키를 유지하고 싶었지만 vim 편집 기능을 잃고 싶지 않았습니다. 내 .emacs에서 다음 키를 리 바인드하기로 결정했습니다.
(define-key evil-normal-state-map "\C-e" 'evil-end-of-line)
(define-key evil-insert-state-map "\C-e" 'end-of-line)
(define-key evil-visual-state-map "\C-e" 'evil-end-of-line)
(define-key evil-motion-state-map "\C-e" 'evil-end-of-line)
(define-key evil-normal-state-map "\C-f" 'evil-forward-char)
(define-key evil-insert-state-map "\C-f" 'evil-forward-char)
(define-key evil-insert-state-map "\C-f" 'evil-forward-char)
(define-key evil-normal-state-map "\C-b" 'evil-backward-char)
(define-key evil-insert-state-map "\C-b" 'evil-backward-char)
(define-key evil-visual-state-map "\C-b" 'evil-backward-char)
(define-key evil-normal-state-map "\C-d" 'evil-delete-char)
(define-key evil-insert-state-map "\C-d" 'evil-delete-char)
(define-key evil-visual-state-map "\C-d" 'evil-delete-char)
(define-key evil-normal-state-map "\C-n" 'evil-next-line)
(define-key evil-insert-state-map "\C-n" 'evil-next-line)
(define-key evil-visual-state-map "\C-n" 'evil-next-line)
(define-key evil-normal-state-map "\C-p" 'evil-previous-line)
(define-key evil-insert-state-map "\C-p" 'evil-previous-line)
(define-key evil-visual-state-map "\C-p" 'evil-previous-line)
(define-key evil-normal-state-map "\C-w" 'evil-delete)
(define-key evil-insert-state-map "\C-w" 'evil-delete)
(define-key evil-visual-state-map "\C-w" 'evil-delete)
(define-key evil-normal-state-map "\C-y" 'yank)
(define-key evil-insert-state-map "\C-y" 'yank)
(define-key evil-visual-state-map "\C-y" 'yank)
(define-key evil-normal-state-map "\C-k" 'kill-line)
(define-key evil-insert-state-map "\C-k" 'kill-line)
(define-key evil-visual-state-map "\C-k" 'kill-line)
(define-key evil-normal-state-map "Q" 'call-last-kbd-macro)
(define-key evil-visual-state-map "Q" 'call-last-kbd-macro)
(define-key evil-normal-state-map (kbd "TAB") 'evil-undefine)
(defun evil-undefine ()
(interactive)
(let (evil-mode-map-alist)
(call-interactively (key-binding (this-command-keys)))))
안타깝게도 이러한 기능은 vim "한 화면 위로 또는 아래로 이동"작업과 겹칩니다. 그러나 대신 다음을 사용하는 것이 편해졌습니다.
(define-key evil-normal-state-map (kbd "DEL") (lambda ()
(interactive)
(previous-line 10)
(evil-scroll-line-up 10)
))
(define-key evil-normal-state-map (kbd "=") (lambda ()
(interactive)
(next-line 10)
(evil-scroll-line-down 10)
))
또한 vim에서 "jk"(또는 다른 2 개의 스트로크 조합)를 사용하여 삽입에서 일반 모드로 빠른 경로를 원하는 경우 가장 좋은 방법은 http://www.emacswiki.org/ 에서 텍스트를 복사하는 것입니다 . emacs / download / key-chord.el 및 ~ / .emacs.d / key-chord.el에 붙여 넣습니다. 그런 다음 .emacs에 다음을 추가합니다.
;load a file named key-chord.el from some directory in the load-path (e.g. "~/.emacs.d")
(require 'key-chord)
(key-chord-mode 1)
(key-chord-define-global "jk" 'evil-normal-state)
또한 vim에서 왔고 emacs의 클립 보드 복사가 좋지 않다고 생각한다면 아마도 맞을 것입니다. 그러나 sudo apt-get install xsel을 실행 한 후 다음과 같은 유용한 정보를 찾을 수 있습니다.
(defun copy-to-clipboard ()
(interactive)
(if (display-graphic-p)
(progn
(message "Yanked region to x-clipboard!")
(call-interactively 'clipboard-kill-ring-save)
)
(if (region-active-p)
(progn
(shell-command-on-region (region-beginning) (region-end) "xsel -i -b")
(message "Yanked region to clipboard!")
(deactivate-mark))
(message "No region active; can't yank to clipboard!")))
)
(evil-define-command paste-from-clipboard()
(if (display-graphic-p)
(progn
(clipboard-yank)
(message "graphics active")
)
(insert (shell-command-to-string "xsel -o -b"))
)
)
(global-set-key [f8] 'copy-to-clipboard)
(global-set-key [f9] 'paste-from-clipboard)
Obviously, you will have to decide for yourself whether any of these controversial changes are worth it, but perhaps these basic changes will inspire you.
For some other really cool function implementations, such as delete and paste, delete without copying to clipboard, efficient 4x / 16x movement, use of counts for paste register specification, tab settings that actually work for c/c++, and more, you can check out the full .emacs, init.el, my-keymaps.el, and my-functions.el versons on my git at https://github.com/Russell91/emacs
I also used to be a Viper/Vimpulse user, with a huge amount of configuration. Then I found Evil-mode.
What's your sharing-worthy experiences/tips on this topic?
This is my whole evil-mode configuration, and it works great for me:
(require 'evil)
(evil-mode 1)
;; Remap org-mode meta keys for convenience
(mapcar (lambda (state)
(evil-declare-key state org-mode-map
(kbd "M-l") 'org-metaright
(kbd "M-h") 'org-metaleft
(kbd "M-k") 'org-metaup
(kbd "M-j") 'org-metadown
(kbd "M-L") 'org-shiftmetaright
(kbd "M-H") 'org-shiftmetaleft
(kbd "M-K") 'org-shiftmetaup
(kbd "M-J") 'org-shiftmetadown))
'(normal insert))
Have you encounter any conflicts between this mode and others?
No, in contrast to Viper/Vimpulse which was causing trouble in several modes.
I started to use Evil a month ago; before it, I tried to use viper/vimpulse without much of success. To be honest, vimpulse is quite nice, but using it with various modes was a bit troublesome (e.g. compilation mode where vimpulse went always crazy) leaving emacs in some mode between vi-emacs-something.
When I switched to Evil, I finally started to explore full Emacs power, and believe me, I didn't regret. Evil works nicely in all modes I used (mostly editing, compilation, scratch and eshell) and even reading info/man/help is working without any problems.
Except that, I only found buffer switching odd as I used to do :b<0-9> instead :b-TAB-then-complete-name or :bn. Note however that Evil developers tries (in some cases) to reduce duplicate functionalities, so instead :! (to exec shell command), you should use native M-!.
If you find urge to add/redefine some custom ex commands, just open evil-maps.el and edit it (try that in vim!).
Evil is still young but promising project and I'm waiting the day when will replace viper in official Emacs distribution.
I like to save the buffer when I exit the insert-mode
: (edited: do not ask to save when there is no associated file for this buffer, like when in a scratch or a magit buffer)
(defun my-save ()
(if (buffer-file-name)
(evil-save))
)
(add-hook 'evil-insert-state-exit-hook 'my-save)
for more possibilities: see http://wikemacs.org/index.php/Evil
Comments welcome for improvements !
I use evil-leader and use ",xm" to replace "M-x", so I seldom press Alt key. There is also general.el which supports multiple leader keys.
evil-matchit, press "%" to jump between tag pair.
evil-nerd-commenter, press "9,ci" to comment/uncomment 9 lines
avoid using ESC key, you can press "kj" instead.
Have faith in free software! Nothing is impossible with Evil which combining the power of Vim and Emacs. For example, many people assume that Evil keybindings conflicts with existing plugins Emacs without heavy re-binding. That's wrong actually
Coming from the emacs side, I very much prefer M-. to be go-to-definition, but the function that runs on M-.
differs across modes. I could override it in the regular way with (define-key evil-normal-state-map (kbd "M-.") 'foo)
where foo
checks the current major mode and runs the appropriate function, but that sounds like it'd require lots of hardcoding. A more general solution is this:
(defun evil-emacs-key-binding (key)
(evil-execute-in-emacs-state)
(key-binding key))
(defmacro evil-revert-key-binding (state-map key)
`(define-key ,state-map ,key (lambda ()
(interactive)
(call-interactively
(evil-emacs-key-binding ,key)))))
(eval-after-load "evil-autoloads"
'(add-hook 'evil-after-load-hook
(lambda ()
(evil-revert-key-binding evil-normal-state-map (kbd "M-."))
;; and so on
)))
Other than that, I like the plugins evil-surround (though I feel smartparens is a more complete solution) and evil-leader.
I used to use key-chord to map jk to ESC like I've learnt to do in vim, but it insisted on treating kj as the same as jk, so instead I'm using the following:
(defun evil-escape-if-next-char (trigger)
"Watches the next letter. If `trigger', then switch to normal mode,
otherwise keep the previously inserted key and forward unpressed
key to `unread-command-events'."
(self-insert-command 1)
(let ((next-key (read-event)))
(if (eq trigger next-key)
(progn
(delete-char -1)
(evil-normal-state))
(setq unread-command-events (cons next-key unread-command-events)))))
(defun evil-escape-if-next-char-is-k (arg)
(interactive "p")
(if (= arg 1)
(evil-escape-if-next-char ?k)
(self-insert-command arg)))
(eval-after-load "evil-autoloads"
'(add-hook 'evil-after-load-hook
(lambda ()
;; … other stuff …
(define-key evil-insert-state-map (kbd "j") 'evil-escape-if-next-char-is-k))))
I use (setq evil-move-cursor-back nil)
which isn't very vimmy (although apparantly you can make your vimrc do that as well), I just never got used to the cursor moving back after exiting insert.
Practical tip: use evil-local-mode-hook
for stuff like lazy loading evil-surround-mode, it won't help to put it in plain evil-mode-hook
. So if you install evil and evil-surround with package-install, you can have it start when you do M-x evil-mode
by doing
(eval-after-load "evil-surround-autoloads"
'(add-hook 'evil-local-mode-hook #'evil-surround-mode))
(Of course, if you always run evil-mode and always have evil installed, there's no need for that autoload stuff, but I prefer to have my .emacs be general enough that I can use it on machines with old emacsen or without having any elpa packages installed.)
참고URL : https://stackoverflow.com/questions/8483182/evil-mode-best-practice
'Programming' 카테고리의 다른 글
mysql-얼마나 많은 열이 너무 많습니까? (0) | 2020.08.13 |
---|---|
csv.DictWriter로 헤더 행을 작성하는 방법은 무엇입니까? (0) | 2020.08.13 |
DLL을로드 할 수 없습니다 (모듈을 찾을 수 없음 HRESULT : 0x8007007E). (0) | 2020.08.13 |
gulp globbing- 디렉토리 아래의 모든 것을 보는 방법 (0) | 2020.08.13 |
HTML / CSS : 두 개의 플로팅 div를 같은 높이로 만들기 (0) | 2020.08.12 |