How to Copy, Cut, Paste in Vim or Vi

Table of Contents
Copy, Cut, Paste in Vim
Vim is one of the popular text editors among the software developers and system administrators. On the macOS as well as on different Linux Distros it comes preinstalled. When you work with Vim copy paste or cut pasting text is one of the common tasks we do most of the time. In this tutorial, you are going to learn how to Copy, Cut, Paste in Vim or Vi.
Copy, Cut, Paste in Visual Mode
If you are in any other mode press Esc
to come in Normal Mode so you can run Vim commands and navigate through the file.
- Place the cursor at the line where you want to start copying or cutting.
- Here you can press
v
(lowercase) to start copy from the position where the cursor located or pressV
(uppercase) to copy full line where cursor located. - Now use h, j, k, l keys to move the cursor left, down, up, right where the end of text located.
- Here you can press
y
to copy text or pressd
to cut text. - Then place the cursor where you want to paste the text.
- Finally, press
p
(lowercase) to paste the text after cursor position and pressP
(uppercase) to paste the text before the cursor position.
You can do Copy-Paste or Cut Paste operations by using the above instructions. If you want to learn more short commands for copying to cutting text then read below points.
Copying or Yanking in Vim
The process of copying also known as yanking in Vim. To copy the text you can also use the following commands directly in Normal Mode.
yw | Copy the text to the start of next word |
yiw | Copy the current word where the cursor is located. |
y$ | Copy text from the cursor to the end of the line. |
yy | Copy the current line with the newline character. |
3yy | Copy three lines from the line where the cursor is located. |
4yy | Copy four lines from the line where the cursor is located. |
y% | Copy text until matching pair character like (), [], {}. |
y^ | Copy text from the cursor to the start of the line. |
Cutting or Deleting in Vim
The process of cutting also known as deleting in Vim. To cut the text you can also use the following commands directly in Normal Mode.
dw | Cut the text to the start of the next word. |
diw | Cut the current word where the cursor is located. |
d$ | Cut text from the cursor to the end of the line. |
dd | Cut the current line with the newline character. |
3dd | Cut three lines from the line where the cursor is located. |
4dd | Cut four lines from the line where the cursor is located. |
d% | Cut text until matching pair character like (), [], {}. |
d^ | Cut text from the cursor to the start of the line. |
Paste in Vim
You can paste the text in Vim using p
key to paste after the cursor position and P
to paste before the cursor position.
Conclusion
In this tutorial, you have learned How to Copy, Cut, Paste in Vim or Vi. If You have any queries regarding this please comment below.
LATEST POSTS
-
How to install PHP 7.2 on Debian 9
-
How to Install WordPress with LAMP Stack on Ubuntu 18.04
-
Secure Apache with Let’s Encrypt SSL on CentOS 7
-
How to Install Opera Browser on Linux Mint 19
-
How to install Node.js with npm on Debian 9
-
How to Install Kodi on Ubuntu 18.04
-
How to Install Gradle on CentOS 7
-
How to Install Eclipse IDE on Linux Mint 19
-
How to Install IntelliJ IDEA IDE on Linux Mint 19
-
How Install Redis on CentOS 8
-
How to Install PhpStorm on Linux Mint 19
-
How to Install RubyMine on Manjaro 18