Enhancing Skills

nano, vi, vim: Text editors for creating and editing files

Commands: nano, vi, vim

These are text editors used for creating and editing files in the command line. Each editor has its own features and usage:


Nano

Command: nano

A simple, user-friendly text editor. It provides on-screen help and straightforward keyboard shortcuts.

Sample Command and Output:

$ nano file.txt

Description:

  • nano file.txt: Opens file.txt in the Nano editor. You can edit the file and use keyboard shortcuts to manage the file.

Common Commands:

  • Ctrl+O: Save the file.
  • Ctrl+X: Exit Nano.
  • Ctrl+K: Cut the current line.
  • Ctrl+U: Paste the cut line.
  • Ctrl+W: Search within the file.
  • Ctrl+G: Display help.

Vi

Command: vi

A traditional text editor with a steeper learning curve. It operates in different modes, including command mode and insert mode.

Sample Command and Output:

$ vi file.txt

Description:

  • vi file.txt: Opens file.txt in the Vi editor. Initially, you start in command mode. Press i to enter insert mode for editing. Press Esc to return to command mode, and use :wq to save and quit, or :q! to quit without saving.

Common Commands:

  • i: Enter insert mode.
  • Esc: Return to command mode.
  • :w: Save the file.
  • :q: Quit (use :q! to quit without saving).
  • dd: Delete the current line.
  • yy: Copy the current line.
  • p: Paste the copied or deleted line.
  • /search_term: Search for search_term.

Here are additional commands for the vi text editor to help you navigate and edit files more effectively:

Navigation: (I mostly use the arrow keys)

  • h: Move the cursor left.
  • j: Move the cursor down.
  • k: Move the cursor up.
  • l: Move the cursor right.
  • 0: Move to the beginning of the line.
  • $: Move to the end of the line.
  • G: Move to the end of the file.
  • gg: Move to the beginning of the file.
  • :n: Move to line n.

Editing:

  • x: Delete the character under the cursor.
  • r: Replace the character under the cursor with another character.
  • cw: Change the word from the cursor position.
  • cc: Change the entire line.
  • o: Open a new line below the current line and enter insert mode.
  • O: Open a new line above the current line and enter insert mode.
  • u: Undo the last action.
  • Ctrl+r: Redo the undone action.

Copying and Pasting:

  • yy: Yank (copy) the current line.
  • y: Yank (copy) a specified number of lines (e.g., 3yy).
  • p: Paste the yanked or deleted text after the cursor.
  • P: Paste the yanked or deleted text before the cursor.

Searching and Replacing:

  • /search_term: Search forward for search_term.
  • ?search_term: Search backward for search_term.
  • n: Repeat the search in the same direction.
  • N: Repeat the search in the opposite direction.
  • :s/old/new: Replace the first occurrence of old with new on the current line.
  • :s/old/new/g: Replace all occurrences of old with new on the current line.
  • : %s/old/new/g: Replace all occurrences of old with new in the entire file.

File Management:

  • :w: Save the file.
  • :q: Quit the editor (use :q! to quit without saving).
  • :wq: Save and quit the file.
  • :x: Save and quit the file (same as :wq).
  • :e filename: Open a new file filename.
  • :w filename: Save the file under a new name filename.

Miscellaneous:

  • :!command: Execute a shell command (!ls to list files).
  • :r filename: Read the content of filename and insert it after the current line.
  • :set number: Display line numbers.
  • :set nonumber: Hide line numbers.

Vim

Command: vim

An enhanced version of Vi with additional features and improvements. Vim stands for “Vi Improved.”

Sample Command and Output:

$ vim file.txt

Description:

  • vim file.txt: Opens file.txt in the Vim editor. Like Vi, Vim starts in command mode. Press i to enter insert mode for editing. Use :wq to save and quit, or :q! to quit without saving. Vim offers advanced features like syntax highlighting and extensibility.

Common Commands:

  • i: Enter insert mode.
  • Esc: Return to command mode.
  • :w: Save the file.
  • :q: Quit (use :q! to quit without saving).
  • dd: Delete the current line.
  • yy: Copy the current line.
  • p: Paste the copied or deleted line.
  • /search_term: Search for search_term.
  • :set number: Show line numbers.
  • :syntax on: Enable syntax highlighting.

Feel free to ask if you need more details about any specific commands or features!


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.