ICS/Lotus (mostly), Linux, Travel, Skiing, Mixology, and Random Musing of Interest

Linux School -- Beginner’s Guide to Vim (Plus A Few Tips)

Bill Malchisky  July 1 2013 12:32:30 AM
For those that attended any of my training sessions or LUG sessions on Linux, you know that I speak highly of vi as a text editor. Fortunately for those new to the Linux and UNIX world, there is vim or 'Vi IMproved'. In 1976, Bill Joy released vi, which was considered a heavy program in the day, due to its size, but very useful. The first UNIX port of vim appeared in 1992, but as I recall, did not gain prominence until just before the turn of the century. The updates included in vim take all the quality capabilities of vi and adds to that set many modern conveniences or behavior that people would expect (e.g. multi-level undo).


The Guide

The Linux Foundation created an excellent short and simple guide explaining vi/vim. If you are new to Linux or still uncertain if vi is for you, take a couple of minutes to read the short file. It may well fill-in several gaps in your knowledge base. I even learned a new command.

N.B. for newbies, the '$' below indicates a user prompt and is not part of the command, thus it appears is standard weight with the command in bold-face.


Setting vim as the Default

Finding the path (also ensures the package exists) - $which vim
[bill@localhost Desktop]$ which vim

/usr/bin/vim


If you get anything other than a path or are returned to a prompt sans output, you may need to install it
Ubuntu - $sudo apt-get install vim

Note: on RHEL, CentOS, Mac OSX, SUSE, vim is installed by default. Most systems have both installed and will map a pointer from vi to vim for sanity purposes.

If you are new to Linux, just typing $vim at the prompt is sufficient and recommended. If you are a *nix veteran, you may be used to typing $vi when you meant to type $vim. Setup an alias to avoid running the lightweight version of vim instead--confusing for beginners, I will add. Running the $alias command shows the mapping existence:
[bill@localhost Desktop]$ alias

alias l.='ls -d .* --color=auto'

alias ll='ls -l --color=auto'

alias ls='ls --color=auto'

alias vi='vim'


If you do not see the vim alias mapping and typing $vim at your prompt works properly, from your terminal window in Linux, Mac OSX, Cygwin, or UNIX, use this syntax:
$alias vi='vim'


N.B. typing this command at the command prompt keeps the alias scope to the current shell only and purges the alias mapping when you close the shell. For permanency, insert the command into the aliases section towards the bottom of your ~/.bashrc file; save, and then run the following command to activate the file changes immediately in your current shell and new shells:
$source ~/.bashrc


Testing the success

[bill@localhost Desktop]$ which vi

alias vi='vim'

     /usr/bin/vim


Which displays your new alias and the underlying system path to the executable.


Additional Resources and Tips

1. If you want to better understand the differences between vim and vi, from within your vim session type :help vi_diff.txt  {including the colon} and you will receive a detailed but abridged document
2. Vim Tutor-- provides a very detailed user guide as a teaching file to edit with vim. It is installed by default in Red Hat, Fedora, CentOS, SUSE, Mac OSX; Ubuntu -- $sudo apt-get install vim (which installs both the vim and vim-runtime packages on Ubuntu, providing vimtutor)
2a. $vimtutor -- starts the Vim Tutor program. It actually makes a copy of the actual vim tutor file and lets you edit it, while learning the program, so you can save your changes to your home directory :w {filename} e.g. :w ~/Documents/vim-test, or exit sans saving changes via :q! and not worry about disturbing the original file.
2b. The Vim Tutor file is available in several languages. To see a list, type:
$ls /usr/share/vim/vim73/tutor/tutor.?? | sort | less

2c. $vimtutor [two_character_language_code] -- converts the vim tutor file into a different language automatically; if the entered code is unavailable, English is used instead
$vimtutor it


Provides the vim tutor file as Italian
==============================================================================
=    Benvenuto  alla   G u i d a    all'Editor   V I M   -    Versione 1.7    =
==============================================================================

   Vim è un Editor molto potente ed ha parecchi comandi, troppi per
   spiegarli tutti in una guida come questa.  Questa guida serve a
   descrivere quei comandi che ti permettono di usare facilmente
   Vim come Editor di uso generale.


The default version is in English on my system
==============================================================================
=    W e l c o m e   t o   t h e   V I M   T u t o r    -    Version 1.7      
==============================================================================

   Vim is a very powerful editor that has many commands, too many to
   explain in a tutor such as this.  This tutor is designed to describe
   enough of the commands that you will be able to easily use Vim as
   an all-purpose editor.


Enjoy and happy editing!

Next time, we'll cover syntax highlighting -- which is a great feature in vim for admins, developers, and power users... stay tuned.
Comments
No Comments Found

Powered by IBM Lotus Domino 8 | Lotus User Group | Get Firefox! | This blog is listed on Planet Lotus   IBM Certified

© 2010 William Malchisky.