Terminal Text Editors

Introduction

  • There are many different text editors in Linux, the most popular are, nano, vi, and vim.

  • to edit a file using any of these tools, type the tool name followed by the file name (i.e. nano <File Name>)

Nano

  • Nano is easy to use but has fewer features than Vi and also isn't installed by default.

  • To move through lines use the arrow keys.

  • To execute commands use the Ctrl button (Represented by ^ in Linux) followed by the letter for the command.

Available Commands

Vi

  • Installed by default on most Linux distributions.

  • Harder to use than Nano but has more features (Especially Vim)

  • There are 2 modes in Vi:

    • Insert: In Insert mode, you can enter text, use the Enter key to go to a new line, use the arrow keys to navigate text, and use vi as a free-form text editor.

    • Command: Command mode means you can use keyboard keys to navigate, delete, copy, paste, and do a number of other tasks—except entering text.

  • When Vi is started, it's in the command mode.

  • To go to the insert mode, press on the i button.

  • To go to the command mode from the insert mode press the Esc key.

  • This is a list of some of Vi's commands:

    • i — Switch to Insert mode.

    • Esc — Switch to Command mode.

    • :w — Save and continue editing.

    • :wq or ZZ — Save and quit/exit vi.

    • :q! — Quit vi and do not save changes.

    • yy — Yank (copy) a line of text.

    • p — Paste a line of yanked text below the current line.

    • o — Open a new line under the current line.

    • O — Open a new line above the current line.

    • A — Append to the end of the line.

    • a — Append after the cursor’s current position.

    • I — Insert text at the beginning of the current line.

    • b — Go to the beginning of the word.

    • e — Go to the end of the word.

    • x — Delete a single character.

    • dd — Delete an entire line.

    • Xdd — Delete X number of lines.

    • Xyy — Yank X number of lines.

    • G — Go to the last line in a file.

    • XG — Go to line X in a file.

    • gg — Go to the first line in a file.

    • :num — Display the current line’s line number.

    • h — Move left one character.

    • j — Move down one line.

    • k — Move up one line.

    • l — Move right one character.

Last updated