DEV Community

Chandu
Chandu

Posted on

Road to Vim Mastery Day 2

this post is continuation to road to mastery day 1.

if you are vim beginner like me, i recommend you to go practice at VimGenius website daily.

In the previous post we discussed about basic commands and navigational keys in vim.

In this post we will discuss about deletion commands.

dw

used to delete a word

Instructions to use dw command:

  1. press ESC to make sure you enter normal mode.
  2. use j(down) | h(left) | k(up)| l(right) to move cursor to the starting letter of the word that you want to delete.
  3. press dw to delete the word

when you press d you will able see d in the bottom right corner of your vim window which means vim is waiting for you to enter w to proceed further, if not press ESC to start again.

Example
suppose cursor is at letter a in apple

"apple makes you strong"

dw

"makes you strong"
now cursor is at letter m in makes.

note that the space between apple and makes is also deleted.

de

used to delete from cursor to the end of the word

Example
cursor at a in apple

"apple makes you strong"

de

" makes you strong"

now cursor is at space before word makes.

note that space before makes is not deleted

d$

used to delete from cursor to the end of the line

Example

cursor at e in apple

"apple makes you strong"

d$

"appl"

If you observe the commands we have used up to now, you can notice that in every delete command d stays static and successive letter or symbol changes. So let's look at some theory.

dd

used to delete whole line

Example

cursor at v in violets.

"
roses are red.
violets are blue.
"
dd

"
roses are red.
"

operators and motion

syntax : d _
d - delete operator
_ - motion is something operator will operate on like e,$,w,d

In the next post we will see how to use count or numbers to move cursor and delete multiple lines

Well that's it for day 2

Zed

Top comments (0)