Viper mode in all modes

时光怂恿深爱的人放手 提交于 2019-12-21 02:03:29

问题


I'm moving from vi to emacs and, using viper and vimpulse, it gets pretty annoying when I C-w C-w to a window and cannot get back to the original one with the same command because the other buffer, which could be a help buffer, is not in the Viper mode. How can I fix this?

I tried to add other modes to the viper configuration and make them start with the viper mode on by default using hooks:

(add-to-list viper-vi-state-mode-list 'help-mode)
(add-hook 'help-mode (lambda () (setq viper-mode t)))

But none of these commands did work. In fact, the first one yielded the following error:

Warning (initialization): An error occurred while loading `/home/konrad/.emacs.d/init.el':

Wrong type argument: symbolp, (fundamental-mode ...

Besides the C-w C-w, I also miss not being able to navigate using hjkl. Isn't there a way to reuse the keybindings set by viper, instead of rebinding them again for every mode?


回答1:


The error is because you neglected to quote the variable viper-vi-state-mode-list like so:

(add-to-list 'viper-vi-state-mode-list 'help-mode)

See this question as to why you need to quote 'viper-vi-state-mode-list.

But, that didn't solve the problem for me, this is how I got C-w C-w to work the way you want:

(define-key help-mode-map (kbd "C-w C-w") 'vimpulse-cycle-windows)



回答2:


The syntax for adding the hook to help-mode would look like this:

(add-hook 'help-mode-hook (lambda () (viper-mode t)))

Note the hook variable is named with "-hook", and setq doesn't work here because viper-mode is a command, not a variable.

You might be able to get all modes to activate viper with:

(add-hook 'fundamental-mode-hook (lambda () (viper-mode t)))

since all modes inherit from fundamental-mode.




回答3:


Look at what I've found: http://www.emacswiki.org/emacs/viper-in-more-modes.el



来源:https://stackoverflow.com/questions/1855890/viper-mode-in-all-modes

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