• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
Source Digit

Source Digit

Linux, Ubuntu Tutorials & News, Technology, Gadgets & Gizmos

  • Home
  • How To
  • Ubuntu
  • Instagram
  • Blogging
  • Android
  • WordPress
  • +More
    • Cloud Computing
    • Gadgets
    • Social Media
    • Technology
  • Write for Us
Home / Ubuntu / How To Copy 4 Lines And Paste It To Another File In Vi Editor

How To Copy 4 Lines And Paste It To Another File In Vi Editor

By Sourabh / August 4, 2022 Category: How To, Ubuntu

Learn how to copy 4 lines and paste it to another file in vi editor. Here is how to cut, copy and paste in vi editor. Learn to cut and paste multiple lines in vi editor.

NOTE:

  • Vim has its own terms for copy, cut, and paste. Copy is called yank (y), cut is called delete (d), and paste is called put (p).
  • All of the following set of commands will only work when you are in command mode. Press the Esc key to enter the command mode – if you are in insert mode.

Yank or Copy

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 – Yank (copy) the current line. It will also include the newline character.
  • 3yy – Yank (copy) three lines. It will copy starting from the line where the cursor is present.
  • y$ – Yank (copy) everything from the start of the cursor to the end of the line.
  • y^ – Yank (copy) everything from the start of the cursor to the start of the line.
  • yw – Yank (copy) to the start of the next word.
  • yiw – Yank (copy) the current word (cursor positioned).

In simple words, yy yanks copies one line and 5yy yanks copies 5 lines.

Delete or Cut

In the normal mode of vi editor, d is the shortcut key for deleting text (to cut is known as to delete in vi). To cut, simply move the cursor to the desired position and press the d key.

  • dd – Delete or cut the current line. It will also include the newline character.
  • 3dd – Delete or cut three lines, starting from the line where the cursor is present.
  • d$ – Delete or cut everything from the cursor posotion to the end of the line.

In simple words, dd will delete one line and 5dd will delete 5 lines.

Put or Paste

To paste in vi editor, simply move the cursor to the desired location and press p to put or paste. When you press p it will paste the text after the cursor and if you press P it will paste before the cursor.

Primary Sidebar

Latest Posts

Ubuntu 25.04 ‘Plucky Puffin’ Is Available To Download

How to Login as Root User in Linux Terminal

Install Firefox In Ubuntu Terminal Command Line

How To Check Kernel Installed Date In Linux Ubuntu

How To List All Kernel Modules That Are Loaded In Ubuntu

Enable Ubuntu Auto Login Without Password

Download Ubuntu 25.04 Official Default Wallpapers

How To Fix Initramfs Error In Ubuntu Command Line

How To Check All Available Kernel Version In Linux Ubuntu

3 Best Artificial Intelligence Domain Name Generators

© 2025 Source Digit • Linux, Ubuntu Tutorials & News, Technology, Gadgets & Gizmos

  • Home
  • About
  • Privacy Policy
  • Terms & Conditions
  • Contact Us
  • Sitemap