<\/span><\/h2>\nBefore going any further, one must first understand the way Vim works. In a nutshell, Vim has three basic modes of operation.<\/p>\n
Command mode<\/strong> – where one can pass commands to Vim in order to manipulate the document. You search for text. Copy\/Paste portions of it. Find and replace text based on a pattern and much more. There is almost no limitation of what one can achieve in this mode.<\/p>\nInsert mode<\/strong> – This is where the writing of text gets done.<\/p>\nVisual mode<\/strong> – This is like a sub-mode of the command mode where one can select text.<\/p>\nCOMMAND\u00a0mode<\/h3>\n
This is\u00a0the default mode and the one that you will find yourself into when opening a file with Vim. In this mode, you can not type, but you can pass commands to Vim. You can scroll through the document using the arrow keys and go up\/down using the Page Up and Page Down keys. By passing commands to Vim, you have the power to quickly manipulate the file you are editing, in ways that no other text editor offers.<\/p>\n
There are several ways that you can pass commands into Vim in this mode. For now, you should know only the most basic ones to get you started:<\/p>\n
i<\/code> – Puts you into INSERT mode – where you can type just as in any other editor; At the same time with the\u00a0ESC<\/code>\u00a0 key you can\u00a0exit from INSERT mode;<\/p>\n:w<\/code> – Save\/Write the changes to disk;<\/p>\n:w!<\/code> – Save but do not prompt for confirmation (! stands for force);<\/p>\n:q<\/code> – Exit from Vim if no changes have been made;<\/p>\n:q!<\/code> – Exit from Vim and discard the changes;<\/p>\nSome commands (those that are compatible can be combined together).<\/p>\n
:wq!<\/code> – Save the changes and exit;<\/p>\nThe last two commands :q!<\/code> and :wq!<\/code> are the ones that you will most often use.<\/p>\nINSERT mode<\/h3>\n
As the name suggest, this is the mode where one does all the typing.<\/p>\n
Using i<\/code> from command mode you can enter INSERT mode, type whatever you like and do the changes, and then exit back into COMMAND mode with ESC key.<\/p>\nVISUAL mode<\/h3>\n
In this mode, you can select text. You can think of this mode like a sub-mode of the Command mode. You can either choose to select whole blocks of text or select just a single portion of it. While in COMMAND mode, there are three types of VISUAL mode that one can enter into.<\/p>\n
v<\/code> – Toggles the most simple visual mode. While in command mode position your cursor anywhere in the text and press v. You will see that at the bottom left of the terminal the status will change to -- VISUAL --<\/code>. Now you can move your cursor using the arrow keys and select parts of the text.<\/p>\nV<\/code> – is the\u00a0— VISUAL LINE — mode. Use this mode when you need to select whole lines.<\/p>\nCTRL-V<\/code> – is the -- VISUAL BLOCK --<\/code> mode. Use this mode to select blocks of text by freely moving the cursor around.<\/p>\n <\/p>\n
Now that we know the three basic modes we can learn some more useful commands. These work in Command mode but are also very useful while used in\u00a0VISUAL mode. That is the exact reason why we are mentioning these command here.<\/p>\n
0<\/code> – Will position your cursor to the begging of the line;<\/p>\n$<\/code> – Will position your cursor to the end of the line;<\/p>\no<\/code> – Will enter INSERT mode and into a new line for writing;<\/p>\ny<\/code> – Copy (y stands for yank)<\/em>;<\/p>\nyy<\/code> – Copy a whole line;<\/p>\np<\/code> – Paste;<\/p>\nP<\/code> – Paste above the cursor;<\/p>\nd<\/code> – Cut;<\/p>\ndd<\/code> – Cut the whole line;<\/p>\nx<\/code> – Is simply delete. Normally it will delete the selected character or the chunk of text selected with v<\/code>. However, we found out that in visual mode there is no difference between d<\/code> and x.<\/code><\/code><\/p>\nu<\/code> – Undo;<\/p>\nCTRL-R<\/code> – Redo;<\/p>\n:set number<\/code> – Toggles line numbering. This does not affect the document, it is just for reference;<\/p>\n:set number!<\/code> – Turn line numbering off;<\/p>\n <\/p>\n
While line numbering is on you can quickly jump to a line number you like:<\/p>\n
:10<\/code> – go to line 10<\/p>\n:5<\/code> – go to line 5<\/p>\n.. and so on.<\/p>\n
<\/p>\n