2.1 KiB
2.1 KiB
VIM Guide: Copy, Paste, and Find/Replace Operations
1. Copy and Paste Lines
Copy a Single Line
- In normal mode, move the cursor to the line you want to copy.
- Press
yyto yank (copy) the entire line.
Paste the Copied Line
- Move the cursor to where you want to paste the copied line.
- Press
pto paste after the current line orPto paste before the current line.
2. Copy and Paste Words
Copy a Word
- Move the cursor to the beginning of the word you want to copy.
- Press
yiwto yank (copy) the word under the cursor.
Paste the Copied Word
- Move the cursor to the desired insertion point.
- Press
pto paste after the cursor orPto paste before the cursor.
3. Copy and Paste Paragraphs
Copy a Paragraph
- Move the cursor to any point within the paragraph you wish to copy.
- Press
yapto yank (copy) the entire paragraph, including the trailing newline.apstands for "a paragraph".
Paste the Copied Paragraph
- Move the cursor to where you want to paste the paragraph.
- Press
pto paste after the current position orPto paste before.
4. Find and Replace
Find and Replace in the Entire Document
- Press
Escto ensure you are in normal mode. - Type
:%s/old/new/gand pressEnter.:%sis the substitute command for the entire file.oldis the text to find.newis the text to replace it with.gis the global flag, replacing all occurrences in each line.
Find and Replace in the Current Line
- With the cursor on the line you want to modify, type
:s/old/new/gand pressEnter.
Find and Replace with Confirmation
- To replace with confirmation for each occurrence, add
cat the end::%s/old/new/gc.
These commands provide a solid foundation for navigating and editing text within VIM, covering basic copying, pasting, and find/replace operations. Remember to always start in normal mode before executing these commands. With practice, these operations will become second nature, allowing you to efficiently edit and manipulate text in VIM.