Ubuntu command line text editor

Ubuntu command line text editor was included in the system by default when you install Ubuntu server. The text editor name is VIM - Vi IMproved. Vi is the famous text editor, which is installed by default in most Linux and other Unix-based text editor. It's not the ease of use that makes vi famous, but because vi is a very powerful text editor. It comes with powerful macro built and plugins.



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.
  1. Command mode - This is the default mode. When you invoke vi from the Ubuntu command line, you'll have this mode.
  2. Insert mode - This is where you can insert content in the file. In other words, you can only type text in this mode.
Remember when we open vi, we'll be in command mode. To begin with, just note a few commands:
  1. i - to insert text. When you press i, you'll be in insert mode.
  2. a - append text. When you press a, you'll be in insert mode.
Some important keys in vi text editor command mode:
  1. x - to delete text. Press x to delete one character at a time.
  2. dd - to delete line. Press dd to delete one line at a time.
  3. u - undo. Back one previous step.
  4. yy - yank. Copy one line.
  5. p - paste.
  6. / - search forward.
  7. ? - search backward.
Please remember, these actions can be done only in vi command mode. However, we can use backspace and delete key in vim insert mode.

Move cursor in vi text editor:
  1. l - move cursor forward.
  2. f - move cursor backward.
  3. j - move cursor down.
  4. k - move cursor up.
In vim, just use up/down, left/right arrow keys to move the cursor.

Exit vi text editor:
  1. ZZ - exit vi and save. (upper case!)
  2. :wq - save and quit vi.
  3. :q - quit without saving.
  4. :q! - force quit without saving.
  5. :wq! - save and force quit.
In vi insert mode (when you press i or a), just remember one important key:
  • Esc - exit insert mode.
My final tip, if you are using vi text editor, remember the insert mode is for input text only so press Esc every time you finish typing.

That's it. Happy editing in Ubuntu command line terminal.