作者:莣Q楽 | 来源:互联网 | 2023-09-09 00:14
Iamlongtime-vimuserandrecentlydiscoveredthatemacshasviper-mode,offeringbestofbothwor
I am long time-vim user and recently discovered that emacs has viper-mode, offering best of both worlds (at least for me). However one thing is really bothering me since I am mostly coding in python and mixing of tabs and spaces is a big deal.
我很长时间用户,最近发现emacs有viper-mode,提供两全其美(至少对我而言)。然而有一件事真的困扰我,因为我主要是在python编码,并且标签和空格的混合是一个大问题。
When in insert mode I would like to insert viper-shift-width spaces instead of TAB when I press TAB. How can I do this? I suppose some simple lisp function/setting is the solution.
当处于插入模式时,我想在按TAB时插入viper-shift-width空格而不是TAB。我怎样才能做到这一点?我想一些简单的lisp函数/设置就是解决方案。
I didn't find anything in viper-mode settings that could do this.
我没有在viper模式设置中找到任何可以执行此操作的内容。
Edit:
I have (setq-default indent-tabs-mode nil)
in my .emacs but this doesn't work when I am in insert mode (in vim meaing of insert mode) in viper-mode
我的.emacs中有(setq-default indent-tabs-mode nil)但是当我在viper-mode中处于插入模式(在插入模式的vim meaing中)时这不起作用
2 个解决方案
First, you should ensure the default value of 'indent-tabs-mode
is nil
, like so:
首先,您应确保'indent-tabs-mode的默认值为nil,如下所示:
(setq-default indent-tabs-mode nil)
Then, in viper-mode
, it also depends on your viper-expert-level
. At level 1 or 2, TAB
appears to be bound to 'self-insert-command
via the mode map viper-insert-diehard-minor-mode
(which is enabled when the expert level is either 1 or 2). I guess that it is trying to provide maximal vi compatibility, which means you sacrifice some Emacs features, including the use of some pretty basic customizations.
然后,在viper模式下,它还取决于你的viper-expert级别。在级别1或2,TAB似乎通过模式映射viper-insert-diehard-minor-mode(在专家级别为1或2时启用)绑定到'self-insert-command。我想它正试图提供最大的vi兼容性,这意味着你牺牲了一些Emacs功能,包括使用一些非常基本的自定义。
So... you can up your expert level to 3 or higher:
所以...你可以将你的专家水平提高到3或更高:
(setq viper-expert-level 5) ; really, why use anything less?
If you really want level 1 or 2, but want TAB to not be a self inserting command, then add this to your .viper file:
如果您确实需要1级或2级,但希望TAB不是自插入命令,请将其添加到.viper文件中:
(define-key viper-insert-diehard-map (kbd "TAB") 'viper-insert-tab)
That does the trick for me, even on level 1.
这对我来说很有用,即使是在第1级。