The vi and vim primer for beginners
January 18th, 2012 § 1 Comment
vi and vim
No matter the subject, you are always smart to start at the beginning. vi is the beginning of almost everything. It is the text editor you will use while configuring your system during almost every administrative task. It mainly edits ASCII files which are configuration files. Without a text editor you may as well power down the box.
A Short History
vi is the descendant of qed, the very first Unix editor written in 1965. From qed came ed (short for editor). From ed came ex, which later begat vi. Today, the old testament ends here. It should be adequate to say that vi has been around for a long while and, as such, it is on every *nix platform developed throughout all history, unless it has specifically been removed for security purposes. There are others, yes; emacs, pico, and nano, and the list goes on without end. This is not to say they are not good tools, they are. But, if you have to know just one – vi is it.
It’s Everywhere *nux Is
Given the prevalence of the Linux OS, vi becomes more and more valid argument. You can find Linux on your DSL modem, in newer Cisco equipment, in Tadiran phone systems, in cash registers and, lest we forget, that thing in your pocket that rings when your friends call. vi is resident on everything and, if it’s not today – it soon will be.
When Will You Need It?
Always – period. Here are some phrases that indicate your going to be using vi; When someone says you’ll have to edit that configuration file. EG:
- Dude, that’s in smb.conf. Change the workgroup value to WHATEVER.
- Dude, you’ll need to set an MX record for that new email server.
- Dude, your command is too long. Write a script.
- Dude, get your hands outta your pants.
The difference between vi and vim
Lots really. vi is old school and vim is the, updated and improved, cool new kid at school. If you ever really ran into vi, I would be kinda surprised. It will exist on older systems but, generally, all you new guys are going to be using vim-minimal; this package includes a minimal version of VIM (vi IMproved), which is installed into /bin/vi – but it’s still not really vi.
Red Hat systems have these packages:
$ rpm -qa vim-*
vim-minimal-7.0.109-7.el5
vim-common-7.0.109-7.el5
vim-enhanced-7.0.109-7.el5
Debian-based systems (Ubuntu/Mint) have these packages:
$ dpkg -l | grep “^ii” | grep ‘vim-*’
ii vim 2:7.2.330-1ubuntu4 Vi IMproved – enhanced vi editor
ii vim-common 2:7.2.330-1ubuntu4 Vi IMproved – Common files
ii vim-runtime 2:7.2.330-1ubuntu4 Vi IMproved – Runtime files
ii vim-tiny 2:7.2.330-1ubuntu4 Vi IMproved – enhanced vi editor – compact version
The vim-common package contains files which every VIM binary will need in order to run. The vim-enhanced package contains a version of VIM with extra, recently-introduced features like Python and Perl interpreters so you can write scripts in these languages as well as bash and awk. If you don’t have the more feature-rich packages, get them:
Red Hat:
$ sudo yum -y install vim-enhanced
Debian-based systems (Ubuntu/Mint) have these packages:
$ sudo apt-get install vim vim-runtime
The Jelly
I WISH someone had shared these videos with me when I started out even though they probably didn’t exist then but still. And just to cover all bases, there are those types that only read their information, pulp snobs; for those people you can trudge through the official documentation. To be fair, there is a great deal of information not covered in these videos, you should read the docs when you run into trouble. But, just to get started, the videos are just fine.
VIM Addons
Once you have a handle on vim, there are only a few real paths: edit configuration files and writing scripts. Configuration files will take care of themselves but when you start scripting there are some add-ons that will make your life easier.
VAM – Vim Addon Manager: this little wonder will simplify your life – if you can get it installed. We’ll talk more in-depth about that in another post. VAM helps you to easily install some things to make your life easier. snipmate is a good example; it performs auto completion of easy to complex code structures; everything from loops to arrays. You could do the extra work but, unless there is a nuclear holocaust and we all have to start over again, why would you?
Pathogen – This does the same thing as VAM but in a different way. If I didn’t start a “vi vs emacs” fight earlier, that last statement should do the trick.
Personally, I use VAM; I’ve chatted with Marc Weber and he’s a mad man willing to fight and die for his cause. This is the only type of person that should be writing software. Marc makes tools that make his coding life easier. If it’s a pain in the ass for Marc to code something, he updates his tools (like VAM) to reduce the pain in his ass. Due to his nature, he makes these tools available to us for free. No pain in Marc’s ass = no pain in your ass. Strangely, he has great patience for supporting his software as well. What more could you ask of a person?
So, vim – learn it, know it, love it – because you can’t live without it.
I found this post to be extremely helpful as a fun intro to VIM and VI!!