VIM: A Brief Introduction
56VIM is a very handy command line text editor for Linux, but if you have never used it, VIM can be a little confusing.
For those that have their own website, VIM can be very handy, because you can SSH into your server and edit files quickly and easily. This is especially useful if you make a change to your Wordpress Theme, which causes it to break
VIM is based off of the popular VI editor.
Opening Files in VIM
It is very easy to open files in vim. From the command line, simply use the command: vim /path/to/file where path/to/file is the location of the file on the harddrive.
Examples:
vim /etc/networks
vim /home/username/file.txt
Insert Mode: Editing the File
Unlike other text editors, like notepad, vim does not let you insert text to the file unless you first press “i” or “a.” This enters insert mode, then when you are done editing, press escape to exit insert mode, which will allow you to enter different commands.
*Actually, there are several other letters you can press, but these are a good one to begin with.*
i - insert text before the cursor.
a - Append the text after the cursor.
Saving the File
To save the file without exiting, first press the escape key to exit insert mode and press :w
*Make sure to include the full colon(:)
Deleting Text
You can use the delete key to delete text.
Un-Doing a Mistake
Make sure you are not in “insert mode” and press the u key to undo mistakes. You can press the u key repeatedly to undo multiple mistakes.
Jumping to the End of the Line
Make sure you are not in insert mode and press the $ key. Depending on the version of vim, you may also be able to use the End key.
Exiting VIM
Exiting Vim can be a little confusing to those who are new to it, but it is very straightforward. First, press the escape key to make sure you are not in insert mode, then use one of the following commands to exit VIM.
:q! exit without saving
:x exit, but save first.
:wq Save and Exit.
* *Remeber to include the full colon(:)
Searching the File
Make sure you are out of insert mode by pressing the escape key, then press the / key.
Enter the word you want to search for and press enter.You can press n to move to the next instance.
To preform a case insensitve search, first enter the following command :set ignorecase command
This will tell VIM to ignore the case. If you want to reenable case sensitivy, use the :set noic command.
Jump to Line Number
This comes in handy if you are trying to debug a php file and get an error on a certain line. First, press escape to exit insert mode, then press :lineNumber, where lineNumber is the line numbe.
Examples:
:45 - Jump to Line 45:10 - Jump to Line 10
Final Thoughts
This serves as a brief introduction to VIM and should get you up and running, but it does not even begin to touch on the power that VIM offers. For every section I listed, there are multiple other commands that you can use, plus many other features.
For a more detailed list of commands, you can start by reading the manul by entering man vim into the command line.
PrintShare it! — Rate it: up down flag this hub








