Day 16 | Exploring the Vi Text Editor in Linux | DevOps Bootcamp

Day 16 | Exploring the Vi Text Editor in Linux | DevOps Bootcamp

introduction

The vi editor is a text editor that is commonly used in Unix-like operating systems, including Ubuntu. It's a powerful and versatile editor, but it can be a bit challenging to use if you're not familiar with its commands. Here are some of the essential commands you can use within the vi editor:

The vi editor is a text editor that is commonly used in Unix-like operating systems, including Ubuntu. It's a powerful and versatile editor, but it can be a bit challenging to use if you're not familiar with its commands. Here are some of the essential commands you can use within the vi editor:

  1. Opening a File:

    • To open a file: vi filename

    • To create a new file: vi newfilename

Modes:

    • Normal Mode: This is the default mode where you can navigate and perform various operations.

      • Insert Mode: This is where you can actually insert and edit text.

      • Command-Line Mode: This mode is used for executing various commands.

Switching Modes:

    • From Normal to Insert mode: Press i (for insert) or a (for append).

      • From Insert to Normal mode: Press Esc.

Saving and Quitting:

    • To save changes and stay in vi: Press Esc, then type :w.

      • To save changes and quit: Press Esc, then type :wq.

      • To quit without saving changes: Press Esc, then type :q!.

Basic Navigation (Normal Mode):

    • Move cursor left: h

      • Move cursor right: l

      • Move cursor up: k

      • Move cursor down: j

  1. Advanced Navigation (Normal

    • Mode):Move to beginning of line: 0 (zero)
  • Move to end of line: $

  • Move to beginning of file: gg

  • Move to end of file: G

Editing (Normal Mode):

    • Delete character: x

      • Delete current line: dd

      • Cut text: yy

      • Paste text: p

Search and Replace (Normal Mode):

    • Search: /search_term

      • Search and replace: :%s/search_term/replace_term/g

Undo and Redo (Normal Mode):

    • Undo: u

      • Redo: Ctrl + r

Copying and Pasting (Normal Mode):

    • Copy: yy

      • Paste: p

Deleting and Inserting (Normal Mode):

    • Delete word: dw

      • Delete to end of line: d$

      • Insert before cursor: i

      • Insert at beginning of line: I

      • Append after cursor: a

      • Append at end of line: A

Search and Navigate (Normal Mode):

    • Search for a word under the cursor: * (forward), # (backward)

      • Move to next occurrence: n (forward), N (backward)

These are just some of the basic and common commands you can use in the vi editor. Remember that vi has a lot more functionality and commands. If you're planning to use it frequently, it's a good idea to learn more about its features and commands. You can access its built-in documentation by typing :help in command-line mode.

Referance:

https://youtube.com/playlist?list=PLg6orTBNhcmcSPQA0rbs_p1dSvLkw4J2q&si=DP_0eMy9372aOgPL

Did you find this article valuable?

Support Aqib Hafeez(DevOps enthusiast) by becoming a sponsor. Any amount is appreciated!