修改emacs前进/后向行为(就像在vi / vim中) [英] Modifying emacs forward-word / backward-ward behavior (to be like in vi/vim)

查看:153
本文介绍了修改emacs前进/后向行为(就像在vi / vim中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在vim中使用相同类型的行为是最简单的方式来回传和导航?在vim中,当您按 w 时,将光标向前移动一个字,其中单词由一系列字母,数字和下划线组成,或其他非空白序列字符,用空格分隔(空格,制表符,eol)。另一方面,在emacs中,它跳过直到下一个单词的结尾,并且在语法表中每个模式定义单词。



例如:在以下行的开头显示当您执行 forward-word w )时,vim放置光标)操作:

  opt1.arg = opt2.arg 
^ ^^ ^ ^ ^^ ^

在emacs中,它就像:

  opt1.arg = opt2.arg 
^ ^ ^ ^ ^

根据自己的喜好,但我倾向于更喜欢vim风格,我想知道在emacs中使用相同的最简单的方法是什么。我想我不是一个人从vim切换到emacs,所以也许有人已经有了一个解决方案,理想情况下,对于 kill-word 我们知道你可以通过 Mf Mb 等,但这不是重点。我也不想开始讨论哪种方法更好 - topis在 here

解决方案

你实际上可以使用'viper-forward-word

 (require'viper)
(global-设置密钥(kbdMf)'viper-forward-word)
(全局设置密钥(kbdMb)'viper-backward-word)


What would be the easiest way to have the same kind of behavior that is in vim for the word back and forth navigation? In vim when you press "w" it moves a cursor forward one word, where word consists of a sequence of letters, digits and underscores, or a sequence of other non-blank characters, separated with white space (spaces, tabs, eol). In emacs on the other hand it skips until the end of the next word and the word is defined per mode in the syntax table.

For example: having a cursor at the beginning of the line following shows where vim put a cursor when you do forward-word ("w") operation:

opt1.arg = opt2.arg
^   ^^   ^ ^   ^^  ^

In emacs it is like:

opt1.arg = opt2.arg
^   ^   ^      ^   ^

It really depends on a one's preference, but I tend to like the vim style better and I was wondering what is the easiest way to have the same in emacs. I guess I'm not alone who switched from vim to emacs so perhaps someone already has a solution, ideally for the kill-word and backward-kill-word as well :)

I know you can get something similar by combination of M-f, M-b etc., but that is not the point. I also don't want to start a discussion which approach is better - the topis is well discussed in here.

解决方案

You can actually use 'viper-forward-word

(require 'viper)
(global-set-key (kbd "M-f") 'viper-forward-word)
(global-set-key (kbd "M-b") 'viper-backward-word)

这篇关于修改emacs前进/后向行为(就像在vi / vim中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆