This is an example of vim. You can view vim by typing vi in the command line.
luzar@ubuntu:~$ vi
In Ubuntu, there are original vi and vim text editors. Type vi, you'll have vi and type vim, you'll get vim. They are the same, except vim is more user friendly and easier to use. For example, the noticeable different of up/down, left/right arrow keys and backspace/delete keys. Here are some information about vim from the manual page.
Name:
vim - Vi IMproved, a programmers text editor
Synopsis/vi syntax/vi format:
vim [options] [file ..]
vim [options] -
vim [options] -t tag
vim [options] -q [errorfile]
DESCRIPTION
Vim is a text editor that is upwards compatible to Vi. It can be used
to edit all kinds of plain text. It is especially useful for editing
programs.
I am not going for a vi text editor full course here. Just a basic vi/vim text editor guide to help you using and editing files in Ubuntu command line. Let's continue.
From the synopsis above, we can simply create or open file using this format:
luzar@ubuntu:~$ vi /path/filename.txt
or
luzar@ubuntu:~$ vim /path/filename.txt
The first thing you should know is vi has two modes. Please keep this in your mind. Most users got confused and find it hard to use vi editor because of this. Well, I'll show you my way.
- Command mode - This is the default mode. When you invoke vi from the Ubuntu command line, you'll have this mode.
- Insert mode - This is where you can insert content in the file. In other words, you can only type text in this mode.
- i - to insert text. When you press i, you'll be in insert mode.
- a - append text. When you press a, you'll be in insert mode.
- x - to delete text. Press x to delete one character at a time.
- dd - to delete line. Press dd to delete one line at a time.
- u - undo. Back one previous step.
- yy - yank. Copy one line.
- p - paste.
- / - search forward.
- ? - search backward.
Move cursor in vi text editor:
- l - move cursor forward.
- f - move cursor backward.
- j - move cursor down.
- k - move cursor up.
Exit vi text editor:
- ZZ - exit vi and save. (upper case!)
- :wq - save and quit vi.
- :q - quit without saving.
- :q! - force quit without saving.
- :wq! - save and force quit.
- Esc - exit insert mode.
That's it. Happy editing in Ubuntu command line terminal.