From the course: Learning Vim

Copy and paste - vi Tutorial

From the course: Learning Vim

Start my 1-month free trial

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.

Contents