views:

90

answers:

2

Hi,

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.

+3  A: 

Mostly a duplicate of this, which says:

(require 'misc)

Then bind whatever keys you want to forward-to-word and backward-to-word. For killing, create some simple functions that wrap these functions and do kill.

scottfrazer
I saw the other post before, but as you see I was asking for a different thing (related to the same topic), so your answer does not help in this.
fikovnik
A: 

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)
Trey Jackson