Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a word and go into insert mode in Vim?

Tags:

vim

In normal mode I can hit Ctrl + E which deletes the rest of the current word and goes to insert mode.

I want to delete the entire word, regardless of the cursor position (within the word of course).

like image 926
Joernsn Avatar asked Sep 04 '09 13:09

Joernsn


People also ask

How do you delete a character in vim insert mode?

Ctrl-O in insert mode will allow you to run a single normal mode command and automatically return back to insert mode. x deletes the key under the cursor.

How do I start vim in insert mode?

Open a new or existing file with vim filename . Type i to switch into insert mode so that you can start editing the file. Enter or modify the text with your file. Once you're done, press the escape key Esc to get out of insert mode and back to command mode.


2 Answers

You can use "change inner word" by typing "ciw" to delete a word your cursor is on.

The "inner" and "a" commands are great in Vim, also try "ci{" inside a {} block, or "ca{" if you also wish to remove the {} characters too. To translate these commands to English to remember them better, try: "change inner { block" and "change a { block".

Documentation at http://vimdoc.sourceforge.net/htmldoc/motion.html#text-objects

like image 50
Kaali Avatar answered Sep 29 '22 18:09

Kaali


Answer to your follow-up question: viwp

v    -> start visual mode iw   -> select the 'inner word' p    -> paste - in visual mode it replaces the visually selected text. 
like image 36
too much php Avatar answered Sep 29 '22 17:09

too much php