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.

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