Vi is something that seems to scare people who know a change needs to be made but are worried about totally destroying their systems. Many folks should relax and take a deep breath. Vi is nothing to be scared of and is rather a tool that can be beneficial in multiple arenas and at multiple times.
However, the standard rule of thumb applies. Do not just jump in and “think” you know what the command should be. The reality is nothing is ever that simple and in a world where shortening words or phrases is common place, you should always feel good before you type.
In order to help out I created a basic Vi cheat sheet to help you get around with confidence. The commands below will help you with probably 80 percent of the items you are trying to accomplish. I will create an advanced cheat sheet at a later date but for now I offer the basic Vi cheat sheet.
It is important to know or remember that there are two modes in Vi; insert and command. When you first enter the editor you are in command mode. In command mode, there is text deletion, pasting of info, and cursor movement. You can enter insertion mode when you input a change or insertion command.
To get out of insertion mode all you need to do is press [ESC] where you can quit by typing :q! or write and quit with :wq!
Some items to always remember when using Vi are:
Buffers – Can be specified before any deletion, change, yank, or put command.
Markers – They can be used for range limits and any lowercase letter can serve as a marker. They can be set on any line within the file.
Counting – Almost every possible command may be led by a number that states how many times it is to be performed. As an example, type “11fc” will move the cursor forward to the 11th existence of the letter c.
Regular Expression Key To Remember – Regular expressions are always case sensitive. An example of a regular expression is typing “/6969$” which matches if the line ends with 6969.
The table below is by all means not the complete list of all things that can be done with Vi but if you can master everything below and learn how they all work together you will be well on your way to success.
[table id=5 /]