Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Move to end of the current word in Vim

Tags:

vim

Usually I use ea to append something to a word; however, this doesn't work if the cursor is already in the last position of the word.

ea will cause the cursor to move to the end of the next word.

I'm interested to know whether there is any hotkey for moving to the end of current word even if the cursor is already in the last position of the word.

Thanks.

like image 406
Cyker Avatar asked Sep 19 '12 04:09

Cyker


People also ask

How do I jump to the next word in vim?

You'll find that Shift-Left/Right and Ctrl-Left/Right will do the trick. Now use CTRL-H and CTRL-L to move by word in insert mode.

How do you go to the last letter in vim?

You can use A to move to the end of the line and switch to editing mode (Append). To jump the last non-blank character, you can press g then _ keys. The opposite of A is I (Insert mode at beginning of line), as an aside.

How do you jump to the last line in vi?

If you're already in vi, you can use the goto command. To do this, press Esc , type the line number, and then press Shift-g . If you press Esc and then Shift-g without specifying a line number, it will take you to the last line in the file.

How do I move text to the next line in vim?

I know that pressing 'o' in normal or visual mode moves the cursor to a new line and switches the mode to insert.


2 Answers

  • w moves you to the beginning of the next word
  • e moves you to the last letter of the word
  • i lets you start editing right where the cursor is
  • a lets you start editing one character ahead

In your situation, it seems like you want a consistent way to append to a word, even if you're on the last letter. I'd switch to using wi instead of ea

I advise against remapping the basic vim movement controls, they are the way they are for a reason.

like image 157
Stephan Avatar answered Sep 23 '22 04:09

Stephan


You can change the functionality of e if you desire. For example, you could put

nnoremap e he 

in your ~/.vimrc. This maps e to he so that it works the way you want. However, you may find e useful and not want to make over it completely. You could use your <leader> key to add an alternate mapping.

nnoremap <leader>e he 

So that you can use \e or ,e (depending on your mapleader setting) to achieve the desired effect. I tend to agree with the others that it's better to become used to vim's standard single keys though. In general, use maps for longer commands that you regularly use.

There's no builtin command like the one you're suggesting, but there is regex \> for the end of a word.

like image 26
Conner Avatar answered Sep 22 '22 04:09

Conner