Introduction to vim


VIM (vi Improved) is a powerful text editor which is more sophisticated than gedit. Also, unlike gedit, you can always expect vim (or its predecessor, vi) to be available in any Linux system.
The vim editor supports sophisticated text manipulations which are very useful for system administration. In fact, if you are familiar with the vi utility, you will find that vim includes vi features, plus many other features such as split screen editing, color formatting of known file types, and text highlighting for copying and changing text, to name a few.
One reason why vim is powerful but tricky to learn is that it is a modal editor; it works differently depending on which mode it is in. There are three modes you need to know to start with: normal mode(also called command mode), insert mode, and ex mode.

Primary vim Modes
  1. Command mode is used for file navigation, cut and paste, and simple commands.
  2.  Insert mode is used for normal text editing.
  3.  Ex mode is used to save, quit, search and replace, and perform other complex operations.

Command Mode
After opening the vim editor, you begin in command mode. This is the basic mode you return to when done with an edit and preparing to save, search and replace text, or perform other operations. In this mode, you can move around the file (using PageUp, pageDown, or arrow keys), and typing characters can execute many different commands to do such things as selecting, copying, or pasting text. One useful command here is u, to undo the last change. If you are confused about what mode vim is in, you can type Esc a couple of times to command mode.

Insert Mode
From command mode, press the I key to go into insert mode at the cursor’s current position. Then you can begin entering text. You can use the arrow keys to move the cursor in vim while remaining in insert mode. Press the Esc key to leave insert and return to command mode.

Ex Mode
From command mode, press a: character to go into ex mode and the cursor moves to the bottom of the screen. Press : q(to quit) :w(to write changes to the file), or :wq to write and quit. Use the ! character to override a default action. For example :q! lets you quit without saving and :w! lets you overwrite a read-only file (if you own it). Other commands are available in ex mode, including an on-line help system under :help.


----------x--------

No comments:

Post a Comment