Text Editor Facts

The vi Editor

  • Initial mode is Command mode for executing commands.

  • Edit mode allows writing and modifying text.

    • Insert mode: adds text.

    • Replace mode: overwrites text.

Importance

  • Text editors are crucial for configuring Linux systems that lack a GUI.

The vim Editor

  • vi or vim is the primary command-line text editor for Linux distributions.

    • Vim stands for "Vi Improved" with extended functionalities.

    • vi and vim interfaces are similar, leading to interchangeable use of names.

Common vi Commands

Command

Function

vi

Starts vi.

vi [file_name]

Opens a specific file (new or existing).

i

Enters insert mode.

Esc

Enters command mode.

Delete

Deletes text.

# [line_number]

Jumps to a specific line in the document.

dw

Cuts a word and trailing space.

de

Cuts a word omitting trailing space.

d$ or D

Cuts from cursor to end of line.

dd

Cuts the entire line.

p

Paste text from memory.

u

Undo last action.

Additional vi Commands

Command

Function

O

Opens a new line above.

o

Opens a new line below.

Ctrl+g

Displays file info (name, lines, cursor position).

/[term]

Searches forward for a term.

?[term]

Searches backward for a term.

yy

Copies current line to memory.

a

Appends text after cursor.

A

Appends after the current line.

C

Changes text to end of line.

cc

Changes entire line text.

ZZ

Saves and exits vi.

h/j/k/l

Moves cursor left/down/up/right respectively.

The nano Editor

  • Starts with nano at the shell prompt.

  • More user-friendly compared to vi.

Nano Shortcuts

Shortcut

Function

^G

Displays help text.

^X

Exits nano.

^O

Saves the current buffer to disk.

M-Space

Goes back one word.

^Space

Goes forward one word.

M-A

Marks text from cursor.

^K

Cuts line or marked region to cut buffer.

^U

Pastes from cut buffer.

Choosing a Text Editor

  • Availability: vi is in all distributions; nano in most.

  • Licensing: vi (BSD/ CDDL), nano (GNU GPL).

  • Interface Complexity: vi is less intuitive; nano is user-friendly.

  • Feature Set: vi is complex; nano is basic.

  • Learning Curve: vi has a steeper learning curve compared to nano.

Recommendation

  • For beginners: choose nano for simplicity.

  • For advanced features: use vi.