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
To use Vim, just type in the command with the file name. The following screen should load.
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.
- 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.
- X- delete the character in front of the cursor.
- x- delete the character after the cursor.
- dd- cut current line.
- u- undo
- ctrl+r- Redo
These are some helpful commands.
Moving cursor commands:
Deleting Text:
Undo/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.
head- displays the first few lines of a file.
tail- displays the last few lines of a files.