This tutorial is not written to make you a guru at Vim (vi Improved) this is written for those that have shell access and need to login in and make changes to files.
By : postalcow
This tutorial is not written to make you a guru at Vim (vi Improved) this is written for those that have shell access and need to login in and make changes to files.
A little bit about VI first. VI is not what you would consider a user friendly editor. But once you become comfortable with VI you will be sending me emails saying "Cow.. You Really Know Your Pies" VI is the best thing since Fillet Mignon. At the end of this down and dirty tutorial I will give you some sites to get more information on VI.
In this tutorial you'll be working in two modes Editing and Command.
Editing, Self explanatory. This is the mode that will give you the ability to edit the file.
Command, This mode is where commands are given to VI to do such things as writing, saving and quitting. If you get the urge to learn more about VI you can turn on text coloring, auto indentation, folding features and 100's of others.
Starting VI and opening a file.
vi somefile.php
To start editing a file you need to enter one of the edit modes. These commands are case sensitive, 'i' is not the same as 'I'. Also, always remember <esc> takes you out of an editing mode.
Lets dig in to basic VI
1) To enter VI, type: vi somefile.xxx <Enter> 2) To go into the insert mode type: i 3) Enter some text. Postal I love using VI 4) Press the <esc> key to leave insert mode 5) Save the file type <esc> :wq (that means write and quit)
Moving around in VI.
You can use your cursor keys <left> <down> <up> <right> or h j k l for left,down,up,right.
In command mode you can use the following commands wherever your cursor is.
x deletes a character.
dd deletes the whole line the cursor is on.
r replaces a character
Displaying Line numbers
<esc> :set nu Turns on line numbering
<esc> :set nonu Turns off line numbering
Quitting VI
:wq Write, then quit
:q Quit (will only work if file has not been changed)
:q! Quit without saving changes to file
That's the Basics. Here are a few advanced commands.
DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.