Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete a word in Vim

Tags:

vim

I'm a vim user and I want to delete a keyword. I always use "dw" to delete specific keyword, but it sometimes doesn't work well. For example, I want to delete "valule123" in sample program.

ex) public void function(int valule123)

When I put my cursor is on "2", and then I input "dw", only part of keyword is deleted and the result is "val1". Why?

I tried another command, "daw". In this case, the result is just as expected! But what does "a" mean? I think "a" means "add".

like image 332
Akira Noguchi Avatar asked Sep 19 '13 01:09

Akira Noguchi


People also ask

How do I delete a specific word in Vim?

Go into insert mode (hit i) and use the Delete key to remove the phrase. Hit escape when you have deleted all of the phrase.

How do I quick delete in Vim?

Deleting a single line in Vim editor: First, bring your cursor to the line you want to delete. Press the “Esc” key to change the mode. Now type, “:d”, and press “Enter” to delete the line or quickly press “dd”.

How do you delete a specific word in Linux?

How do I match and remove (delete) the words “ssh_args=-p 1222” from config file using sed command under Linux or Unix like operating systems? You can use the the substitute sed command changes all occurrences of the “ssh_args=-p 1222”. The same command can be used to delete the required words.


1 Answers

The command/action/verb d in Vim acts on an object. For dw the object is "all text the cursor moves over with a w command". For daw you're actually using a Vim concept called a "text object". There are many of these, including aw (a word), as (a sentence), i} (inner {...} block, e.g. code within a block in C code), it (inner tag, useful for XML-like languages), and more.

See :help text-objects for the full list.

These can not only be used by the d command, but any command/action/verb that takes an object. For example, =aB will reindent an entire code block, cas will delete a sentence and drop you into insert mode to type a new one, and yit will yank/copy everything inside the current XML tag.

like image 138
Ben Avatar answered Oct 02 '22 03:10

Ben