An easy way to copy, cut and paste in Vim / VI

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 Esc.

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 (p).

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.
  • 3yy Yank (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 (), {}And and []. 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.

Paste (put)

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.

  1. Position the pointer over the line where you want to crop.
  2. Visual mode has three subtypes.
    • Tekan v To enter the visual mode.
    • Journalism V To enter Visual Font mode, where text is selected by line.
    • Journalism Ctrl+v To 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.

  3. 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.
    Visually copy paste
  4. Journalism y For copying or d For the distinctive cut.
  5. Move the cursor to where you want to paste the content.
  6. Journalism P (Large P) for pre-pointer content, or p (Small P) to paste past the pointer.

Conclusion

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.

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *