If the cursor is placed on a whitespace and there're multiple whitespaces between 2 words, how can I move the cursor backwards to the end of the 1st word?
You could call
forward-whitespace with a negative prefix argument. You can bind this to a key with a lambda. For example, bind it to
(global-set-key (kbd "M-B") (lambda () (interactive) (forward-whitespace -1)))
- move cursor to the beginning of the first word with
- and then move forward with
forward-word), which place cursor after the end of the first word.
For example (
* means point):
0: first * second 1: *first second 2: first* second
If you want always go to the end of the word when moving backward, then use in
(defun backward-word-end () "Move backward to the end of the word." (interactive) (backward-word 2) (forward-word)) (global-set-key (kbd "M-b") 'backward-word-end)
P.S. But don't forget about
bind-key if you use