[ Back | warped.org ]

Primer to use VI to edit text files, especially source code and email.

VI or VIM?

vi is the generic term for both programs. Technically vi is original software, that can be found installed on any unix system derivitave. This is the text editor that system admins have been using since the beginning of time.

The version installed on a lot of os's is from before the beginning of time, enter vim. The M stands for iMproved. This is MORE than an understatement. For a lot of newer unix flavors (most notabley linux), vi has been dropped and vi and vim are one in the same. But for most sun releases and some bsd releases, vim is either absent or named vim and vi is the old school.

Get used to typing vim !

Graphical Version

GVIM is a great tool to get you started, it's just the X-windows version of the same program, with some handy menus and mouse usage, which can help lower that nasty vi learning curve. Once you have the setup below working, and you know you can get in and out of vim, try just running the command gvim and if that didn't work try vim -g , which does the same thing. If you've used emacs before, gvim is the parallel to xemacs.

Great! A screen full of ~'s ... Now What?

Now you get to expierence what is known as a sharp learning curve. Think jedi knight, the payoff is almost as good.

:q! [return] will get you out of it. (that's 3 keys followed by big enter key = 4 keystrokes)
(Optionally ZZ )

Setup your envoirnment

First things first -- you have to get to the editor first, right?

Shell Stuff

First, find vim. then
Make sure your shell can find vim by editing these files found in your home directory : If you don't know which shell you have, the rule of thumb is if you see a % at your prompt it's probably csh based (standard on sun machines and at ucsc), and if you see a $ it's probably bash (standard on linux machines).
csh / tcsh
  • .cshrc : Add these lines to the very top :
    setenv EDITOR vi
    alias vi /usr/local/bin/vim
  • .cshrc : UCSC Specific Lines to Add in addition
    setenv PATH "/usr/local/gnu/bin:/usr/local/bin:$PATH"
    setenv PAGER less
    setenv LESS "-i -m"
    setenv VIMRUNTIME /usr/local/vim/vim57
bash
  • .bashrc : Add these lines to the very top :
    export EDITOR=vi
    alias vi=/usr/local/bin/vim
  • .bashrc : UCSC Specific Lines to Add in addition
    export PATH="/usr/local/gnu/bin:/usr/local/bin:$PATH"
    export PAGER=less
    export LESS="-i -m"
    export VIMRUNTIME=/usr/local/vim/vim57

Vim stuff

Vim is controlled by a file called .vimrc found in your home directory. you can also call this file .exrc and .virc but then vim specific commands that you put into it will cause old versions to get mad at you, so name the file .vimrc

HERE is a copy of my vimrc, copy this to your home directory as .vimrc and use it as a good starting place.

Please note that the file contains escape sequences (control characters), so you MUST download it, and use a good editor (vi?) to swipe commands out of it.

See links below for more info.

Terminal Stuff

Well just like emacs, vim comes in two flavors -- graphical and console mode. The console is a window, kinda like a dos prompt. If you set this up right, your life is a lot happier, eg colors and working function keys etc. I prefer xterm when using linux and dtterm when using cde (windows found on sun machines). try running this from another console to invoke a new one that's BETTER :

xterm -bg black -fg white -geometry 100x45 &
or try running gvim with     gvim -reverse

Links

  1. vim.org
  2. My vimrc file
  3. My bashrc file
  4. My bashprofile file


[ Back to Index ]

Tell me if you read this. I dont write this for myself, damnit.


If this information helped you, consider exiting through your right. ©2000-2013 Max Baker
Sun Apr 27 22:32:34 2008 PST