To delete text in the vi editor, you can use several commands depending on what you want to delete. Here’s a concise guide on how to do it:
Deleting Text in vi
-
Delete a Single Character:
- In Normal Mode: Move the cursor to the character you want to delete and press
x. This will delete the character under the cursor.
- In Normal Mode: Move the cursor to the character you want to delete and press
-
Delete a Word:
- In Normal Mode: Move the cursor to the beginning of the word you want to delete and type
dw. This command deletes from the cursor position to the end of the word.
- In Normal Mode: Move the cursor to the beginning of the word you want to delete and type
-
Delete a Line:
- In Normal Mode: Move the cursor to the line you want to delete and type
dd. This will delete the entire line.
- In Normal Mode: Move the cursor to the line you want to delete and type
-
Delete Multiple Lines:
- In Normal Mode: Type
dfollowed by a number and thend. For example,3ddwill delete the next three lines starting from the current line.
- In Normal Mode: Type
-
Delete Until the End of the Line:
- In Normal Mode: Type
d$to delete from the cursor position to the end of the line.
- In Normal Mode: Type
Example Usage
-
To delete a single character:
- Move the cursor to the character and press
x.
- Move the cursor to the character and press
-
To delete a word:
- Position the cursor at the start of the word and type
dw.
- Position the cursor at the start of the word and type
-
To delete the current line:
- Type
dd.
- Type
Saving Changes
After deleting text, remember to save your changes by pressing Esc to return to Normal Mode and then typing :wq to save and exit.
Further Learning
For more advanced text manipulation in vi, consider checking out resources like:
- Vim Documentation: Comprehensive guide on all commands.
- Vim Tutor: A built-in tutorial that you can access by typing
vimtutorin your terminal.
If you have any more questions or need clarification on specific commands, feel free to ask! Your feedback is appreciated.
