When working with text files, copying, cutting, and pasting text is one of the most common tasks.
Vim, or its predecessor Vi, is preinstalled on macOS and most Linux distributions. Knowing the basics of Vim is useful in situations where your preferred text editor is not available.
This article shows you how to copy, cut, and paste in the Vim / Vi editor.
Copy, cut and paste in normal mode
When you launch the Vim Editor, you are in normal mode. In this mode, you can run Vim commands and move between files.
To return to normal mode from another mode, just press the button
Vim has its own copy, cut and paste terms. A version called yank (
y), The pieces are called delete (
d), And pasting is called putting (
To copy text, place the cursor where you want it and press the button
y Followed by additional commands. Here are some commands to help you transcribe text:
yy– Yank (copy) the current line, including the newline characters.
3yyYank (copying) three lines, starting with the line on which the cursor is located.
y$– Yank (copy) everything from the cursor to the end of the line.
y^Yank (copy) everything from the cursor to the beginning of the line.
yw– Yank (copy) the text to the beginning of the next word.
yiw– Yank (copy) the current word.
y%– Yank (copy) to match character. By default, the supported pairs are
. Useful for copying text between matching parentheses.
In normal mode,
d The key is to cut (delete) the text. Move the cursor to the desired position and press the button
d, Followed by additional commands. Here are some additional helpful commands:
dd– Delete (cut) the current line, one line will be deleted.
3dd– Delete (cut) three lines, starting with the one where the cursor is,
d$Delete (cut) everything from the cursor to the end of the line.
Additional commands that apply to stripping also apply to deletion (deletion). For example
dw, Delete to the beginning of the next word and
d^ Removes everything from the cursor to the beginning of the line.
To place your drawn or deleted text, move the cursor to the desired location and click
p To place (paste) text after the cursor or
P To put (paste) before the cursor.
Copy, cut and paste in visual mode
Vim’s visual mode lets you select and manipulate text.
- Position the pointer over the line where you want to crop.
- Visual mode has three subtypes.
Tekan vTo enter the visual mode.
VTo enter Visual Font mode, where text is selected by line.
Ctrl+vTo enter visual blocking mode. In this mode, the text is outlined by a rectangular block.
Entering Visual Mode is also the starting point for selection.
- Move the pointer to the end of the text that you want to copy or cut. You can use gesture commands or the up, down, right, and left arrow keys.
yFor copying or
dFor the distinctive cut.
- Move the cursor to where you want to paste the content.
P(Large P) for pre-pointer content, or
p(Small P) to paste past the pointer.
In this guide, we showed you how to copy, cut and paste in Vim.
If you want to get to know Vim more, visit the Open Vim website, where you can practice Vim with interactive tutorials.