From the course: Learning Vim
Copy and paste
- [Instructor] Sometimes you'd like to add similar text to another part of a document. You do it quickly by copy and paste. Can you guess what the command for copy is? It's "y" which stands for yank. See what's taken for change action. Open time dot text, vim time dot text. Now let's copy the first word, y w yank word. Not to have the word in a vim register, known as for as the clipboard, we can use p to paste it, p. This looks funny, p pastes the text right after where the cursor is. The cursor was on the t, so we paste it inside the initial there. Let's undo with u. Now let's try pasting with capital p, shift p. This time the text was pasted before the current cursor. To copy a whole line, use y y, and then paste it with p. You could use many other motions command with y. If you would like to delete one character, you can use x, which deletes the character under the cursor, and place it in a register. I tend to make typos when letters are in the wrong order. Move to the end of the file with shift g, and then enter insert mode with o. Now let's write some text. I'd like to receive notifications. Then we notice the spelling for receive is wrong. Vim has spellchecker integration, but it's not enabled by default since people use vim to edit code and configuration, where most of the content is not regular English words. Move to the error with backward search. First hit escape, and then question mark i e, and enter. And now, hit x p, we deleted the character and pasted it after the cursor. This swaps the current character with the next one, very handy.
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)
-
-
-
-
-