• 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

Delete Directory And Contents Recursively Without Prompt On Linux

Check User Login History In Ubuntu Linux Command Line

Use Locate Command To Find File In Linux Terminal By Name

How To Change Terminal Color In Ubuntu Command Line

How To Run Fsck Manually In Linux To Fix Unexpected Inconsistency

How To Fix Broken Packages On Ubuntu From Terminal

Re Execute The Previous Command In Linux Ubuntu Command Line

How Much RAM Is Needed For Ubuntu PC

How To Find Large Files And Directories In Linux Command Line

How To Use Clear Command History In Linux Terminal

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

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