Welcome to Team5 Unix Live

Text Editing

Text Editing

Using and Installing vim

Writing and editing files are very important in Linux because it allows you to configure system setting files to your liking. There are many text editing tools, however, in this lesson we will be using Vim. Vim is a powerful text editor that can be accessed right from the command line!
To get started, download Vim using the command line.
Sudo apt install vim

Installing Vim

To use Vim, just type in the command with the file name. The following screen should load.

Vim [filename]

Vim

There are many modes in vim. The most common ones are insert mode, visual mode, and command mode.
Insert mode allows you to edit the file. To enter insert mode, simply type in the letter “i”
Visual mode allows you to select text to cut, copy, paste, or delete. To enter visual mode, type in the letter “v”.
Command mode perform keystrokes as commands. To enter command mode, hit the Esc key.
File commands are important command because they allow you to exit and save the file. These commands start with “:”.

  • :w- writes file to the disk (save file).
  • :q- quit without saving.
  • :wq- save file and quit.
  • :q!- ignore warning and quit without saving.
    • Vim file save

      These are some helpful commands.

      Moving cursor commands:

      • h- move cursor to the left.
      • j- move cursor down.
      • k- move cursor up.
      • l- move cursor to the right.
      • 0- move to the beginning of the line.
      • $- move to the end of the line.
      • y- copy the selected text.
      • yy- copy current line.
      • I- insert text in the beginning of the line.
      • P-insert text in front of the cursor.
      • p- insert text after the cursor.

      Deleting Text:

      • X- delete the character in front of the cursor.
      • x- delete the character after the cursor.
      • dd- cut current line.

      Undo/Redo:

      • u- undo
      • ctrl+r- Redo

      Let’s say you want to see the contents of a file without using a text editor. Here are some ways to output contents of a file:

      cat- stands for concatenate and displays all contents of a file.

      cat [option] [filename]

      cat

      head- displays the first few lines of a file.

      head [-number of lines] [filename]
      head

      tail- displays the last few lines of a files.

      tail [-number of lines] [filename]
      tail < Last Lesson Chapter Quiz >