Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How to Copy, Cut and Paste in Vim / Vi - DesignLinux

Sep 03 2020
designlinux 0 Comments
How to Copy, Cut and Paste in Vim / Vi

It is common action to do copy, cut and paste text when working with the text files. Vim is a text editor which is comes preinstalled on macOS and almost all Linux distributions. It’s good to have basics of Vim if your favorite editor is not available. In this article we will show you how to copy, cut, and paste in Vim / Vi editor.

Copy, Cut and Paste in Normal Mode#

By default, your are in normal mode when you launch the Vim editor. In this mode, you can run Vim commands and navigate through the file.

Just press Esc key to switch back to normal mode from any other mode. Vim has its own terms for copying, cutting, and pasting. Copy is called yank (y), cut is called delete (d), and paste is called put (p). Let’s see each in brief:

Copying (Yanking)#

To copy text, place the cursor in the desired location and press the y key followed by the movement command. Below are some helpful yanking commands:

  • yy – Copy the current line, including the newline character.
  • 3yy – To copy three lines, starting from the line where the cursor is positioned.
  • y$ – You can copy everything from the cursor to the end of the line.
  • y^ – Copy everything from the cursor to the start of the line.
  • yw – Yank (copy) to the start of the next word.
  • yiw – Copy the current word.
  • y% – To copy to the matching character. By default supported pairs are (), {}, and [].

Cutting (Deleting)#

To cutting the text you should use d key. Place the cursor at the desired position and press d key. Below are some helpful deleting commands:

  • dd – It will cut or delete the current line, including the newline character.
  • 3dd – To delete or cut three lines, starting from the line where the cursor is positioned.
  • d$ – Delete or cut everything from the cursor to the end of the line.

The movement commands that apply for yanking are also valid for deleting. For example dw, deletes to the start of the next word and d^ deletes everything from the cursor to the start of the line.

Pasting (Putting)#

Move the cursor at the desired place to paste the yanked or deleted text and press p to put the text after the cursor or P to paste before the cursor.

Copy, Cut and Paste in Visual Mode#

Vim’s visual mode allows you to select and manipulate text.

1. Move the the cursor on the line you want to begin copping or cutting.

2. There are three subtypes in the visual mode:

  • Press v to enter the visual mode
  • To enter visual line mode press V, where the text is selected by line.
  • Press Ctrl+v to enter visual block mode. In this mode, the text is selected by rectangle blocks.

3. Move the cursor to the end of the text you want to copy or cut. You can use a movement command or up, down, right, and left arrow keys

vim-copy-paste-visual

4. To copy press y, or d to cut the selection.

5. Place the cursor to the location where you want to paste the contents.

6. Press P to paste the contents before the cursor, or p to paste it after the cursor.

Conclusion#

In this article explained how to copy, cut, and paste in Vim text editor. To know more about Vim, visit the Open Vim site.

If you have any questions or feedback, you can leave a comment below.

Related

Tags: terminal, vim

How to Install Chromium Web Browser on Ubuntu 20.04

Prev Post

How to Open Port for a Specific IP Address in Firewalld

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 0
  • 97
  • 568,937

DesignLinux.com © All rights reserved

Go to mobile version