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

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

问题描述

在 vim 中对单词来回导航具有相同行为的最简单方法是什么?在 vim 中,当您按w"时,它会将光标向前移动一个单词,其中单词由一系列字母、数字和下划线或一系列其他非空白字符组成,以空格分隔(空格、制表符、eol).另一方面,在 emacs 中,它会一直跳到下一个单词的结尾,并且该单词在语法表中按模式定义.

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.

例如:在以下行的开头有一个光标显示了当您执行forward-word ("w") 操作时vim 放置光标的位置:

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
^   ^^   ^ ^   ^^  ^

在 emacs 中是这样的:

In emacs it is like:

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

这真的取决于个人喜好,但我倾向于更喜欢 vim 风格,我想知道在 emacs 中使用相同风格的最简单方法是什么.我想我不是唯一一个从 vim 切换到 emacs 的人,所以也许有人已经有了解决方案,非常适合 kill-wordbackward-kill-word 以及:)

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 :)

我知道你可以通过 M-fM-b 等组合得到类似的东西,但这不是重点.我也不想开始讨论哪种方法更好 - 在 这里.

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.

推荐答案

你其实可以使用'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天全站免登陆