From the course: Learning Vim
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Delete text
- [Instructor] Ken Thompson said, "One of my most productive days "was throwing away a thousand lines of code." Deleting text is an important part of writing, and Vim makes it easy. Can you guess the command for deleting text? It's d. Let's open persistence.txt, vim persistence.txt. And now to delete, type d. Nothing happens. The d command needs to know what to delete. Now type w. And the first word was deleted. dw stands for delete word. To undo, hit u. Now let's delete a sentence. Remember that the sentence motion is the closing braces, so d and closing braces. And again, u to undo. To delete a line, use dd. And again, u to undo. We can even use regular expression motion to delete. Let's delete everything up to genius. So, d and then /Genius and enter. Remember that d is for delete, and it should be followed by a motion command, such as w. To delete the current line, use dd.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
(Locked)
Delete text1m 16s
-
(Locked)
Challenge: Delete sentence5s
-
(Locked)
Solution: Delete sentence15s
-
Copy and paste2m 2s
-
(Locked)
Challenge: Copy and paste6s
-
(Locked)
Solution: Copy and paste15s
-
(Locked)
Change text1m 25s
-
(Locked)
Challenge: Change text13s
-
(Locked)
Solution: Change text16s
-
(Locked)
Visual selection1m 55s
-
(Locked)
Challenge: Use visual selection6s
-
(Locked)
Solution: Use visual selection21s
-
(Locked)
Registers2m 36s
-
(Locked)
Challenge: Use registers11s
-
(Locked)
Solution: Use registers46s
-
Replace text1m 7s
-
(Locked)
-
-
-
-
-