Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between de and dw in vim?

Following vimtutor tips I found the following in Lesson 2.3:

Many commands that text are made from an operator and a motion.
The format for a  follows:

      d   motion

Where:
  d      - is the delete operator.
  motion - is what the operator will operate on (listed below).

A short list of motions:
  w - until the start of the next word, EXCLUDING its first character.
  e - to the end of the current word, INCLUDING the last character.
  $ - to the end of the line, INCLUDING the last character.

However, I don't see the difference between dw and de. What's the use case when using dw and de?

like image 689
GhitaB Avatar asked Oct 03 '14 07:10

GhitaB


People also ask

What does DW do in Vim?

dw will delete from cursor to beginning of next word, so will not delete the entire current word under the cursor unless the cursor happens to be at the beginning of the word. So bdw will delete the whole word and the space(s) after it (unless the cursor is already at the beginning of the word).

What does D mean in Vim?

The basic delete command is d , and you can combine it with movement commands: move to next word is w , delete to next word is dw ; move to next paragraph is } , delete to next paragraph is d} and so on. As a special shortcut, dd deletes a line. You can delete three lines with 3dd .

What is the difference between Q and Q in Vim?

When you have some changes and use :q , it fails and throws an error stating No write since last change . In order to quit from the Vim without saving changes, you should write :q! , it will quit the Vim and ! will work as a negation, which will negate the write operation.

What does CW command do?

The cw command preprocesses any specified troff files containing English-language text to be typeset in the constant-width (CW) font. The cw command reads standard input if you do not specify a file or if you specify a - (minus sign) as one of the input file names. The cw command writes to standard output.


1 Answers

dw means "cut from here to next word".

before: fo[o]bar baz
        dw
after:  fo[b]az

de means "cut from here to the end of the current word".

before: fo[o]bar baz
        de
after:  fo[ ]baz
like image 195
romainl Avatar answered Sep 28 '22 02:09

romainl