mirror of https://github.com/tLDP/LDP
2991 lines
100 KiB
Plaintext
2991 lines
100 KiB
Plaintext
<!doctype linuxdoc system>
|
|
<!--
|
|
|
|
************************** begin comment *****************************
|
|
The following is the HOW-TO for setting up VIM editor.
|
|
This document is in the SGML format. You must use sgml package to
|
|
process this document
|
|
************************* end of comment *****************************
|
|
|
|
-->
|
|
<!--
|
|
************************** SGML USER GUIDE *****************************
|
|
The SGML user guide on linux is located at /usr/doc/sgml-tools
|
|
Read the example.sgml and guide.html documents.
|
|
Usage:
|
|
HTML sgml2html foo (Do not give extension .sgml here!!)
|
|
Text sgml2txt foo.sgml
|
|
Latex sgml2latex foo.sgml
|
|
|
|
Note: Use 2 dashes - before language, error while compiling
|
|
Postscript sgml2latex -language=english -o ps foo.sgml
|
|
DVI sgml2latex -d foo.sgml
|
|
Lyx sgml2lyx foo.sgml
|
|
Richtext sgml2rtf foo.sgml
|
|
gnuinfo sgml2info foo.sgml
|
|
man sgml2txt -man foo.sgml
|
|
SGML sgmlcheck foo.sgml
|
|
************************* end of comment *****************************
|
|
-->
|
|
|
|
<article>
|
|
|
|
<!-- Title information -->
|
|
|
|
<title>Vim Color Editor HOW-TO (Vi Improved with syntax color highlighting)
|
|
<!-- chapt change
|
|
Vim Color Editor HOW-TO
|
|
Vi Improved with syntax color highlighting
|
|
|
|
|
|
|
|
-->
|
|
<author>Al Dev (Alavoor Vasudevan)
|
|
<htmlurl url="mailto:
|
|
alavoor[AT]yahoo.com
|
|
"name="
|
|
alavoor[AT]yahoo.com
|
|
">
|
|
<date>v18.4, 01 Oct 2002
|
|
<abstract>
|
|
This document is a guide to quickly setting up the Vim color editor on Linux or Unix systems. The information here will improve the productivity of programmers because the
|
|
Vim editor supports syntax color highlighting and bold fonts, improving the
|
|
"readability" of program code. A programmer's productivity improves 2 to 3 times
|
|
with a color editor like Vim.
|
|
The information in this document applies to all operating sytems where Vim
|
|
works, such as Linux, Windows 95/NT, Apple Mac, IBM OSes, VMS, BeOS and all flavors of Unix like Solaris, HPUX, AIX, SCO, Sinix, BSD, Ultrix etc.. (it means almost all operating systems on this planet!)
|
|
</abstract>
|
|
|
|
<!-- Table of contents -->
|
|
<toc>
|
|
|
|
<!-- Begin the document -->
|
|
|
|
|
|
|
|
<sect>Introduction
|
|
<p>
|
|
<bf>
|
|
(The latest version of this document is at <url url="http://www.milkywaygalaxy.freeservers.com">. You may
|
|
want to check there for changes).
|
|
</bf>
|
|
|
|
Vim stands for 'Vi Improved'. Vi is the most popular and powerful
|
|
editors in the Unix world. <bf>Vi</bf> is an abbreviation for "<it><bf>Vi</bf></it>sual" editor.
|
|
One of the first editors was a line editor
|
|
called 'ed' (and 'ex'). The <it><bf>Vi</bf></it>sual editor
|
|
like Vi was a vast improvement over line editors like 'ed' (or 'ex'). The editors 'ed'
|
|
and 'ex' are still available on Linux: see 'man ed' and 'man ex'.
|
|
<p>
|
|
A good editor improves programmer productivity. Vim supports color syntax highlighting of program code and
|
|
also emphasises text using different fonts like normal, bold or italics. A color editor like Vim
|
|
can improve the <bf>productivity</bf> of programmers by <bf>2 to 3 times</bf>!! Programmers can
|
|
read the code much more rapidly as the code syntax is colored and highlighted.
|
|
|
|
|
|
|
|
<sect1> Before you Install <label id="Before you Install">
|
|
<p>
|
|
Before you install Vim, please refer to the OS specific release notes and
|
|
information about compiling and usage of Vim at -
|
|
<itemize>
|
|
<item> Go to this location and look for files os_*.txt <url url="http://cvs.vim.org/cgi-bin/cvsweb/vim/runtime/doc">
|
|
</itemize>
|
|
If you do not have the Vim package (RPM, DEB, tar, zip) then download
|
|
the Vim source code by ftp from the official Vim site
|
|
<itemize>
|
|
<item> The home page of vim is at <url url="http://www.vim.org">
|
|
<item> Mirror site in US is at <url url="http://www.us.vim.org">
|
|
<item> Ftp site <url url="ftp://ftp.vim.org/pub/vim">
|
|
<item> Or use one of the mirrors <url url ="ftp://ftp.vim.org/pub/vim/MIRRORS">
|
|
</itemize>
|
|
|
|
|
|
|
|
<sect1> Install Vim on Redhat Linux
|
|
<p>
|
|
To use Vim install the following RPM packages on Redhat Linux -
|
|
<code>
|
|
rpm -i vim*.rpm
|
|
OR do this -
|
|
rpm -i vim-enhanced*.rpm
|
|
rpm -i vim-X11*.rpm
|
|
rpm -i vim-common*.rpm
|
|
rpm -i vim-minimal*.rpm
|
|
</code>
|
|
You can see the list of files the vim rpm installs by -
|
|
<code>
|
|
rpm -qa | grep ^vim | xargs rpm -ql | less
|
|
or
|
|
rpm -qa | grep ^vim | awk '{print "rpm -ql " $1 }' | /bin/sh | less
|
|
</code>
|
|
and browse output using j,k, CTRL+f, CTRL+D, CTRL+B, CTRL+U or using arrow keys, page up/down keys.
|
|
See 'man less'.
|
|
<p>
|
|
Note that the RPM packages for Redhat Linux use a Motif interface. If you have installed the
|
|
GTK libraries on your system, consider compiling Vim from the source code for a clean
|
|
GUI interface. For information on compiling Vim from the source code, see "Install Vim on Unixes", below.
|
|
|
|
|
|
<sect1> Install Vim on Debian GNU/Linux
|
|
<p>
|
|
To install Vim on Debian Linux (GNU Linux), login as root and when connected to internet
|
|
type -
|
|
<code>
|
|
apt-get install vim vim-rt
|
|
</code>
|
|
It will download the latest version of vim, install it, configure it.
|
|
The first package listed is vim, the standard editor, compiled
|
|
with X11 support, vim-rt is the vim runtime, it holds all the syntax and help files.
|
|
<p>
|
|
On Debian 3.0 (woody) and above, use 'apt-get install vim' instead.
|
|
The vim-rt package is part of the main vim package.
|
|
|
|
|
|
<sect1> Install Vim on Unixes
|
|
<p>
|
|
For other flavors of unixes like Solaris, HPUX, AIX, Sinix, SCO download the source code file
|
|
( see
|
|
<ref id="Before you Install">
|
|
)
|
|
<code>
|
|
zcat vim.tar.gz | tar -xvf -
|
|
cd vim-5.5/src
|
|
./configure --prefix=$HOME/local
|
|
make
|
|
make install
|
|
</code>
|
|
You can exclude prefix option if you want to install in default location in /usr/local.
|
|
If the graphics version 'gvim' gives trouble then try with
|
|
<code>
|
|
./configure --prefix=$HOME/local --enable-gui=motif
|
|
</code>
|
|
<p>
|
|
|
|
|
|
<sect1> Install Vim on Microsoft Windows 95/NT
|
|
<p>
|
|
See <ref id="installmswin" name="Install on MS Windows">.
|
|
|
|
|
|
|
|
<sect1> Install Vim on VMS
|
|
<p>
|
|
|
|
|
|
<sect2> Download files
|
|
<p>
|
|
You will need both the Unix and Extra archives to build vim.exe for VMS.
|
|
For using Vim's full power you will need the runtime files as well.
|
|
Get these files
|
|
( see
|
|
<ref id="Before you Install">
|
|
)
|
|
|
|
You can download precompiled executables from:
|
|
<url url="http://www.polarfox.com/vim">
|
|
|
|
VMS vim authors are -
|
|
<itemize>
|
|
<item>
|
|
<htmlurl url="mailto:
|
|
zoltan.arpadffy@essnet.se
|
|
"name="
|
|
zoltan.arpadffy@essnet.se
|
|
">
|
|
<item>
|
|
<htmlurl url="mailto:
|
|
arpadffy@altavista.net
|
|
"name="
|
|
arpadffy@altavista.net
|
|
">
|
|
<item>
|
|
<htmlurl url="mailto:
|
|
cec@gryphon.gsfc.nasa.gov
|
|
"name="
|
|
cec@gryphon.gsfc.nasa.gov
|
|
">
|
|
<item>
|
|
<htmlurl url="mailto:
|
|
BNHunsaker@chq.byu.edu
|
|
"name="
|
|
BNHunsaker@chq.byu.edu
|
|
">
|
|
<item>
|
|
<htmlurl url="mailto:
|
|
sandor.kopanyi@altavista.net
|
|
"name="
|
|
sandor.kopanyi@altavista.net
|
|
">
|
|
</itemize>
|
|
|
|
|
|
|
|
<sect2> Compiling
|
|
<p>
|
|
Unpack the Unix and Extra archives together into one directory. In the <.SRC>
|
|
subdirectory you should find the make file OS_VMS.MMS. By editing this file
|
|
you may choose between building the character, GUI and debug version. There
|
|
are also additional options for Perl, Python and Tcl support.
|
|
|
|
You will need either the DECSET mms utility or the freely available clone of
|
|
it called mmk (VMS has no make utility in the standard distribution). You can
|
|
download mmk from http://www.openvms.digital.com/freeware/MMK/
|
|
|
|
If you have MSS on your system, the command
|
|
|
|
> mms /descrip=os_vms.mms
|
|
|
|
will start building your own customised version of Vim.
|
|
The equivalent command for mmk is:
|
|
|
|
> mmk /descrip=os_vms.mms
|
|
|
|
|
|
|
|
<sect2> Deploy
|
|
<p>
|
|
Vim uses a special directory structure to hold the document and runtime files:
|
|
|
|
<code>
|
|
vim (or wherever)
|
|
|- tmp
|
|
|- vim55
|
|
|----- doc
|
|
|----- syntax
|
|
|- vim56
|
|
|----- doc
|
|
|----- syntax
|
|
vimrc (system rc files)
|
|
gvimrc
|
|
|
|
Use:
|
|
|
|
> define/nolog device:[leading-path-here.vim] vim
|
|
> define/nolog device:[leading-path-here.vim.vim56] vimruntime
|
|
> define/nolog device:[leading-path-here.tmp] tmp
|
|
</code>
|
|
|
|
to get vim.exe to find its document, filetype, and syntax files, and to
|
|
specify a directory where temporary files will be located. Copy the "runtime"
|
|
subdirectory of the vim distribution to vimruntime.
|
|
|
|
Note: Logicals $VIMRUNTIME and $TMP are optional. Read more at :help runtime
|
|
|
|
|
|
|
|
<sect2> Practical usage
|
|
<p>
|
|
Usually you want to run just one version of Vim on your system, therefore
|
|
it is enough to dedicate one directory for Vim.
|
|
Copy all Vim runtime directory structure to the deployment position.
|
|
Add the following lines to your LOGIN.COM (in SYS$LOGIN directory).
|
|
Set up logical $VIM as:
|
|
|
|
<code>
|
|
> $ define VIM device: <path>
|
|
</code>
|
|
|
|
Set up some symbols:
|
|
|
|
<code>
|
|
> $ ! vi starts Vim in chr. mode.
|
|
> $ vi*m :== mcr device:<path>VIM.EXE
|
|
|
|
> $ !gvi starts Vim in GUI mode.
|
|
> $ gv*im :== spawn/nowait mcr device:<path>VIM.EXE -g
|
|
</code>
|
|
|
|
Create .vimrc and .gvimrc files in your home directory (SYS$LOGIN).
|
|
|
|
The easiest way is just rename example files. You may leave the menu file
|
|
(MENU.VIM) and files vimrc and gvimrc in the original $VIM directory. It will
|
|
be default setup for all users, and for users is enough just to have their
|
|
own additions or resetting in home directory in files .vimrc and .gvimrc.
|
|
It should work without problems.
|
|
|
|
Note: Remember, system rc files (default for all users) do not have the leading
|
|
"." So, system rc files are:
|
|
|
|
<code>
|
|
> VIM$:vimrc
|
|
> VIM$:gvimrc
|
|
> VIM$:menu.vim
|
|
</code>
|
|
and user's customised rc files are:
|
|
<code>
|
|
> sys$login:.vimrc
|
|
> sys$login:.gvimrc
|
|
</code>
|
|
|
|
You can check that everything is on the right place with the :version command.
|
|
|
|
<code>
|
|
Example LOGIN.COM:
|
|
|
|
> $ define/nolog VIM RF10:[UTIL.VIM]
|
|
> $ vi*m :== mcr VIM:VIM.EXE
|
|
> $ gv*im :== spawn/nowait mcr VIM:VIM.EXE -g
|
|
> $ set disp/create/node=192.168.5.223/trans=tcpip
|
|
</code>
|
|
|
|
Note: This set-up should be enough if you are working in a standalone server or
|
|
clustered environment, but if you want to use Vim as an internode editor, it
|
|
should suffice. You just have to define the "whole" path:
|
|
|
|
<code>
|
|
> $ define VIM "<server_name>[""user password""]::device:<path>"
|
|
> $ vi*m :== "mcr VIM:VIM.EXE"
|
|
</code>
|
|
|
|
as for example:
|
|
|
|
<code>
|
|
> $ define VIM "PLUTO::RF10:[UTIL.VIM]"
|
|
> $ define VIM "PLUTO""ZAY mypass""::RF10:[UTIL.VIM]" ! if passwd required
|
|
</code>
|
|
|
|
You can also use $VIMRUNTIME logical to point to proper version of Vim if you
|
|
have multiple versions installed at the same time. If $VIMRUNTIME is not defined
|
|
Vim will borrow value from $VIM logical. You can find more information about
|
|
$VIMRUNTIME logical by typing :help runtime as a Vim command.
|
|
|
|
|
|
|
|
<sect2> GUI mode questions
|
|
<p>
|
|
VMS is not a native X window environment, so you can not start Vim in GUI mode
|
|
"just like that". But it is not too complicated to get a running Vim.
|
|
|
|
<code>
|
|
1) If you are working on the VMS X console:
|
|
Start Vim with the command:
|
|
|
|
> $ mc device:<path>VIM.EXE -g
|
|
|
|
or type :gui as a command to the Vim command prompt. For more info :help gui
|
|
|
|
2) If you are working on other X window environment as Unix or some remote X
|
|
VMS console. Set up display to your host with:
|
|
|
|
> $ set disp/create/node=<your IP address>/trans=<transport-name>
|
|
|
|
and start Vim as in point 1. You can find more help in VMS documentation or
|
|
type: help set disp in VMS prompt.
|
|
Examples:
|
|
|
|
> $ set disp/create/node=192.168.5.159 ! default trans is DECnet
|
|
> $ set disp/create/node=192.168.5.159/trans=tcpip ! TCP/IP network
|
|
> $ set disp/create/node=192.168.5.159/trans=local ! display on the same node
|
|
</code>
|
|
|
|
Note: you should define just one of these.
|
|
For more information type $help set disp in VMS prompt.
|
|
|
|
|
|
<sect1> Install Vim on OS/2
|
|
<p>
|
|
Read the release notes for Vim on OS/2, see
|
|
<ref id="Before you Install">
|
|
.
|
|
|
|
At present there is no native PM version of the GUI version of vim: The OS/2
|
|
version is a console application. However, there is now a Win32s-compatible
|
|
GUI version, which should be usable by owners of Warp 4 (which supports
|
|
Win32s) in a Win-OS/2 session. The notes in this file refer to the native
|
|
console version.
|
|
|
|
To run Vim, you need the emx runtime environment (at least rev. 0.9b). This
|
|
is generally available as (ask Archie about it):
|
|
<code>
|
|
emxrt.zip emx runtime package
|
|
</code>
|
|
|
|
|
|
|
|
<sect1> Install Vim on Apple Macintosh
|
|
<p>
|
|
Read the release notes for Vim on OS/2, see
|
|
<ref id="Before you Install">
|
|
.
|
|
|
|
The author of Vim on Mac (old version vim 3.0) is
|
|
<code>
|
|
Eric Fischer
|
|
5759 N. Guilford Ave
|
|
Indianapolis IN 46220 USA
|
|
</code>
|
|
Email to
|
|
<htmlurl url="mailto:
|
|
enf@pobox.com
|
|
"name="
|
|
enf@pobox.com
|
|
">
|
|
|
|
Mac Bug Report
|
|
When reporting any Mac specific bug or feature change, makes sure to include
|
|
the following address in the "To:" or "Copy To:" field.
|
|
|
|
<htmlurl url="mailto:
|
|
dany.stamant@sympatico.ca
|
|
"name="
|
|
dany.stamant@sympatico.ca
|
|
">
|
|
|
|
Vim compiles out of the box with the supplied CodeWarrior project when using
|
|
CodeWarrior 9. If you are using a more recent version (e. g. CW Pro) you have
|
|
to convert the project first.
|
|
When compiling Vim for 68k Macs you have to open the "size" resource in
|
|
ResEdit and enable the "High level events aware" button to get drag and drop
|
|
working.
|
|
You have to increase the memory partition to at least 1024 kBytes to prevent
|
|
Vim from crashing due to low memory.
|
|
<code>
|
|
vim:ts=8:sw=8:tw=78:
|
|
</code>
|
|
|
|
|
|
<sect> Install Vim on Microsoft Windows 95/NT <label id="installmswin">
|
|
<p>
|
|
For Windows 95/NT, download the Vim zip file.
|
|
Double click on the vim.exe and <bf>do "FULL"
|
|
install and not "Typical"</bf> to get graphics and colors.
|
|
|
|
If you decide download in parts, then you must download <bf>TWO</bf> zip files -
|
|
<itemize>
|
|
<item> Runtime support file <bf>vim*rt.zip</bf>
|
|
<item> Vim command file <bf>vim*60.zip</bf>. Where Vim version is 5.6.
|
|
</itemize>
|
|
|
|
Get one big executable or two zip files from:
|
|
Goto <url url="http://www.vim.org"> and click on
|
|
Download-> download FAQ-> Windows 95/NT or click on these
|
|
<url url="ftp://vim.ftp.fu-berlin.de/pc/gvim60.zip"> and
|
|
<url url="ftp://vim.ftp.fu-berlin.de/pc/vim60rt.zip">.
|
|
( see also
|
|
<ref id="Before you Install">
|
|
)
|
|
|
|
Unpack the zip files using the Winzip <url url="http://www.winzip.com">.
|
|
Both the zip files (vim*rt.zip and vim*60.zip) must be unpacked
|
|
in the same directory like say <bf>c:\vim</bf>.
|
|
|
|
For Windows 95/98, set the environment variable VIM (all caps no lowercase) in
|
|
autoexec.bat by adding this line -
|
|
<code>
|
|
set VIM=c:\vim\vim60
|
|
</code>
|
|
For Windows NT, add the environment variable VIM (all caps no lowercase) to the
|
|
<bf>Start | Control Panel | System | Environment | System Properties</bf> dialog.
|
|
For Windows 2000, click on
|
|
<bf>Start | Control Panel | System | Advanced | Environment Variable</bf> dialog
|
|
and add variable VIM (all caps no lowercase):
|
|
<code>
|
|
VIM=c:\vim\vim60
|
|
</code>
|
|
|
|
The VIM variable should point to wherever you installed the vim60 directory.
|
|
You can also set your PATH to include the gvim.exe's path.
|
|
|
|
You may need to logoff and relogin to set your environment. Bring up a MS-DOS window by
|
|
click on Start->Programs->MSDOS (for Windows 95/98) and Start->Run->cmd (for Windows NT/2000).
|
|
At an MS-DOS prompt type -
|
|
<code>
|
|
c:\> set vim
|
|
c:\> cd vim\vim60
|
|
c:\> install.exe
|
|
</code>
|
|
For 'set vim' command, you should see - VIM=c:\vim\vim60 and start the install program
|
|
which will setup the enviroment.
|
|
|
|
Create a short-cut on to your desktop by click-and-drag
|
|
from c:\vim\vim60\gvim.exe.
|
|
|
|
<bf>Color Syntax Highlighting: </bf> To enable color syntaxt highlighting and
|
|
other nice features you must copy the gvimrc_example file to
|
|
the $VIM\_gvimrc. In my case it is c:\vim\vim60\_gvimrc.
|
|
<code>
|
|
c:\> copy c:\vim\vim60\gvimrc_example $VIM\_gvimrc
|
|
</code>
|
|
|
|
|
|
<bf>Useful Tips : </bf>
|
|
<itemize>
|
|
<item>Just double click on gvim icon on desktop and
|
|
click MyComputer->C:drive->Select a file and drag and drop it into the gvim window.
|
|
The file is automatically opened by gvim window!!
|
|
<p>
|
|
<item> To automatically maximize the Vim window in MS Windows, you can use
|
|
<url url="http://www.southbaypc.com/AutoSizer"> or you can right click on Gvim shortcut
|
|
and select properties and pick maximize the window on startup.
|
|
</itemize>
|
|
|
|
|
|
<sect1> Install bash shell
|
|
<p>
|
|
In order make MS Windows 95/98/NT/2000/XP even more user-friendly, install the
|
|
bash shell (Bourne Again Shell). Install
|
|
<url url="http://sources.redhat.com/cygwin/setup.exe">
|
|
(Cygwin-setup program) and select bash and other common utilities.
|
|
The CygWin main site is at <url url="http://sources.redhat.com/cygwin">.
|
|
With CygWin the Windows 2000 computer will look like Linux/Unix box!!
|
|
And combined with gvim editor, the Windows 2000 gives programmers more power.
|
|
The cygwin home is at <url url="http://cygwin.com">.
|
|
|
|
You may also want to install MKS in case you are planning to use Java and
|
|
Java compilers. Get MKS from <url url="http://www.mks.com">.
|
|
|
|
|
|
<sect1> Edit bash_profile
|
|
<p>
|
|
After installing the Cygwin, insert some useful aliases in ~/.bash_profile file.
|
|
Open a cygwin window and at bash prompt -
|
|
<code>
|
|
bash$ cd $HOME
|
|
bash$ gvim .bash_profile
|
|
set -o vi
|
|
alias ls='ls --color '
|
|
alias cp='cp -i '
|
|
alias mv='mv -i '
|
|
alias rm='rm -i '
|
|
alias vi='gvim '
|
|
alias vip='gvim ~/.bash_profile & '
|
|
alias sop='. ~/.bash_profile '
|
|
alias mys='mysql -uroot -p '
|
|
PATH=$PATH:"/cygdrive/c/Program Files/mysql/bin"
|
|
</code>
|
|
With color ls, when you do ls you will see all the directory names and files in
|
|
different colors (it looks great!!).
|
|
With set -o vi, you can use the command line history editing just as in linux.
|
|
|
|
|
|
<sect1> Setup Window colors
|
|
<p>
|
|
The default background color of MS DOS prompt window is black and white text.
|
|
You must change the color, fontsize and window size to make it more pleasing.
|
|
On MS Windows 2000, click on button Start->Run and type "cmd" and hit return.
|
|
On MS Windows 95/98/NT click on Start->Programs->MSDOS Prompt which will
|
|
bring up MSDOS window.
|
|
Right click on the top left corner of the MSDOS prompt window and select properties.
|
|
Select color background and enter R=255, G=255, B=190 (red, green, blue) for
|
|
lightyellow background
|
|
and text foreground color to black (R=0, G=0, B=0).
|
|
This sets background to light yellow and text foreground to black and this
|
|
combination is most pleasing to human eyes.
|
|
If you have problems with colors in cygwin bash window when doing 'man ls', set the
|
|
text color to "marune".
|
|
|
|
For Windows95 see <url name="Color for MS-DOS prompt window" url="http://www.elementkjournals.com/w95/9711/w9597b3.htm">.
|
|
|
|
|
|
<sect> Setup gvim init files
|
|
<p>
|
|
To enable the syntax color highlighting you MUST copy the gvimrc file to
|
|
your home directory. This will also put the "Syntax" Menu with gvim command.
|
|
You can click on Syntax Menu and select appropriate languages like C++, Perl, Java, SQL, ESQL etc..
|
|
<CODE>
|
|
cd $HOME
|
|
cp /usr/doc/vim-common-5.3/gvimrc_example ~/.gvimrc
|
|
</CODE>
|
|
Comment lines in .gvimrc begin with double-quotes (").
|
|
You can customize gvim by editing the file $HOME/.gvimrc and put the following lines -
|
|
<CODE>
|
|
" This line is a comment .... one which begins with double-quotes
|
|
" The best is the bold font, try all of these and pick one....
|
|
set guifont=8x13bold
|
|
"set guifont=9x15bold
|
|
"set guifont=7x14bold
|
|
"set guifont=7x13bold
|
|
"
|
|
" Highly recommended to set tab keys to 4 spaces
|
|
set tabstop=4
|
|
set shiftwidth=4
|
|
"
|
|
" The opposite is 'set wrapscan' while searching for strings....
|
|
set nowrapscan
|
|
"
|
|
" The opposite is set noignorecase
|
|
set ignorecase
|
|
set autoindent
|
|
"
|
|
" You may want to turn off the beep sounds (if you want quite) with visual bell
|
|
" set vb
|
|
|
|
" Source in your custom filetypes as given below -
|
|
" so $HOME/vim/myfiletypes.vim
|
|
</CODE>
|
|
It is <bf>very strongly</bf> recommended that you set the <it>tabstop</it> to 4 and
|
|
<it>shiftwidth</it> to 4.
|
|
The <it>tabstop</it> is the number of spaces the TAB key will indent while editing with gvim. The
|
|
<it>shiftwidth</it> is the number of spaces the lines will be
|
|
shifted with ">>" or "<<" vi commands. Refer to Vi
|
|
tutorials
|
|
<ref id="Vim Tutorial">
|
|
for more details.
|
|
|
|
To see the list of available fonts on Linux/Unix see
|
|
the command <bf>xlsfonts</bf>. Type -
|
|
<code>
|
|
bash$ xlsfonts | less
|
|
bash$ xlsfonts | grep -i bold | grep x
|
|
bash$ man xlsfonts
|
|
</code>
|
|
|
|
|
|
|
|
<sect1> Sample gvimrc file
|
|
<p>
|
|
You can change the settings like color, bold/normal fonts in your $HOME/.gvimrc file.
|
|
It is <bf>very strongly</bf> recommended that you set the background color
|
|
to <it>lightyellow</it> or <it>white</it> with <it>black</it> foreground. Ergonomics says
|
|
that best background color is
|
|
<it>lightyellow</it> or <it>white</it> with <it>black</it> foreground. Hence change
|
|
the variable 'guibg' in your $HOME/.gvimrc file as follows:
|
|
<code>
|
|
highlight Normal guibg=lightyellow
|
|
</code>
|
|
|
|
The sample gvimrc from /usr/doc/vim-common-5.3/gvimrc_example is as follows:
|
|
<CODE>
|
|
" Vim
|
|
" An example for a gvimrc file.
|
|
" The commands in this are executed when the GUI is started.
|
|
"
|
|
" To use it, copy it to
|
|
" for Unix and OS/2: ~/.gvimrc
|
|
" for Amiga: s:.gvimrc
|
|
" for MS-DOS and Win32: $VIM\_gvimrc
|
|
|
|
" Make external commands work through a pipe instead of a pseudo-tty
|
|
"set noguipty
|
|
|
|
" set the X11 font to use. See 'man xlsfonts' on unix/linux
|
|
" set guifont=-misc-fixed-medium-r-normal--14-130-75-75-c-70-iso8859-1
|
|
set guifont=8x13bold
|
|
"set guifont=9x15bold
|
|
"set guifont=7x14bold
|
|
"set guifont=7x13bold
|
|
"
|
|
" Highly recommended to set tab keys to 4 spaces
|
|
set tabstop=4
|
|
set shiftwidth=4
|
|
"
|
|
" The opposite is 'set wrapscan' while searching for strings....
|
|
set nowrapscan
|
|
"
|
|
" The opposite is set noignorecase
|
|
set ignorecase
|
|
"
|
|
" You may want to turn off the beep sounds (if you want quite) with visual bell
|
|
" set vb
|
|
|
|
" Source in your custom filetypes as given below -
|
|
" so $HOME/vim/myfiletypes.vim
|
|
|
|
" Make command line two lines high
|
|
set ch=2
|
|
|
|
" Make shift-insert work like in Xterm
|
|
map <S-Insert> <MiddleMouse>
|
|
map! <S-Insert> <MiddleMouse>
|
|
|
|
" Only do this for Vim version 5.0 and later.
|
|
if version >= 500
|
|
|
|
" I like highlighting strings inside C comments
|
|
let c_comment_strings=1
|
|
|
|
" Switch on syntax highlighting.
|
|
syntax on
|
|
|
|
" Switch on search pattern highlighting.
|
|
set hlsearch
|
|
|
|
" For Win32 version, have "K" lookup the keyword in a help file
|
|
"if has("win32")
|
|
" let winhelpfile='windows.hlp'
|
|
" map K :execute "!start winhlp32 -k <cword> " . winhelpfile <CR>
|
|
"endif
|
|
|
|
" Hide the mouse pointer while typing
|
|
set mousehide
|
|
|
|
" Set nice colors
|
|
" background for normal text is light grey
|
|
" Text below the last line is darker grey
|
|
" Cursor is green
|
|
" Constants are not underlined but have a slightly lighter background
|
|
highlight Normal guibg=grey90
|
|
highlight Cursor guibg=Green guifg=NONE
|
|
highlight NonText guibg=grey80
|
|
highlight Constant gui=NONE guibg=grey95
|
|
highlight Special gui=NONE guibg=grey95
|
|
|
|
endif
|
|
</CODE>
|
|
See also sample vimrc used for console mode vim command from /usr/doc/vim-common-5.3/vimrc_example.
|
|
|
|
|
|
<sect1> Xdefaults parameters
|
|
<p>
|
|
You can set some of the Vim properties in Xdefaults file.
|
|
|
|
<bf> WARNING: </bf><it>Do not set <bf>Vim*geometry</bf> as it will break the gvim menu, use <bf>Vim.geometry</bf> instead</it>.
|
|
|
|
Edit the $HOME/.Xdefaults file and add the following lines:
|
|
<CODE>
|
|
! GVim great Colors.
|
|
Vim*useSchemes: all
|
|
Vim*sgiMode: true
|
|
Vim*useEnhancedFSB: true
|
|
Vim.foreground: Black
|
|
!Vim.background: lightyellow2
|
|
Vim*background: white
|
|
! Do NOT use Vim*geometry , this will break the menus instead
|
|
! use Vim.geometry. Asterisk between Vim and geometry is not allowed.
|
|
! Vim.geometry: widthxheight
|
|
Vim.geometry: 88x40
|
|
!Vim*font: -misc-fixed-medium-r-normal--20-200-75-75-c-100-iso8859-15-*5
|
|
Vim*menuBackground: yellow
|
|
Vim*menuForeground: black
|
|
</CODE>
|
|
In order for this change to take effect, type -
|
|
<code>
|
|
xrdb -merge $HOME/.Xdefaults
|
|
man xrdb
|
|
</code>
|
|
|
|
You can also edit the &tilde/.gvimrc file to change the background colors
|
|
<CODE>
|
|
gvim $HOME/.gvimrc
|
|
The best background color is lightyellow or white, with black foreground.
|
|
highlight Normal guibg=lightyellow
|
|
</CODE>
|
|
|
|
|
|
<sect> Color Syntax init files
|
|
<p>
|
|
<sect1> Auto source-in method
|
|
<p>
|
|
This section below is obtained from gvim session by typing 'help syntax' -
|
|
<code>
|
|
bash$ gvim some_test
|
|
:help syntax
|
|
</code>
|
|
Click on the menu Window=>Close_Others to close other Window. And then do CTRL+] on 'Syntax Loading Procedure' menu which will take you there.
|
|
(Use CTRL+T to rewind and go back).
|
|
|
|
If a file type you want to use is not detected, then there are two ways to
|
|
add it.
|
|
|
|
|
|
<bf>Method 1: </bf> You can modify the <it>$VIMRUNTIME/filetype.vim</it> file,
|
|
but this is not recommended as it will be overwritten when you
|
|
install a new version of Vim.
|
|
|
|
<bf> Method 2: </bf> Create a file in $HOME/vim/myfiletypes.vim and put
|
|
these lines in it -
|
|
<code>
|
|
"
|
|
" *************************************************************
|
|
" Filename : $HOME/vim/myfiletypes.vim
|
|
" See the document by typing :help autocmd within vim session
|
|
" see also the doc at /usr/share/vim/doc/autocmd.txt
|
|
" This file will setup the autocommands for new filetypes
|
|
" using the existing syntax-filetypes.
|
|
" For example when you open foo.prc it will use syntax of plsql
|
|
" Basically does :set filetype=prc inside vim
|
|
" Add a line in $HOME/.gvimrc as below:
|
|
" so $HOME/vim/myfiletypes.vim
|
|
"
|
|
" *************************************************************
|
|
|
|
augroup filetype
|
|
au!
|
|
au! BufRead,BufNewFile *.phc set filetype=php
|
|
au! BufRead,BufNewFile *.mine set filetype=mine
|
|
au! BufRead,BufNewFile *.xyz set filetype=drawing
|
|
au! BufRead,BufNewFile *.prc set filetype=plsql
|
|
augroup END
|
|
</code>
|
|
Then add a line in your $HOME/.vimrc and $HOME/.gvimrc file to source
|
|
in the file "myfiletypes.vim".
|
|
(<bf>CAUTION:</bf> You MUST put this in both vimrc and gvimrc files
|
|
in order for this to work) Example:
|
|
<code>
|
|
so $HOME/vim/myfiletypes.vim
|
|
</code>
|
|
|
|
<bf>NOTE:</bf> Make sure that you set "so myfiletypes.vim" before switching on file type
|
|
detection. This is must be before any ":filetype on" or ":syntax on"
|
|
command.
|
|
|
|
See the documentation on autocommand at -
|
|
<itemize>
|
|
<item><bf>:help autocmd</bf> (within a vim editing session)
|
|
<item>See also the doc at /usr/share/vim/doc/autocmd.txt
|
|
</itemize>
|
|
|
|
Your file will then be sourced in after the default FileType autocommands have
|
|
been installed. This allows you to overrule any of the defaults, by using
|
|
":au!" to remove any existing FileType autocommands for the same pattern.
|
|
Only the autocommand to source the scripts.vim file is given later. This
|
|
makes sure that your autocommands in "myfiletypes.vim" are used before
|
|
checking the contents of the file.
|
|
|
|
|
|
|
|
<sect1> Manual method
|
|
<p>
|
|
Instead of using "Syntax" menu you can also
|
|
manually source in the syntax file. Edit the file with gvim
|
|
and at : (colon) command give 'so' command. For example -
|
|
<CODE>
|
|
gvim foo.pc
|
|
:so $VIM/syntax/esqlc.vim
|
|
</CODE>
|
|
The syntax source files are at /usr/share/vim/syntax/*.vim. Vim supports more
|
|
than 120 different syntax files for different languages like C++, PERL, VHDL, JavaScript,...and so on!!
|
|
|
|
Each syntax file supports one or more default file name extensions, for example, JavaScript syntax
|
|
file supports the *.js extension. If you happen to use an extension that conflicts with
|
|
another default syntax file (such as adding JavaScript to a *.html file) than you can source in
|
|
the additional syntax file with the command :so $VIM/syntax/javascript.vim.
|
|
To avoid all of this typing, you can create a soft link like -
|
|
<code>
|
|
ln -s $VIM/syntax/javascript.vim js
|
|
gvim foo.html (... this file contains javascript functions and HTML)
|
|
:so js
|
|
</code>
|
|
|
|
|
|
|
|
<sect> VIM Usage
|
|
<p>
|
|
You can use Vim in two modes - one with GUI and other without GUI.
|
|
To use GUI use command -
|
|
<CODE>
|
|
gvim foo.cpp
|
|
</CODE>
|
|
To use non-gui mode give -
|
|
<CODE>
|
|
vim foo.cpp
|
|
OR plain vanilla mode
|
|
vi foo.cpp
|
|
</CODE>
|
|
It is very strongly recommended that you always use gvim instead of vim, since GUI mode
|
|
with colors will definitely improve your productivity.
|
|
The vim also gives colors but cannot set the background colors and gvim can set the
|
|
background and foreground colors.
|
|
|
|
GUI mode gvim provides the following -
|
|
<itemize>
|
|
<item> You can mark the text using the mouse to do cut, copy and paste.
|
|
<item> You can use the Menu bar which has - File, Edit, Window, Tools, Synatx and Help buttons.
|
|
<item> Also in near future in gvim - a second menu bar will display the list of files being edited,
|
|
and you can switch files by clicking on the filenames, until then you can use
|
|
vi commands - :e#, :e#1, :e#2, :e#3, :e#4, ....so on to select the files.
|
|
</itemize>
|
|
|
|
|
|
<sect> Remote Vi - MS Windows QVWM Manager
|
|
<p>
|
|
QVWM Window Manager is the best as it is very similar in appearance to Microsoft Windows.
|
|
If you want to use Vi and Vim remotely from a MS Windows PC client, then
|
|
you should use VNC + QVWM manager. Servers are generally located
|
|
in remote Data Centers and to edit the files, you should first login
|
|
to remote servers from MS Windows or Linux desktop PCs.
|
|
After starting VNC server and QVWM manager on remote server, you should
|
|
fire up <bf>vncviewer</bf> on your client desktop and edit remote files
|
|
with <bf>gvim</bf>.
|
|
|
|
To use graphical editor like <bf>gvim</bf> for remote operations, use the
|
|
following techniques below:
|
|
|
|
You can use the VNC to display remote machines on your local display.
|
|
<itemize>
|
|
<item> The VNC is at <url url="http://www.uk.research.att.com/vnc">
|
|
and commercial VNC is at <url url="http://www.realvnc.com">
|
|
<p>
|
|
<item> Get VNC rpms from
|
|
<url name="rpmfind" url="http://rpmfind.net/linux/rpm2html/search.php?query=vnc">
|
|
or from commercial VNC at <url url="http://www.realvnc.com">
|
|
<p>
|
|
<item> The best Window manager for VNC is QVWM which is like MS Windows 98/NT/2000 interface, get
|
|
it from <url url="http://www.qvwm.org">.
|
|
<p>
|
|
<item> After starting vncserver, you can start the <bf>vncviewer</bf> program on clients
|
|
like MS Windows, Mac or Linux.
|
|
<p>
|
|
<item> See also the
|
|
<url name="List of X11 Windows Managers" url="http://www.dlhoffman.com/publiclibrary/RPM/X11_Window_Managers.html">.
|
|
</itemize>
|
|
|
|
<bf>Compiling qvwm on Solaris : </bf>
|
|
On Solaris you should install the following packages which you can get
|
|
from <url url="http://sun.freeware.com"> - xpm, imlib, jpeg, libungif, giflib (giftran),
|
|
libpng, tiff.
|
|
And you can download the binary package for solaris from
|
|
<url url="http://www.qvwm.org">.
|
|
|
|
Or you can download the qvwm source for solaris from
|
|
<url url="http://www.qvwm.org"> and compile it using gcc.
|
|
If mainsite is busy use the mirror sites listed there.
|
|
Click on the link "The latest version of qvwm is [ftp/http]" to
|
|
download the source code.
|
|
|
|
Troubleshooting the compile:
|
|
<itemize>
|
|
<item> You must install all the packages listed - xpm, imlib, jpeg, libungif,
|
|
giflib, libpng, tiff. Otherwise src will not compile
|
|
|
|
<item> Must edit the src/util.cc file and change snprintf to printf to compile
|
|
the program to get rid of the compile errors.
|
|
|
|
<item>You should put unsigned long before arg in usleep()
|
|
usleep((unsigned long) 10000)
|
|
|
|
<item> Still problems then see
|
|
<url url="http://www.milkywaygalaxy.freeservers.com/vnc"> for compile instructions.
|
|
|
|
</itemize>
|
|
|
|
For transferring files from Unix to MS Windows use the ftp clients like
|
|
<itemize>
|
|
<item> Commercial :
|
|
<enum>
|
|
<item> The ftp voyager <url url="http://cws.internet.com/ftp-ftpvoyag.html">
|
|
<item> Cute ftp <url url="http://cws.internet.com/ftp-cuteftp.html">
|
|
</enum>
|
|
|
|
<item> Free ratings:
|
|
<enum>
|
|
<item> WSFTP : <url url="http://www.csra.net/junodj/ws_ftp32.htm">
|
|
<item> LeechFTP <url url="http://cws.internet.com/ftp-leechftp.html">
|
|
<url url="http://stud.fh-heilbronn.de/~jdebis/leechftp/">
|
|
<item> FTP Control
|
|
<url url="http://cws.internet.com/ftp-ftpcontrol.html">
|
|
<item> GetRight <url url="http://cws.internet.com/ftp-getright.html">
|
|
</enum>
|
|
</itemize>
|
|
|
|
|
|
|
|
|
|
<sect> Vi companions
|
|
<p>
|
|
Generally Vim is used in conjunction with other powerful
|
|
tools like <bf>ctags</bf> and <bf>gdb</bf>. <bf>ctags</bf> is for very rapid navigation
|
|
through millions of lines of "C/C++" code and <bf>gdb</bf> is for debugging the "C/C++" code.
|
|
A brief introduction of these two indispensable commands will be given in this chapter.
|
|
<p>
|
|
<bf>ctags</bf> is the most powerful command available for coding C, C++, Java, Perl,
|
|
Korn/Bourne shell scripts or Fortran. Developers very extensively use <bf>ctags</bf> to
|
|
navigate through thousands of functions within C/C++ programs. See 'man ctags' on Unix.
|
|
It is <bf>very important</bf> that you learn how to use ctags to
|
|
develop programs in C or C++, Java, etc.. Navigation is the single most important task while
|
|
doing development of C or C++ code. Using ctags you can very quickly read the code
|
|
by jumping from a calling line to the called function, drill down deeper into nested function calls,
|
|
and unwind back all the way up to the top. You can go back and forth from function to function
|
|
very quickly.
|
|
|
|
Without NAVIGATION you will be completely lost! <bf>ctags</bf> is like the magnetic COMPASS
|
|
needle for the programmers.
|
|
|
|
Usage of <bf>ctags</bf> :
|
|
<code>
|
|
ctags *.cpp
|
|
gvim -t foo_function
|
|
gvim -t main
|
|
</code>
|
|
This will edit the C++ program file which contains the function foo_function() and will
|
|
automatically place the cursor on the first line of the function foo_function(). The second
|
|
command takes you to the line with the main() function definition.
|
|
|
|
Inside the Vim editor, you can jump to a function by typing : (colon) tag < function name >
|
|
as below -
|
|
<code>
|
|
:tag sample_function
|
|
</code>
|
|
This will place the cursor on first line of sample_function()
|
|
|
|
If you want to jump into the function from a line in file which contains the function name, place the
|
|
cursor just before the function name and press <bf>CTRL+]</bf> (press control key and
|
|
left-square-bracket key simultaneously).
|
|
<code>
|
|
// example code
|
|
switch(id_number) {
|
|
Case 1:
|
|
if ( foo_function( 22, "abcef") == 3 )
|
|
^
|
|
|
|
|
|
|
|
|
|
|
Place the cursor here (just before foo_function) and press CTRL+]
|
|
This takes you to the function named "foo_function".
|
|
To come back to this line press CTRL+t
|
|
</code>
|
|
To go back to the calling line press <bf>CTRL+t</bf> (Control key and letter 't' together). Keep pressing <bf>CTRL+t</bf>
|
|
to unwind and go to the first line where you started the navigation. That is you can keep pressing <bf>CTRL+]</bf>
|
|
and then keep pressing <bf>CTRL+t</bf> to go back. You can repeat these as many times as you want to have complete
|
|
navigation through all the functions of C or C++.
|
|
|
|
<sect1> Directory Tree 'tags'
|
|
<p>
|
|
To recursively process the tags file for the entire directory :
|
|
<code>
|
|
$ cd $HOME
|
|
$ ctags -R
|
|
</code>
|
|
This will recurse the directory underneath and create a tag file all the files
|
|
under the directory and beneath. But to use this tag file you must set the following
|
|
in the vim session or modify .gvimrc file
|
|
<code>
|
|
$ vi ~/.gvimrc
|
|
" Set the tag file search order
|
|
set tags=./tags,tags,~/tags,/home/john/ccplus/tags
|
|
</code>
|
|
|
|
Or in the Vim session you set the tags with colon command:
|
|
<code>
|
|
$ vi somefile.cpp
|
|
:set tags=./tags,tags,~/tags,/home/john/ccplus/tags
|
|
</code>
|
|
|
|
|
|
|
|
<sect1> Ctags for ESQL
|
|
<p>
|
|
Since ctags does not directly support the Embedded SQL/C (ESQL) language, the following shell script
|
|
can be used to create tags for esql. ESQL/C is database SQL commands embedded inside the "C" programs.
|
|
Oracle's ESQL/C is called Pro*C and Sybase, Informix have ESQL/C and PostgreSQL has product "ecpg".
|
|
<p>
|
|
Save this file as "sqltags.sh" and do chmod a+rx tags_gen.sh.
|
|
<code>
|
|
#!/bin/sh
|
|
|
|
# Program to create ctags for ESQL, C++ and C files
|
|
ESQL_EXTN=pc
|
|
tag_file1=tags_file.1
|
|
tag_file2=tags_file.2
|
|
|
|
which_tag=ctags
|
|
|
|
rm -f $tag_file1 $tag_file2 tags
|
|
|
|
aa=`ls *.$ESQL_EXTN`
|
|
#echo $aa
|
|
for ii in $aa
|
|
do
|
|
#echo $ii
|
|
jj=`echo $ii | cut -d'.' -f1`
|
|
#echo $jj
|
|
|
|
if [ ! -f $jj.cpp ]; then
|
|
echo " "
|
|
echo " "
|
|
echo "***********************************************"
|
|
echo "ESQL *.cpp files does not exist.. "
|
|
echo "You must generate the *.cpp from *.pc file"
|
|
echo "using the Oracle Pro*C pre-compiler or Sybase"
|
|
echo "or Informix esql/c pre-compiler."
|
|
echo "And then re-run this command"
|
|
echo "***********************************************"
|
|
echo " "
|
|
exit
|
|
fi
|
|
|
|
rm -f tags
|
|
$which_tag $jj.cpp
|
|
kk=s/$jj\.cpp/$jj\.pc/g
|
|
|
|
#echo $kk > sed.tmp
|
|
#sed -f sed.tmp tags >> $tag_file1
|
|
|
|
#sed -e's/sample\.cpp/sample\.pc/g' tags >> $tag_file1
|
|
sed -e $kk tags >> $tag_file1
|
|
done
|
|
|
|
# Now handle all the C++/C files - exclude the ESQL *.cpp files
|
|
rm -f tags $tag_file2
|
|
bb=`ls *.cpp *.c`
|
|
aa=`ls *.$ESQL_EXTN`
|
|
for mm in $bb
|
|
do
|
|
ee=`echo $mm | cut -d'.' -f1`
|
|
file_type="NOT_ESQL"
|
|
# Exclude the ESQL *.cpp and *.c files
|
|
for nn in $aa
|
|
do
|
|
dd=`echo $nn | cut -d'.' -f1`
|
|
if [ "$dd" = "$ee" ]; then
|
|
file_type="ESQL"
|
|
break
|
|
fi
|
|
done
|
|
|
|
if [ "$file_type" = "ESQL" ]; then
|
|
continue
|
|
fi
|
|
|
|
rm -f tags
|
|
$which_tag $mm
|
|
cat tags >> $tag_file2
|
|
done
|
|
|
|
mv -f $tag_file2 tags
|
|
cat $tag_file1 >> tags
|
|
rm -f $tag_file1
|
|
|
|
# Must sort tags file for it work properly ....
|
|
sort tags > $tag_file1
|
|
mv $tag_file1 tags
|
|
</code>
|
|
|
|
|
|
|
|
<sect1> Ctags for JavaScript programs, Korn, Bourne shells
|
|
<p>
|
|
The shell script given below can be used to generate tags for a very large variety of programs
|
|
written in JavaScript, PHP/FI scripts, Korn shell, C shell, Bourne shell and many others. This is
|
|
a very generic module.
|
|
|
|
Save this file as tags_gen.sh and do chmod a+rx tags_gen.sh.
|
|
<code>
|
|
#!/bin/sh
|
|
|
|
tmp_tag=tags_file
|
|
tmp_tag2=tags_file2
|
|
|
|
echo " "
|
|
echo " "
|
|
echo " "
|
|
echo " "
|
|
echo " "
|
|
echo "Generate tags for ...."
|
|
while :
|
|
do
|
|
echo " Enter file extension for which you want to generate tags."
|
|
echo -n " File-extension should be like sh, js, ksh, etc... : "
|
|
read ans
|
|
|
|
if [ "$ans" == "" ]; then
|
|
echo " "
|
|
echo "Wrong entry. Try again!"
|
|
else
|
|
break
|
|
fi
|
|
done
|
|
|
|
\rm -f $tmp_tag
|
|
|
|
aa=`ls *.$ans`
|
|
|
|
for ii in $aa
|
|
do
|
|
jj=`echo $ii | cut -d'.' -f1`
|
|
#echo $jj
|
|
cp $ii $jj.c
|
|
ctags $jj.c
|
|
echo "s/$jj.c/$ii/g" > $tmp_tag2
|
|
sed -f $tmp_tag2 tags >> $tmp_tag
|
|
\rm -f tags $jj.c
|
|
done
|
|
|
|
sort $tmp_tag > tags
|
|
|
|
\rm -f $tmp_tag $tmp_tag2
|
|
</code>
|
|
|
|
|
|
|
|
<sect1> Debugger gdb
|
|
<p>
|
|
You would be using gdb extensively along with Vi.
|
|
Debugging is the most important aspect of programming
|
|
as the major cost of software projects goes into debugging and testing.
|
|
<p>
|
|
To debug C++/C programs use 'gdb' tool. See <bf>'man gdb'</bf>.
|
|
You must compile your programs with -g3 option like
|
|
<tscreen><verb>
|
|
gcc -g3 foo.c foo_another.c sample.c
|
|
</verb></tscreen>
|
|
|
|
To set up easy aliases do -
|
|
<tscreen><verb>
|
|
Setup an alias in your ~/.bash_profile
|
|
alias gdb='gdb -directory=/home/src -directory=/usr/myname/src '
|
|
Give -
|
|
gdb foo.cpp
|
|
gdb> dir /hom2/another_src
|
|
This will add to file search path
|
|
gdb> break 'some_class::func<TAB><TAB>
|
|
This will complete the function name saving you typing time... and will output like -
|
|
gdb> break 'some_class::function_foo_some_where(int aa, float bb)'
|
|
</verb></tscreen>
|
|
|
|
Pressing TAB key twice is the command line completion, which will save
|
|
you lots of typing time. This is one of the most important technique of using gdb.
|
|
|
|
To get online help do -
|
|
<tscreen><verb>
|
|
gdb> help
|
|
Gives online help
|
|
gdb> help breakpoints
|
|
Gives more details about breakpoints.
|
|
</verb></tscreen>
|
|
|
|
To set breakpoints and do debugging
|
|
<tscreen><verb>
|
|
unixprompt> gdb exe_filename
|
|
gdb> b main
|
|
This will put breakpoint in main() function
|
|
gdb> b 123
|
|
This will put breakpoint in line 123 of the current file
|
|
gdb> help breakpoints
|
|
Gives more details about breakpoints.
|
|
</verb></tscreen>
|
|
|
|
To analyze the core dumps do
|
|
<tscreen><verb>
|
|
unixprompt> gdb exe_filename core
|
|
gdb> bt
|
|
Gives backtrace of functions and line numbers where the program failed
|
|
gdb> help backtrace
|
|
Gives more details about backtrace.
|
|
</verb></tscreen>
|
|
<p>
|
|
You can also use GUI version of gdb called xxgdb.
|
|
|
|
See also gdb interface to Vim at <url url="http://www.lxlinux.com/gdbvim.tgz">.
|
|
<p>
|
|
Memory leak tools -
|
|
<itemize>
|
|
<item> Freeware Electric Fence on linux cd,
|
|
<item> Commercial tools Purify <url url="http://www.rational.com">
|
|
<item> Insure++ <url url="http://www.insure.com">
|
|
</itemize>
|
|
<p>
|
|
|
|
|
|
|
|
<sect> Online VIM help
|
|
<p>
|
|
See the online man pages. At unix shell prompt
|
|
type <bf>'man vim'</bf> and <bf>'man gvim'</bf>.
|
|
|
|
Or inside the gvim session type :help to get the help page. See also <ref id="Vim Tutorial">
|
|
To see the settings type :set all or :set. To see list of options type :options.
|
|
To see topics on set type :help set.
|
|
|
|
<tscreen><verb>
|
|
VIM - main help file
|
|
|
|
Move around: Use the cursor keys, or "h" to go left,
|
|
"j" to go down, "k" to go up, "l" to go right.
|
|
":1" takes you to 1st line of page
|
|
":n" takes you to nth line of page
|
|
"<SHIFT>g" takes you to bottom of page
|
|
":/someword/ will search for "someword" in doc
|
|
|
|
Close this window: Use ":q<Enter>".
|
|
|
|
Jump to a subject: Position the cursor on a tag between |bars| and hit CTRL-].
|
|
|
|
With the mouse: ":set mouse=a" to enable the mouse (in xterm or GUI).
|
|
Double-click the left mouse button on a tag between |bars|.
|
|
|
|
jump back: Type CTRL-T or CTRL-O.
|
|
|
|
Get specific help: It is possible to go directly to whatever you want help
|
|
on, by giving an argument to the ":help" command |:help|.
|
|
It is possible to further specify the context:
|
|
WHAT PREPEND EXAMPLE ~
|
|
Normal mode commands (nothing) :help x
|
|
Visual mode commands v_ :help v_u
|
|
Insert mode commands i_ :help i_<Esc>
|
|
command-line commands : :help :quit
|
|
command-line editing c_ :help c_<Del>
|
|
Vim command arguments - :help -r
|
|
options ' :help 'textwidth'
|
|
|
|
list of documentation files:
|
|
|
|
|howto.txt| how to do the most common things
|
|
|intro.txt| introduction to Vim
|
|
|index.txt| alphabetical index for each mode
|
|
|autocmd.txt| automatically executing commands on an event
|
|
|change.txt| delete and replace text
|
|
</verb></tscreen>
|
|
|
|
|
|
|
|
<sect> Vim Home page and Vim links
|
|
<p>
|
|
The home page of vim is at <url url="http://www.vim.org">
|
|
and mirror site in US is at <url url="http://www.us.vim.org">
|
|
|
|
Vim FAQ is at <url url="http://www.grafnetix.com/~laurent/vim/faq.html">
|
|
and at <url url="http://www.vim.org/faq">
|
|
|
|
Eli's Vim Page at <url url="http://www.netusa.net/~eli/src/vim.html">
|
|
|
|
<!--
|
|
The Vi Lovers Home Page <url url="http://www.cs.vu.nl/~tmgil/vi.html">
|
|
-->
|
|
Vi Lovers home page <url url="http://www.thomer.com/thomer/vi/vi.html">
|
|
|
|
Vim Reference Guide at <url url="http://scisun.sci.ccny.cuny.edu/~olrcc/vim/">
|
|
|
|
Vim mailing list at <url url="http://www.findmail.com/listsaver/vimannounce.html">
|
|
and <url url="http://www.vim.org/mail.html">
|
|
|
|
Mailing list archives are kept at:
|
|
<itemize>
|
|
<item> <url url="http://www.egroups.com/group/vim">
|
|
<item> <url url="http://www.egroups.com/group/vimdev">
|
|
<item> <url url="http://www.egroups.com/group/vimannounce">
|
|
</itemize>
|
|
|
|
Vim macros <url url="http://www.grafnetix.com/~laurent/vim/macros.html">
|
|
|
|
|
|
|
|
<sect> Vim Tutorial <label id="Vim Tutorial">
|
|
<p>
|
|
|
|
|
|
<sect1> Vim Hands-on Tutorial <label id="vimhandson">
|
|
<p>
|
|
On Linux system see the tutorial at /usr/doc/vim-common-5.*/tutor, on other
|
|
unix systems go to directory where vim is installed and look for doc directory.
|
|
<code>
|
|
bash$ cd /usr/doc/vim-common*/tutor
|
|
bash$ less README.txt
|
|
bash$ cp tutor $HOME
|
|
bash$ cd $HOME
|
|
bash$ less tutor
|
|
</code>
|
|
|
|
|
|
|
|
<sect1> Vi Tutorials on Internet<label id="vimurls">
|
|
<p>
|
|
<itemize>
|
|
<item> Purdue University <url url="http://ecn.www.ecn.purdue.edu/ECN/Documents/VI/">
|
|
<p>
|
|
<item> Advanced Vi tutorial <url url="http://www.yggdrasil.com/bible/bible-src/user-alpha-4/guide/node171.html">
|
|
<p>
|
|
<item> Tutorials <url url="http://www.cfm.brown.edu/Unixhelp/vi_.html">
|
|
<p>
|
|
<item> Univ of Hawaii tutorial <url url="http://www.eng.hawaii.edu/Tutor/vi.html">
|
|
<p>
|
|
<item> InfoBound <url url="http://www.infobound.com/vi.html">
|
|
<p>
|
|
<item> Vi Lovers home page <url url="http://www.thomer.com/thomer/vi/vi.html">
|
|
<p>
|
|
<item> vi Help file <url url="http://www.vmunix.com/~gabor/vi.html">
|
|
<p>
|
|
These are dead links::
|
|
<item> Quick Vi tutorial <url url="http://linuxwww.db.erau.edu/LUG/node165.html">
|
|
<p>
|
|
<item> Tutorials <url url="http://www.linuxbox.com/~taylor/4ltrwrd/section3_4.html">
|
|
<p>
|
|
<item> Unix world online vi tutorial <url url="http://www.networkcomputing.com/unixworld/unixhome.html">
|
|
<p>
|
|
<item> Cornell Univ <url url="http://www.tc.cornell.edu/Edu/Tutor/Basics/vi/">
|
|
<p>
|
|
<item> Beginner's Guide to vi <url url="http://www.cs.umr.edu/unixinfo/general/packages/viguide.html">
|
|
<p>
|
|
<item> vim FAQ <url url="http://www.math.fu-berlin.de/~guckes/vim/faq/">
|
|
</itemize>
|
|
There are many Vi Tutorials on internet. In Yahoo (Lycos, excite or Hotbot)
|
|
enter "Vi Tutorial" in search field and search engine will return many pointers.
|
|
|
|
|
|
|
|
<sect> Vi Tutorial <label id="vimtut">
|
|
<p>
|
|
In this tutorial, we describe some "advanced" <bf>vi</bf> concepts and commands, so you can appreciate the power of <bf>vi</bf> and so you decide how to build your
|
|
knowledge of <bf>vi</bf> commands. Nearly all <bf>vi</bf> references list the available
|
|
commands, but many don't bother to discuss how the commands interrelate;
|
|
this topic is the main purpose of this tutorial.
|
|
|
|
|
|
<sect1> Cursor Movement Commands
|
|
<p>
|
|
The <bf>vi</bf> cursor movement commands allow you to position the cursor in the file
|
|
and/or on the screen efficiently, with a minimum number of keystrokes. There
|
|
are oodles of cursor movement commands - don't try memorizing them all at
|
|
once! Later, we'll see that much of the power of <bf>vi</bf> comes from mixing cursor
|
|
movement commands with other commands to delete, change, yank (copy), and
|
|
filter text.
|
|
|
|
Please edit a large text file (say, <bf>wknight</bf>) so you can experiment with each
|
|
command as it is described. Keep in mind these commands will only work in
|
|
Command Mode, not Insert Mode; if you start getting your "commands" in your
|
|
text, press the ESC key to return to Command Mode.
|
|
|
|
<itemize>
|
|
<item> <bf>cursor keys</bf> : As we've seen, cursor keys move by single character amounts
|
|
left, down, up, and right. Movement above the top of the file,
|
|
below the bottom, to the right of the end of a line, or left of the
|
|
beginning is not allowed (no line wrapping).
|
|
|
|
<p>
|
|
<item> <bf>hjkl</bf> : When <bf>vi</bf> was written (around 1978), many terminals on UNIX
|
|
systems did not have cursor keys! <bf>h, j, k,</bf> and <bf>l</bf> were chosen
|
|
as commands to move left, down, up, and right, respectively.
|
|
Try them! Most <bf>vi</bf> diehards prefer these to the cursor keys
|
|
because
|
|
<itemize>
|
|
<item><bf>(a)</bf> they are in the same place on all keyborads, and
|
|
<item><bf>(b)</bf> they fit nicely under the fingers, unlike
|
|
most cursor keys, which are arranged in a box or "T" or some
|
|
other nonlinear shape.
|
|
</itemize>
|
|
|
|
Why h, j, k, and l? Well, in the ASCII character set, CTRL-H is backspace
|
|
(moves left), CTRL-J is linefeed (moves down), and, of course, k and l are
|
|
next to h and j, so you see, they're mnemonic.
|
|
|
|
<p>
|
|
<item> <bf>0</bf> : ("zero", not "oh") Move to the beginning of current line. (To try
|
|
this and the next few commands, use the cursor keys or <bf>h j k l</bf> to
|
|
move to an indented text line that contains few "e"
|
|
characters. If you can't find an indented line in your file, create
|
|
one by inserting a few space characters at the beginning of a
|
|
line.)
|
|
|
|
<p>
|
|
<item> <bf> ^ </bf> : Move to first non-white character of current line. (For
|
|
indented line, 0 and ^ are different.)
|
|
|
|
<p>
|
|
<item> <bf> $ </bf> : Move to last character of current line.
|
|
|
|
<p>
|
|
<item> <bf> tC </bf> : Move to (but not on) next character c in current line. (Press 0,
|
|
then press te. This will move to the first e in the curent line.)
|
|
|
|
<p>
|
|
<item> <bf> fC </bf> : Find (move on top of) next character c in current line. (Press
|
|
fe, and the cursor will find - that is, move on top - the next e in
|
|
the current line.)
|
|
|
|
<p>
|
|
<item> <bf> TC </bf> : Move to (but not on) the previous character c in current line
|
|
(Press $, then Te.)
|
|
|
|
<p>
|
|
<item> <bf> FC </bf> : Find (move on top of) the previous character c in current line.
|
|
(Press Fe.)
|
|
|
|
<p>
|
|
<item> <bf> n| </bf> : Move to column n in current line. (Try 20 |. The digits 2 and 0
|
|
will not be displayed as you type them, but when you press | the cursor will
|
|
move to column 20.)
|
|
|
|
Try some experiments with t f T F | . When you do something illegal, <bf>vi</bf> will
|
|
beep your terminal.
|
|
|
|
<p>
|
|
<item> <bf> w </bf> : Forward to beginning of next "small" word ( a "small" word
|
|
consists of unbroken alphanumeric characters or punctuation characters, but
|
|
not mixed alphanumeric and punctuation). Try
|
|
tapping w a dozen times or so - note what happens at
|
|
punctuation.
|
|
|
|
<p>
|
|
<item> <bf> W </bf> : Forward to beginning of next "big" word (alphanumeric and
|
|
punctuation mixed). Try W a dozen times or so.
|
|
|
|
<p>
|
|
<item> <bf> b </bf> : Backward to beginning of "small" word.
|
|
|
|
<p>
|
|
<item> <bf> B </bf> : Backward to beginning of "big" word.
|
|
|
|
<p>
|
|
<item> <bf> e </bf> : Forward to end of "small" word.
|
|
<p>
|
|
<item> <bf> E </bf> : Forward to end of "big" word.
|
|
|
|
<p>
|
|
<item> <bf> + Return </bf> : Move to first non-white space character on next line. (+ and
|
|
the Return key have the same effect.)
|
|
|
|
<p>
|
|
<item> <bf> - </bf> : Move to first non-white space character on previous line.
|
|
|
|
<p>
|
|
<item> <bf> ) </bf> : Move to the end of sentence. (A sentence ends either at a
|
|
blank line or at a period or examination mark followed by two
|
|
space characters or at the end of a line. A period or
|
|
exclamation mark followed by one space character does not
|
|
end a sentence; this is correct behaviour, according to traditional
|
|
rules of how sentences should appear in typed documents, but often
|
|
appears wrong to those who have never suffered through
|
|
a formal typing class.)
|
|
|
|
<p>
|
|
<item> <bf> ( </bf> : Move to beginning of sentence.
|
|
|
|
<p>
|
|
<item> <bf> } </bf> : Move to end of paragraph. (Paragraphs are seperated with
|
|
blank lines, by <bf>vi</bf>'s definition.)
|
|
|
|
<p>
|
|
<item> <bf> { </bf> : Move to beginning of paragraph.
|
|
|
|
<p>
|
|
<item> <bf> H </bf> : Move to home position (top line) on the screen
|
|
|
|
<p>
|
|
<item> <bf> M </bf> : Move to middle line on the screen.
|
|
|
|
<p>
|
|
<item> <bf> L </bf> : Move to last line on the screen.
|
|
|
|
<p>
|
|
<item> <bf> nG </bf> : Move to line n. If n is not given, move
|
|
to the last line in the file.
|
|
(Try 15G to move to line 15, for example. The CTRL-G command displays
|
|
the name of the file, some status information, and the
|
|
current line number. To move to the top of the file: 1G)
|
|
|
|
<p>
|
|
<item> <bf> CTRL-d </bf> : Scroll down half-screen (see note).
|
|
<item> <bf> CTRL-u </bf> : Scroll up half-screen (see note).
|
|
<item> <bf> CTRL-f </bf> : Move forward one-screen (see note).
|
|
<item> <bf> CTRL-b </bf> : Move backward one-screen (see note).
|
|
<item> <bf> Note </bf> : These four scrolling/paging commands cannot be used
|
|
with the delete, change, yank, or filter commands.
|
|
|
|
<p>
|
|
<item> <bf> /reg_exp </bf> : Move to next occurrence of the regular expression reg_exp
|
|
When you press /, the cursor drops to the lower left corner of the screen and
|
|
waits for you to type in the regular expression.
|
|
Press the Return key to finish; <bf>vi</bf> then searches forward for the next
|
|
occurrence of the regular expression. For example, press /the followed by
|
|
Return. This moves forward to the next occurrence of the, perhaps imbedded
|
|
in the middle of some longer word (other, weather, etc.). If you just press /
|
|
and then Return, <bf>vi</bf> searches for the next occurrence of whatever the last
|
|
regular expression was that you searched for.
|
|
|
|
<p>
|
|
<item> <bf> n </bf> : Has the same effect as pressing / and then Return; i.e.,
|
|
searches for the next occurrence of whatever the last regular
|
|
expression was that you searched for.
|
|
|
|
<p>
|
|
<item> <bf> ?reg_exp </bf> : Searches backward, rather than forward. If no reg_exp is
|
|
given, it searches for the last regular expression that was entered.
|
|
Both / and ? wrap around, so searching "below" the bottom or "above" the
|
|
top of the file is legal.
|
|
|
|
<p>
|
|
<item> <bf> N </bf> : Same as pressing ? and then Return.
|
|
</itemize>
|
|
|
|
|
|
<sect1> Repeat Counts
|
|
<p>
|
|
Many of the movement commands discussed above can be preceded with a
|
|
repeat count; the movement is simply repeated the given number of times:
|
|
<itemize>
|
|
<item> <bf> 3w </bf> : Move forward three words
|
|
<item> <bf> 5k </bf> : Move up four characters
|
|
<item> <bf> 3fa </bf> : Find the third succeeding a in current line
|
|
<item> <bf> 6+ </bf> : Move down six lines
|
|
</itemize>
|
|
For some commands, the "repeat counts" has special meaning:
|
|
<itemize>
|
|
<item> <bf> 4H </bf> : Move to Line 4 on the screen (home plus 3)
|
|
<item> <bf> 8L </bf> : Move to the eigth line from the bottom of the screen
|
|
<item> <bf> 3$ </bf> : Move to the end of the third line down
|
|
</itemize>
|
|
For some commands (e.g., ^) the repeat count is ignored; for others (e.g.,
|
|
/ and ? ) it is illegal
|
|
|
|
|
|
|
|
<sect1> Deleting Text
|
|
<p>
|
|
We've seen that <bf>dd</bf> deletes the current line. This can be used
|
|
with a repeat
|
|
count: 3dd deletes three lines, the current line, and the two following lines.
|
|
|
|
The d command can be used as a "prefix" on most of the movement commands
|
|
above to delete nearly arbitrary chunks of text. When used with d, the
|
|
movement commands are called target specifiers. d can be given a repeat
|
|
count. (As you try these experiments, remember to press u after each command
|
|
to undo the deletion).
|
|
|
|
<itemize>
|
|
<item> <bf> dw </bf> : Delete "small" word forward
|
|
<item> <bf> d3w </bf> : Delete three "small" words forward
|
|
<item> <bf> 3dw </bf> : Three times, delete "small" word forward
|
|
<item> <bf> 3d3w </bf> : Three times, delete three "small" words forward (that is,
|
|
delete nine "small" words forward)
|
|
<item> <bf> d+ </bf> : Delete current line and next line down
|
|
<item> <bf> d/the </bf>: Delete from current character up to but not including the
|
|
next occurrence of the pattern the.
|
|
<item> <bf> d$ </bf> : Delete to end of line
|
|
<item> <bf> d0 </bf> : Delete to beginning of line
|
|
<item> <bf> d30G </bf> : Delete from the curent line to and including Line 30
|
|
<item> <bf> dG </bf> : Delete from current line to and including last line
|
|
<item> <bf> d1G </bf> : Delete from current line to and including Line 1
|
|
</itemize>
|
|
To delete single characters, use x. x can be given a repeat count:
|
|
<itemize>
|
|
<item> <bf> 15x </bf> : Delete current and 14 following characters
|
|
</itemize>
|
|
x is actually just an abbreviation of d1; that is, delete one character right.
|
|
|
|
|
|
<sect1> Changing Text
|
|
<p>
|
|
The c command is similar to d, except it toggles <bf>vi</bf> into Insert Mode, allowing
|
|
the original (unwanted) text to be changed to something else.
|
|
|
|
For example, put the cursor on the beginning of a word (press w to get to the
|
|
beginning of the next word). Then, press cw to change that word. On the
|
|
screen, the last character in the word being changed will be replaced
|
|
with a <bf>$</bf>
|
|
symbol indicating the boundary of the change; type in a new word (you will
|
|
overwrite the original word on the screen) and press the ESC key when done.
|
|
Your input may be longer or shorter than the word being changed.
|
|
|
|
Put the cursor at the beginning of a line containing at least three words, and
|
|
try c3w to change three words. Try c$ to change to the end of the current line.
|
|
In all cases where the change affects only the current line, the boundary of the
|
|
change is indicated with $.
|
|
|
|
When a change affects more than just the current line, <bf>vi</bf> deletes the original
|
|
text from the screen and toggles into Insert Mode. For example, try c3+ to
|
|
change the current and the next three lines; <bf>vi</bf> deletes the four
|
|
original lines from the screen and toggles into Insert Mode in a new blank line.
|
|
As usual, press the ESC key when you have finished entering your new text.
|
|
|
|
Some other change commands:
|
|
<itemize>
|
|
<item> <bf> cc </bf> : Change current line
|
|
<item> <bf> 5cc </bf> : Change five lines (current and next four)
|
|
<item> <bf> c/the </bf> : Change from current character up to but not including the next
|
|
occurrence of the pattern the
|
|
<item> <bf> c$ </bf> : Change to end of line
|
|
<item> <bf> c30G </bf> : Change from the current line to and including Line 30
|
|
<item> <bf> cG </bf> : Change from curernt line to and including last line
|
|
<item> <bf> c1G </bf> : Change from curernt line to and including Line 1
|
|
</itemize>
|
|
|
|
|
|
|
|
<sect1> Yanking (Copying) Text
|
|
<p>
|
|
The y command yanks a copy of text into a buffer; the yanked text can then
|
|
be put (or pasted) elsewhere in the file using p or P.
|
|
|
|
The simplest form of yank is yy to yank the current line; after yy, try p to
|
|
put a copy of the yanked line after the cursor. Following yy, you can make
|
|
as many copies of the yanked line as you want by moving up and down in the file
|
|
and pressing p.
|
|
|
|
To copy multiple lines, try, for example, 5yy (yank the current and next four
|
|
lines). p puts a copy of the yanked lines after the cursor; the sequence 5yyp
|
|
"works" but it probably doesn't do what you would like. The P command is like
|
|
p, but puts a copy of the yanked text ahead of the cursor; try the sequence
|
|
5yyP.
|
|
|
|
Other yank commands:
|
|
<itemize>
|
|
<item> <bf> y3w </bf> : Yank three words
|
|
<item> <bf> y$ </bf> : Yank to end of current line
|
|
<item> <bf> y1G </bf> : Yank from current line to and including Line 1
|
|
</itemize>
|
|
|
|
|
|
<sect1> Filtering text
|
|
<p>
|
|
The filter command <bf>!</bf>, prompts for the name of a UNIX command (which should
|
|
be a filter), then passes selected lines through the filter, replacing those
|
|
selected line in the <bf>vi</bf> buffer with the output of the filter command. <bf>vi</bf>'s
|
|
ability to pass nearly arbitrary chunks of text through any UNIX filter adds
|
|
incredible flexibility to <bf>vi</bf>, at no "additional cost" in size or performance to
|
|
<bf>vi</bf> itself.
|
|
|
|
Some examples will help illustrate. Create a line in your file containing just
|
|
the word who and absolutely no other text. Put the cursor on this line, and press <bf>!!</bf>
|
|
This command is analogous to dd, cc, or yy, but instead of deleting, changing,
|
|
or yanking the current line, it filters the current line. When you press the
|
|
second !, the cursor drops down to the lower left corner of the screen and a
|
|
single ! is displayed, prompting you to enter the name of a filter. As the
|
|
filter name, type sh and press the Return key. <bf>sh</bf> (the Bourne shell) is a filter!
|
|
It reads standard input, does some processing of its input (that is, executes
|
|
commands), and sends its output (the output of those commands) to standard output. Filtering the line containing who through sh causes the line containing who to be replaced with a list of the current users on the system - right in your file!
|
|
|
|
Try repeating this process with <bf>date</bf>. That is, create a line containing nothing
|
|
but the word <bf>date</bf>, then put the cursor on the line, and press <bf>!!sh</bf> and the
|
|
Return key. The line containing <bf>date</bf> is replaced with the output of the <bf>date</bf>
|
|
command.
|
|
|
|
Put your cursor on the first line of the output of who. Count the number of lines.
|
|
Suppose, for example, the number is six. Then select those six lines to be
|
|
filtered through sort; press <bf>6!!sort</bf> and the Return key. The six lines will
|
|
be passed through sort, and sort's output replaces the original six lines.
|
|
|
|
The filter command can only be used on complete lines, not on characters or
|
|
words.
|
|
|
|
Some other filter commands (here, < CR > means press Return):
|
|
<itemize>
|
|
<item> <bf>!/the < CR > sort < CR ></bf> : Sort from the current line up to and including the
|
|
next line containing the
|
|
<item><bf> !1Ggrep the < CR ></bf> : Replace from the current line to and including Line 1
|
|
with just the lines that contain the
|
|
<item><bf> !Gawk '{print $1}' < CR > </bf>: From the current line to the end of file, replace every line with just its first word.
|
|
</itemize>
|
|
|
|
|
|
|
|
<sect1> Marking Lines and Characters
|
|
<p>
|
|
You can mark lines and characters to be used as targest for movement, deletion,
|
|
change, yanking, and filtering using the command mc, where c is a
|
|
lowercase letter.
|
|
|
|
For example, put the cursor in the middle of some word and press ma. This
|
|
marks the character under the cursor as mark a.
|
|
|
|
Now, move the cursor off the marked character and to a different line ( use
|
|
the cursor keys, CTRL-u, or whatever). To return to the marked line, press 'a
|
|
(that is, single quote, then a). This moves to the first non-white space
|
|
character on the line containing mark a.
|
|
|
|
Move off that line again. To return to the marked character, press `a (that is,
|
|
backquote, then a). This moves on top of the character marked with a.
|
|
|
|
Marking is usually used with deleting, changing, yanking or filtering. For
|
|
example, move the cursor to a line other than the one containing mark a,
|
|
and then press d'a (d, single quote, a). This deletes from the current line to and
|
|
including the line marked with a.
|
|
|
|
Put the cursor in the middle of a different word and press mb to set mark b.
|
|
Now, move the cursor away from that word (but only a few lines, so you can see
|
|
what we're about to do more easily), and then press d`b (d, backquote, b).
|
|
This deletes from the current CHARACTER to and including the CHARACTER marked
|
|
with b.
|
|
|
|
As another example, to sort the output of who, mark the first line (ma), then
|
|
move the cursor to the last line and press !'asort and the Return key.
|
|
|
|
If you jump to a mark and decide you want to jump back to whatever you jumped
|
|
from, you can press '' (jump back to line) or `` (jump back to character).
|
|
|
|
|
|
<sect1> Naming Buffers
|
|
<p>
|
|
When you delete, change, or yank text, the original text is stored (until the next delete, change, or yank) in an unnamed buffer from which it can be put using
|
|
p or P. Using the unnamed buffer, only the most recently deleted, changed or yanked
|
|
text may be recovered.
|
|
|
|
If you wish to delete, change, or yank multiple sections of text and remember
|
|
them all (up to a maximum of 26), you can give a buffer name ahead of the
|
|
delete change or yank command. A buffer name has the form "c (double quote,
|
|
lowercase c).
|
|
|
|
For example, press "ayy to yank the current line into buffer a, then move to a
|
|
different line and press "byy to yank that line into buffer b. Now, move
|
|
elsewhere in the file and press "ap and "bp to put copies of the text
|
|
stored in buffers a and b.
|
|
|
|
Some other named buffer commands:
|
|
<itemize>
|
|
<item> <bf> "a6yy </bf> : Yank six lines (current and next five) into buffer a
|
|
<item> <bf> "bd1G </bf> : Delete from the curernt line to and including Line 1,
|
|
storing the deleted lines in buffer b
|
|
<item> <bf> "cy'c </bf> : Yank from the current line to the line marked c into buffer c
|
|
(marks and buffers are distinct, and may
|
|
have the same name without confusing <bf>vi</bf>)
|
|
</itemize>
|
|
|
|
|
|
|
|
<sect1> Substitutions
|
|
<p>
|
|
To substitute one chunk of text for another in lines throughout your file,
|
|
use the :s command. Some substitute examples:
|
|
<itemize>
|
|
<item> <bf> :1,$s/the/THE/g </bf> From Line 1 to the last line (line $), substitute
|
|
for the text THE; do this globally in each line where the occurrs
|
|
<item> <bf> :'a,.s/.*/ha ha/ </bf> From the line marked a to the current line (line .),
|
|
substitute for everything on the line the text ha ha
|
|
</itemize>
|
|
|
|
|
|
<sect1> Miscellaneous "Colon Commands"
|
|
<p>
|
|
All colon commands begin with a colon; when you press the colon, the cursor
|
|
drops to the lower left corner of the screen, and a colon prompt is displayed
|
|
waiting for you to finish your colon command.
|
|
|
|
Some important examples:
|
|
<itemize>
|
|
<item><bf>:w </bf> Write the buffer contents to the file without quitting from <bf>vi</bf>
|
|
<item><bf>:w abc </bf>Write the buffer contents to the file abc (creating abc
|
|
if it doesn't exist, or overwriting current contents if it does exist) without
|
|
quitting from <bf>vi</bf>
|
|
<item><bf>:1,10w abc </bf>Write lines 1 through 10 to file abc
|
|
<item><bf>:'a,$w abc </bf>Write from the line marked a to the last line into file abc
|
|
<item><bf>:e abc </bf>Edit file abc, instead of the current file. <bf>vi</bf> prints an error
|
|
message if changes have been made to the curernt file that have not been saved
|
|
with :w
|
|
<item><bf>:e! abc </bf>Edit file abc, throwing away any changes that may
|
|
have been made to the current file
|
|
<item><bf>:e # </bf>Edit the prior file edited (successive :e# commands toggle
|
|
back and forth between two files)
|
|
<item><bf>:f abc </bf>Change the file anme for the current <bf>vi</bf> buffer to abc
|
|
<item><bf>:q </bf>Quit, unless unsaved chanegs have been made
|
|
<item><bf>:q! </bf>Quit, throwing away any changes that may have been made
|
|
<item><bf>:r abc </bf>Read the file abc into current <bf>vi</bf> buffer, after the line the
|
|
cursor is on (try :r croc to read in a copy of the croc file)
|
|
<item><bf>:!cmd </bf>Execute command cmd (who, sort, ls, etc.)
|
|
</itemize>
|
|
|
|
|
|
<sect1> Setting Options
|
|
<p>
|
|
Various options affect the "feel" of <bf>vi</bf>. You can display all the various options
|
|
that can be set using the colon command :set all. You can also use set to
|
|
change options.
|
|
|
|
For example, if you want to see line numbers for the lines in the file you're
|
|
editing, use the command :set number. To turn off line numbering, use
|
|
the command :set nonumber. Most options can be abbreviated; :set nu turns
|
|
on line numbering and :set nonu turns off line numbering.
|
|
|
|
If you :set nomagic, the special meanings of regular expression characters
|
|
(period, asterisk, square bracket, etc.) are switched off. Use :set magic to
|
|
restore the special meanings.
|
|
|
|
Some options take a value. For example, :set tabstop=4 causes tabs to
|
|
be displayed as four space characters, rather than the usual eight.
|
|
|
|
If you find you always want certain options set certain ways, you can put the
|
|
set commands you want ina file .exrc, or you can set up the
|
|
environment variable EXINIT to specify the options you want.
|
|
|
|
For example, if your login shell is Bourne shell, this line could go in your
|
|
.profile file:
|
|
<code>
|
|
EXINIT='set nomagic nu tabstop=4'; export EXINIT
|
|
</code>
|
|
If your login shell is a C shell, this line could go in your .login file:
|
|
<code>
|
|
setenv EXINIT 'set nomagic nu tabstop=4'
|
|
</code>
|
|
|
|
|
|
<sect1> Key Mappings
|
|
<p>
|
|
If you find you're performing a series of simple commands over and over,
|
|
you can map the command series to an unused command key using the :map
|
|
command. If your mapping must include control characters such as Return
|
|
key (CTRL-M in ASCII) or the ESC (CTRL-[ in ASCII) key, precede such
|
|
characters with CTRL-v to suppress their usual special meaning.
|
|
|
|
For example, this command maps CTRL-A to move the cursor forward 55 lines,
|
|
then back up to the most recent blank line, then change that blank line
|
|
to a formfeed (CTRL-L) and three blank lines. That is, each CTRL-A will
|
|
paginate the next page, without splitting paragraphs across pages.
|
|
|
|
Note: In this command, each control character is shown as ^C, where C is
|
|
some uppercase letter. For example, CTRL-M is shown as ^M. Also, when you enter
|
|
this command you will not see the CTRL-v characters as shown: each CTRL-v
|
|
merely suppresses the usual special meaning of the following control
|
|
character, so when you press the sequence ^V^M, all you will see on the screen is
|
|
^M. In this command, ^M is the Return key and ^[ is the ESC key.
|
|
<code>
|
|
:map ^A 55+?^$^V^Mcc^V^L^V^M^V^M^V^M^V^[
|
|
</code>
|
|
|
|
|
|
<sect1> Editing Multiple Files
|
|
<p>
|
|
You can edit multiple files with <bf>vi</bf> by giving multiple file names as command
|
|
line arguments:
|
|
<code>
|
|
vi croc fatherw wknight
|
|
</code>
|
|
Three colon commands are used to move through the multiple files:
|
|
<itemize>
|
|
<item><bf> :n </bf>Move to the next file in the argument list (you must save
|
|
changes with :w or <bf>vi</bf> will print an error message)
|
|
<item><bf> :N </bf>Move to the previous file in the argument list (you must save
|
|
changes with :w or <bf>vi</bf> will print an error message)
|
|
<item><bf> :rew </bf>Rewind and start over with the first file in the argument list
|
|
</itemize>
|
|
The :n, :N, and :rew commands are somewhat clumsy, but there are some
|
|
important benefits: the contents of named buffers ("a, "b, "c, etc.) are
|
|
remembered across files, so you can use :n and :rew with p and P to copy
|
|
text back and forth between files. Also, the most recent search string for the
|
|
/ and ? commands remembered across files, so you can do repetitive searches
|
|
in multiple files rather easily.
|
|
|
|
For example, try the following experiment:
|
|
First get out of <bf>vi</bf>, then execute <bf>vi</bf> with croc and wknight as arguments:
|
|
<code>
|
|
$ vi croc wknight
|
|
</code>
|
|
In croc, search for the
|
|
|
|
<bf> /the < CR > </bf>
|
|
|
|
Yank this line into buffer a:
|
|
|
|
<bf> "ayy </bf>
|
|
|
|
Now go to the next file (you've made no change to croc, so this will work):
|
|
|
|
<bf> :n < CR > </bf>
|
|
|
|
Search for the "next" line containing the, without retyping the search string:
|
|
|
|
<bf> n </bf>
|
|
|
|
Put a copy of buffer a after the current line in wknight:
|
|
|
|
<bf> "ap </bf>
|
|
|
|
Move down two lines, and yank the current line into buffer b:
|
|
|
|
<bf> jj"byy </bf>
|
|
|
|
Save the changes to wknight
|
|
|
|
<bf> :w < CR > </bf>
|
|
|
|
Now, rewind to croc
|
|
|
|
<bf> :rew < CR > </bf>
|
|
|
|
Search again, and put a copy of buffer b after the found line:
|
|
|
|
<bf> n"bp </bf>
|
|
|
|
Save the changes, and exit <bf>vi</bf>
|
|
|
|
<bf> ZZ </bf>
|
|
|
|
|
|
<sect1> Final Remarks
|
|
<p>
|
|
This tutorial was intended to introduce some of the <bf>vi</bf> capabilities that you
|
|
might overlook in your system's <bf>vi</bf> manual or that might not be mentioned in
|
|
the manual (different systems have manuals of widely varying quality).
|
|
|
|
You will not be a <bf>vi</bf> expert after reading this tutorial, but you will have a
|
|
good appreciation of <bf>vi</bf>'s capabilities. Only time and effort can make a <bf>vi</bf>
|
|
expert. But the efficiency and universality of <bf>vi</bf> make this effort pay off in
|
|
the long run.
|
|
|
|
You may have decided you hate <bf>vi</bf>. So be it! But be aware that <bf>vi</bf> remains
|
|
the standard UNIX text editor - the one editor you can count on being
|
|
available on every UNIX system you'll use - so even if you prefer to use
|
|
something else day-to-day, you'd be well advised to know the bare minimum <bf>vi</bf>
|
|
material covered in this tutorial.
|
|
|
|
|
|
<sect> Vim Reference Card <label id="vimref">
|
|
<p>
|
|
<sect1> Vi states
|
|
<p>
|
|
Vi has 3 modes:
|
|
<enum>
|
|
<item> <bf><it>command mode</it></bf> - Normal and initial state; others return here (use <bf>ESC</bf> to abort a partially typed command)
|
|
<item> <bf><it>input mode</it></bf> - entered by specific commands <bf>a i A I o O c C s S R </bf> and ended by <bf>ESC</bf> or abnormally with interrupt
|
|
<item> <bf><it>line mode</it></bf> - i.e. waiting for input after a <bf>: </bf>, <bf>/ </bf>, <bf>? </bf> or a <bf>! </bf>
|
|
command (end with <bf>CR</bf>, abort with <bf>CTRL-c</bf>). <bf>CTRL</bf> is the control key: <bf>CTRL-c</bf> means "control c"
|
|
</enum>
|
|
|
|
|
|
<sect1> Shell Commands
|
|
<p>
|
|
<enum>
|
|
<item> <bf>TERM=</bf> <it>code</it> Puts a code name for your terminal into the variable <bf>TERM</bf>
|
|
<item> <bf>export TERM</bf> Conveys the value of <bf>TERM</bf> (the terminal code) to any UNIX system program that is terminal dependant.
|
|
<item> <bf>tput init</bf> Initializes the terminal so that it will function properly with various UNIX system programs.
|
|
<item> <bf>vi </bf> <it>filename</it> Accesses the <bf>vi</bf> screen editor so that you can edit a specified file.
|
|
<item> <bf>vi </bf> <it>file1 file2 file3</it> Enters three files into the <bf>vi</bf> buffer to be edited. Those files are <it>file1, file2,</it> and <it>file3</it>.
|
|
<item> <bf>view </bf> <it>file</it> Invoke vi editor on <it>file</it> in read-only mode
|
|
<item> <bf>vi -R </bf> <it>file</it> Invoke vi editor on <it>file</it> in read-only mode
|
|
<item> <bf>vi -r </bf> <it>file</it> Recover <it>file</it> and recent edits after system crash
|
|
</enum>
|
|
|
|
|
|
|
|
<sect1> Setting Options
|
|
<p>
|
|
<enum>
|
|
<item> <bf>:set</bf> <it>option</it> Activate <it>option</it>
|
|
<item> <bf>:set</bf> <it>option=value</it> Assign <it>value</it> to <it>option</it>
|
|
<item> <bf>:set no</bf> <it>option</it> Deactivate <it>option</it>
|
|
<item> <bf>:set </bf> Display options set by user
|
|
<item> <bf>:set all</bf> Display list of all current options, both default and those set by the user
|
|
<item> <bf>:set </bf> <it>option</it>? Display values of <it>option</it>
|
|
</enum>
|
|
|
|
|
|
<sect1> Notations used
|
|
<p>
|
|
Notations:
|
|
<enum>
|
|
<item> <bf>CTRL-c</bf> <bf>CTRL</bf> is the control key: <bf>CTRL-c</bf> means "control c"
|
|
<item> <bf>CR</bf> is Carriage return (ENTER key)
|
|
</enum>
|
|
|
|
|
|
|
|
<sect1> Interrupting, cancelling
|
|
<p>
|
|
<enum>
|
|
<item> <bf>ESC</bf> end insert or incomplete command
|
|
<item> <bf>CTRL-?</bf> <bf>CTRL</bf> is the control key: <bf>CTRL-?</bf> means "control ?" delete or rubout interrupts
|
|
<item> <bf>CTRL-l</bf> reprint/refresh screen if CTRL-? scrambles it
|
|
</enum>
|
|
|
|
|
|
|
|
<sect1> File Manipulation
|
|
<p>
|
|
<enum>
|
|
<item> <bf>ZZ</bf> Save the file and exit vi
|
|
<item> <bf>:wq</bf> Save the file and exit vi
|
|
<item> <bf>:w</bf> Write the current file
|
|
<item> <bf>:w!</bf> Force write the current file, if file is read-only
|
|
<item> <bf>:w<it>name</it></bf> Write to file <it>name</it>
|
|
<item> <bf>:q</bf> Exit from vi
|
|
<item> <bf>:q!</bf> Force exit from vi (discarding changes)
|
|
<item> <bf>:e name</bf> Edit file <it>name</it>
|
|
<item> <bf>:e!</bf> reedit, discard changes
|
|
<item> <bf>:e + name</bf> edit file <it>name</it>, starting at end
|
|
<item> <bf>:e + n</bf> edit starting at line <it>n</it>
|
|
<item> <bf>:e #</bf> edit alternate file
|
|
<item> <bf>:n</bf> edit next file in <it>arglist</it>
|
|
<item> <bf>:args</bf> list files in current filelist
|
|
<item> <bf>:rew</bf> rewind current filelist and edit first file
|
|
<item> <bf>:n args</bf> specify new arglist
|
|
<item> <bf>:f </bf> show current file and line
|
|
<item> <bf>CTRL-G</bf> synonym for :f , show current file and line
|
|
<item> <bf>:ta tag </bf> to tag file entry <it>tag</it>
|
|
<item> <bf>CTRL-] </bf> :ta, following word is tag
|
|
</enum>
|
|
|
|
|
|
<sect1> Movement
|
|
<p>
|
|
<enum>
|
|
<item> <bf>Arrows</bf> Move the cursor
|
|
<item> <bf>CTRL-d</bf> Scroll half page down
|
|
<item> <bf>CTRL-u</bf> Scroll half page up
|
|
<item> <bf>CTRL-f</bf> Scroll a full page down
|
|
<item> <bf>CTRL-b</bf> Scroll a full page up
|
|
<item> <bf>:0</bf> Move to start of file
|
|
<item> <bf>:n</bf> Move to line number n
|
|
<item> <bf>:$</bf> Move to end of file
|
|
<item> <bf>0</bf> Move to start of line
|
|
<item> <bf>^</bf> Move to first non-blank character
|
|
<item> <bf>$</bf> Move to end of line
|
|
<item> <bf>CR</bf> Move to the start of next line
|
|
<item> <bf>-</bf> Move to the start of previous line
|
|
<item> <bf>%</bf> Find matching bracket
|
|
<item> <bf>G </bf> goto line (last line default)
|
|
<item> <bf>&rsqb&rsqb </bf> next section/function
|
|
<item> <bf>&lsqb&lsqb </bf> previous section/function
|
|
</enum>
|
|
|
|
|
|
|
|
<sect1> Line Positioning
|
|
<p>
|
|
<enum>
|
|
<item> <bf>H </bf> Home window line
|
|
<item> <bf>L </bf> Last window line
|
|
<item> <bf>M </bf> Middle window line
|
|
<item> <bf>+ </bf> Next line, at first non-white
|
|
<item> <bf>- </bf> Previous line, at first non-white
|
|
<item> <bf>CR </bf> return, same as +
|
|
<item> <bf>j </bf> next line, same column
|
|
<item> <bf>k </bf> previous line, same column
|
|
</enum>
|
|
|
|
|
|
|
|
<sect1> Character positioning
|
|
<p>
|
|
<enum>
|
|
<item> <bf>0 </bf> beginning of line
|
|
<item> <bf>$ </bf> end of line
|
|
<item> <bf>h </bf> forward
|
|
<item> <bf>l </bf> backwards
|
|
<item> <bf>SPACE </bf> same as l
|
|
<item> <bf>fx </bf> find x forward
|
|
<item> <bf>Fx </bf> find x backward
|
|
<item> <bf>; </bf> repeat last f F
|
|
<item> <bf>, </bf> inverse of ;
|
|
<item> <bf>| </bf> to specified column
|
|
<item> <bf>% </bf> find matching { or }
|
|
</enum>
|
|
|
|
|
|
|
|
<sect1> Words, sentences, paragraphs
|
|
<p>
|
|
<enum>
|
|
<item> <bf>w </bf> Word forward
|
|
<item> <bf>b </bf> Word backward
|
|
<item> <bf>e </bf> End of word
|
|
<item> <bf>) </bf> To next sentence
|
|
<item> <bf>( </bf> Back sentence
|
|
<item> <bf>} </bf> To next paragraph
|
|
<item> <bf>{ </bf> Back paragraph
|
|
<item> <bf>W </bf> Blank delimited word
|
|
<item> <bf>B </bf> Back W
|
|
<item> <bf>E </bf> To end of W
|
|
</enum>
|
|
|
|
|
|
|
|
<sect1> Marking and returning
|
|
<p>
|
|
<enum>
|
|
<item> <bf>``</bf> (press twice the back-quote ` key) Previous context
|
|
<item> <bf>''</bf> (press twice the single-quote ` key) Previous context at first non-white in line
|
|
<item> <bf>mx</bf> mark position with letter x
|
|
<item> <bf>`x</bf> (back quote key and letter x) goto mark x
|
|
<item> <bf>'x</bf> goto mark x at first non-white in line
|
|
</enum>
|
|
|
|
|
|
|
|
<sect1> Corrections during insert
|
|
<p>
|
|
<enum>
|
|
<item> <bf>CTRL-h</bf> Erase last character
|
|
<item> <bf>CTRL-w</bf> Erase last word
|
|
<item> <bf>erase </bf> Press DELETE key, same as CTRL-h
|
|
<item> <bf>kill </bf> Your kill key, erase input this line
|
|
<item> <bf>\ </bf> Escapes CTRL-h, DELETE and kill
|
|
<item> <bf>ESC </bf> Ends insertion, back to command
|
|
<item> <bf>CTRL-? </bf> Interrupt, terminates insert
|
|
<item> <bf>CTRL-d </bf> Backtab over <it>autoindent</it>
|
|
<item> <bf>CTRL-v </bf> Quote non-printing character
|
|
</enum>
|
|
|
|
|
|
|
|
<sect1> Adjusting the screen
|
|
<p>
|
|
<enum>
|
|
<item> <bf>CTRL-l</bf> Clear and redraw
|
|
<item> <bf>CTRL-r</bf> retype, eliminate @lines
|
|
<item> <bf>z-CR</bf> redraw, current line at window top
|
|
<item> <bf>z-</bf> redraw, current line at window bottom
|
|
<item> <bf>z.</bf> redraw, current line at window center
|
|
<item> <bf>/pat/z-</bf> <it>pat</it> line bottom
|
|
<item> <bf>tn</bf> Use n line window
|
|
<item> <bf>CTRL-e</bf> Scroll window down 1 line
|
|
<item> <bf>CTRL-y</bf> Scroll window up 1 line
|
|
</enum>
|
|
|
|
|
|
|
|
<sect1> Delete
|
|
<p>
|
|
<enum>
|
|
<item> <bf>x</bf> Delete the character under the cursor
|
|
<item> <bf>X</bf> Delete the charater before the cursor
|
|
<item> <bf>D</bf> Delete to the end of line
|
|
<item> <bf>d^</bf> Delete back to start of line
|
|
<item> <bf>dd</bf> Delete the current line
|
|
<item> <bf>ndd</bf> Delete <it>n</it> lines starting with the current one
|
|
<item> <bf>dnw</bf> Delete <it>n</it> words starting from cursor
|
|
</enum>
|
|
|
|
|
|
|
|
<sect1> Insert, change
|
|
<p>
|
|
<enum>
|
|
<item> <bf>i</bf> Enter input mode inserting before the cursor
|
|
<item> <bf>I</bf> Enter input mode inserting before the first non-blank character
|
|
<item> <bf>a</bf> Enter input mode inserting after the cursor
|
|
<item> <bf>A</bf> Enter input mode inserting after the end of the line
|
|
<item> <bf>o</bf> Open a new line below current line and enter input mode
|
|
<item> <bf>O</bf> Open a new line above current line and enter input mode
|
|
<item> <bf>r</bf> Replace the character under the cursor (does NOT enter input mode)
|
|
<item> <bf>R</bf> Enter input mode replacing characters
|
|
<item> <bf>C</bf> shift-c. Change rest of line
|
|
<item> <bf>D</bf> shift-d. Delete rest of line
|
|
<item> <bf>s</bf> Substitute chars
|
|
<item> <bf>S</bf> Substitute lines
|
|
<item> <bf>J</bf> Join lines
|
|
<item> <bf>J</bf> Join lines
|
|
</enum>
|
|
|
|
|
|
<sect1> Copy and Paste
|
|
<p>
|
|
The "yank buffer" is filled by <it>EVERY</it> delete command, or explicitely by
|
|
<bf>Y</bf> and <bf>yy</bf>.
|
|
<enum>
|
|
<item> <bf>Y</bf> Copy the current line to the yank buffer
|
|
<item> <bf><it>n</it>yy</bf> Copy <it>n</it> lines starting from the current to the yank buffer
|
|
<item> <bf>p</bf> Paste the yank buffer after the cursor (or below the current line)
|
|
<item> <bf>P</bf> Paste the yank buffer before the cursor (or above the current line)
|
|
<item> <bf>"<it>x</it>p </bf> Put from buffer x
|
|
<item> <bf>"<it>x</it>y </bf> Yank to buffer x
|
|
<item> <bf>"<it>x</it>d </bf> Delete into buffer x
|
|
</enum>
|
|
|
|
|
|
<sect1> Operators (use double to affect lines)
|
|
<p>
|
|
<enum>
|
|
<item> <bf>d </bf> delete
|
|
<item> <bf>c </bf> change
|
|
<item> <bf>< </bf> left shift
|
|
<item> <bf>> </bf> right shift
|
|
<item> <bf>! </bf> filter through command
|
|
<item> <bf>= </bf> indent for LISP
|
|
<item> <bf>y </bf> yank text to buffer
|
|
</enum>
|
|
|
|
|
|
<sect1> Search and replace
|
|
<p>
|
|
<enum>
|
|
<item> <bf>/<it>text</it></bf> Search forward for <it>text</it>
|
|
<item> <bf>?<it>text</it></bf> Search backward for <it>text</it>
|
|
<item> <bf>n</bf> Repeat the last search in the same direction
|
|
<item> <bf>N</bf> Repeat the last search in the reverse direction
|
|
<item> <bf>/</bf> Repeat the last search forward
|
|
<item> <bf>?</bf> Repeat the last search backward
|
|
<item> <bf>&lsqb addr &rsqb s/from/to/ &lsqb g &rsqb </bf> Search for the occurence of <it>from</it>
|
|
and replace it with <bf><it>to</it></bf> in the current line, or in the range
|
|
<bf><it>addr</it></bf> (two line numbers seperated by command; 1,$ is the whole file).
|
|
Replaces one occurrence per line, or all occurrences
|
|
if <bf><it>g</it></bf> is specified.
|
|
For example, :3,20s/someword/anotherword/g Will replace "someword" with "anotherword" starting from line 3 to line 20. 'g' is global means replace all occurrences of "someword".
|
|
</enum>
|
|
|
|
|
|
<sect1> General
|
|
<p>
|
|
<enum>
|
|
<item> <bf>:sh</bf> Forks a shell (to be exited with CTRL-d)
|
|
<item> <bf>:!<it>command</it></bf> Forks a shell to execute <it>command</it>
|
|
<item> <bf>:set number</bf> Switch on line numbering
|
|
<item> <bf>:set nonumber</bf> Switch off line numbering
|
|
</enum>
|
|
|
|
|
|
<sect1> Line Editor Commands
|
|
<p>
|
|
<enum>
|
|
<item> <bf>:</bf> Tells <bf>vi</bf> that the next commands you issue will be line editor commands.
|
|
<item> <bf>:sh</bf> Temporarily returns to the shell to perform some shell commands without leaving <bf>vi</bf>.
|
|
<item> <bf>CTRL-d</bf> Escapes the temporary return to the shell and returns to <bf>vi</bf> so you can edit the current window.
|
|
<item> <bf>:</bf><it>n</it> Goes to the <it>n</it>th line of the buffer.
|
|
<item> <bf>:</bf><it>x,z</it><bf>w</bf> <it>filename</it> Writes lines from the numbers <it>x</it> through the number <it>z</it> into a new file called <it>filename</it>.
|
|
<item> <bf>:$</bf> Moves the cursor to the beginning of the last line in the buffer.
|
|
<item> <bf>:.,$d</bf> Deletes all the lines from the current line to the last line
|
|
<item> <bf>:r</bf> <it>filename</it> Inserts the contents of the file <it>filename</it> under the current line of the buffer.
|
|
<item> <bf>:s</bf><it>/text/new_text/</it> Replaces the first instance of <it>text</it> on the current line with <it>new_text</it>
|
|
<item> <bf>:s</bf><it>/text/new_text/g</it> Replaces the every occurrence of <it>text</it> on the current line with <it>new_text</it>
|
|
<item> <bf>:g</bf><it>/text/s//new_text/g</it> Changes every occurrence of <it>text</it> on the buffer to <it>new_text</it>.
|
|
</enum>
|
|
|
|
|
|
<sect1> Other commands
|
|
<p>
|
|
<enum>
|
|
<item> <bf>u</bf> Undo the last change
|
|
<item> <bf>U</bf> Restore the current line
|
|
<item> <bf>&tilde</bf> Change case
|
|
<item> <bf>J</bf> Join the currentline with the next line
|
|
<item> <bf>.</bf> Repeat last text changing command
|
|
<item> <bf>CTRL-g</bf> Show file name and line number
|
|
</enum>
|
|
|
|
|
|
<sect> Build Your "WYSIWYG" HTML Editor With Vi & Netscape
|
|
<p>
|
|
This section was written by
|
|
<url url="http://www.pcquest.com/content/linux/handson/101100102.asp" name="Manas K Laha">
|
|
, Aerospace Engineering Department, IIT Kharagpur, India.
|
|
This is about a quick and dirty way to create an HTML editor combining vi and Netscape.
|
|
|
|
If vi (or one of its friends, such as elvis or vim ) is your favorite text
|
|
editor, as it is mine, you must surely long for a way
|
|
of creating HTML with it quickly and comfortably. And
|
|
if with that you could get the convenience of
|
|
"WYSIWYG", wouldn't you just jump at it? All this is
|
|
indeed possible, and here we'll see how.
|
|
|
|
The major hurdles I've found in editing HTML with vi are
|
|
<enum>
|
|
<item> The need to write HTML tags. It appears that there
|
|
are more tags to be written than displayable matter. Moreover, some
|
|
of these tags have a syntax that is hard to remember.
|
|
<item> The need to keep track of whether an opening tag has been given
|
|
its proper closing tag at the right place (for example, whether a <
|
|
ol> has a
|
|
matching <
|
|
/ol> ).
|
|
<item> Difficulty in readily identifying matching pairs of tags.
|
|
</enum>
|
|
|
|
These can be got around using some of the less used features of vi and
|
|
friends. In this article I shall use vim for definiteness, but the ideas should
|
|
apply to classic vi and its other look-alikes as well.
|
|
|
|
The "abbreviation" feature of vim:
|
|
|
|
Vim has a feature whereby it is possible to assign a keystroke sequence to
|
|
represent a string of characters in input mode. This is the ab colon
|
|
command. For example, the command
|
|
<code>
|
|
:ab tT <
|
|
tt> <
|
|
/tt>
|
|
</code>
|
|
|
|
creates an abbreviation, named tT, for the sequence of characters <
|
|
tt><
|
|
/tt>.
|
|
Then, in input mode, as soon as the characters tT are typed, they are
|
|
replaced by the string <
|
|
tt><
|
|
/tt>. Complicated HTML tags may also be
|
|
abbreviated. The ab definition
|
|
|
|
<code>
|
|
:ab aH <a href=?http://?><!? { ?>^M
|
|
Comments here^M^D <
|
|
/a><!? } ?>
|
|
</code>
|
|
|
|
makes aH the shorthand for
|
|
|
|
<code>
|
|
<a href=?http://?><!? { ?>
|
|
Comments here
|
|
<
|
|
/a><!? } ?>
|
|
</code>
|
|
|
|
where the two ^M s cause the two line breaks and the ^D causes the closing
|
|
<
|
|
/a> tag to be indented back to be in line with the opening <
|
|
a> tag.
|
|
(Indenting the matter enclosed within a matching pair of tags makes reading and
|
|
editing the raw HTML easier.) The syntax of the tag is outlined, as an aid to
|
|
memory. The 'Comments here' line is a placeholder, to be replaced with
|
|
appropriate text.
|
|
|
|
What are the { and } within HTML comments doing there? Aha! Those are for
|
|
matching the opening and closing tags (in this case <
|
|
a> and <
|
|
/a>). The bracket
|
|
matching feature of vi (using the % key) is readily usable for the purpose. This
|
|
can be really helpful when the opening and closing tags are many lines apart
|
|
and cannot be readily matched 'by eye', such as can be the case with the
|
|
<
|
|
ol><
|
|
/ol> pair.
|
|
|
|
This technique can be extended to generate fancier HTML, for example with
|
|
frames. All one has to do is to define the appropriate abbreviations. For
|
|
example, the definition
|
|
|
|
<code>
|
|
:ab fS <
|
|
frameset scrolling=?no?
|
|
frameborder=?0? framespacing=?0?
|
|
cols=?20%,80%?><
|
|
!? { ?>^M <
|
|
/frameset> <
|
|
!?
|
|
} ?>
|
|
</code>
|
|
|
|
makes the string fS a convenient
|
|
abbreviation for the pair of tags:
|
|
|
|
<code>
|
|
<
|
|
frameset scrolling=?no? frameborder=?0?
|
|
framespacing=?0? cols=?20%,80%?> <
|
|
!? { ?>
|
|
<
|
|
/frameset><
|
|
!? } ?>
|
|
</code>
|
|
|
|
Some tags do not like comments to come in between the opening and closing pair.
|
|
The ones I have found are <
|
|
title><
|
|
/title> and <
|
|
a\ href=?mailto:?>
|
|
<
|
|
/a>. Luckily, in both these the opening and closing pair are never very far
|
|
apart, so the braces-within-comments feature is not needed.
|
|
|
|
<sect1>
|
|
Sample .vimhtmlrc File
|
|
<p>
|
|
How do I tell vim about these abbreviations? I put all of them (and a
|
|
command to set some of vim's variables) in a file, which I call .vimhtmlrc and
|
|
which resides in my home directory, and invoke
|
|
|
|
<code>
|
|
vim -u ~/.vimhtmlrc index.html
|
|
</code>
|
|
|
|
where index.html is the HTML file I want to edit. This is what my .vimhtmlrc
|
|
file looks like:
|
|
|
|
<code>
|
|
ab aH <
|
|
a href=?http://?><
|
|
!? { ?>^M
|
|
Comments here^M^D<
|
|
/a> <
|
|
!? } ?>
|
|
|
|
ab aM <
|
|
a href=?mailto:?>^M Comments
|
|
here^M^D <
|
|
/a>
|
|
|
|
ab bO <
|
|
body bgcolor=#e0e0e0
|
|
text=#000000><
|
|
!? { ?>^M <
|
|
/body> <
|
|
!? } ?>
|
|
|
|
ab bR <
|
|
br>
|
|
|
|
ab cE <
|
|
center bgcolor=#e0e0e0
|
|
text=#000000><
|
|
!? { ?>^M <
|
|
/center> <
|
|
!? } ?>
|
|
|
|
ab cM <
|
|
!? ^M ?>
|
|
|
|
ab cO <
|
|
code> <
|
|
!? { ?>^M <
|
|
/code> <
|
|
!? } ?>
|
|
|
|
ab dL <
|
|
dl><
|
|
!? { ?>^M<
|
|
/dl><
|
|
!? } ?>
|
|
|
|
ab dT <
|
|
dt>
|
|
|
|
ab fO <
|
|
font color=#000000>^M <
|
|
/font>
|
|
|
|
ab h1 <
|
|
h1><
|
|
!? { ?>^M Heading size
|
|
1^M^D <
|
|
/h1> <
|
|
!? } ?>
|
|
|
|
ab h2 <
|
|
h2><
|
|
!? { ?>^M Heading size
|
|
2^M^D <
|
|
/h2><
|
|
!? } ?>
|
|
|
|
ab h3 <
|
|
h3><
|
|
!? { ?>^M Heading size
|
|
3^M^D <
|
|
/h3> <
|
|
!? } ?>
|
|
|
|
ab hD <
|
|
head> <
|
|
!? { ?>^M <
|
|
/head> <
|
|
!? } ?>
|
|
|
|
ab hR <
|
|
hr>
|
|
|
|
ab hT <
|
|
html> <
|
|
!? { ?>^M <
|
|
/html> <
|
|
!? } ?>
|
|
|
|
ab iM <
|
|
img src=??>
|
|
|
|
ab lI <
|
|
li> <
|
|
!? { ?>^M <
|
|
/li> <
|
|
!? } ?>
|
|
|
|
ab oL <
|
|
ol> <
|
|
!? { ?>^M <
|
|
/ol> <
|
|
!? } ?>
|
|
|
|
ab pR <
|
|
pre> <
|
|
!? { ?>^M <
|
|
/pre> <
|
|
!? } ?>
|
|
|
|
ab tD <
|
|
td> <
|
|
!? { ?>^M <
|
|
/td> <
|
|
!? } ?>
|
|
|
|
ab tL <
|
|
title>^M Title here^M^D <
|
|
/title>
|
|
|
|
ab tS <
|
|
table bgcolor=?#d0d0d0?> <
|
|
!? {
|
|
?>^M <
|
|
/table> <
|
|
!? } ?>
|
|
|
|
ab tT <
|
|
tt> <
|
|
/tt>
|
|
|
|
ab uL <
|
|
ul> <
|
|
!? { ?>^M <
|
|
/ul> <
|
|
!? } ?>
|
|
|
|
ab xB <
|
|
b> <
|
|
/b>
|
|
|
|
ab xI <
|
|
i> <
|
|
/i>
|
|
|
|
ab xP <
|
|
p> <
|
|
!? { ?>^M <
|
|
/p> <
|
|
!? } ?>
|
|
se ai aw sw=4 ts=4 wm=10 showmode
|
|
showmatch ruler magic
|
|
</code>
|
|
|
|
When the ab commands are put in a file, to be read in by vim at startup, then
|
|
the leading :is not needed. The last line is a command to set some of vim 's
|
|
variables. Here is what they mean:
|
|
|
|
<code>
|
|
se set: tells vim to activate the options that follow autoindent: begin the next
|
|
ai line in the same column as this one (and not from column 1)
|
|
aw autowrite: automatically write file to disk when it changes on a TAB key, move cursor 4
|
|
ts=4 characters (and not the normal 8); this is my personal preference
|
|
sw=4 number of spaces to use for indentation chars from right margin where
|
|
wm=10 line wrapping starts (useful if one is writing running text and not programs)
|
|
message on status line to show
|
|
showmode current mode (for the novice, actually) briefly jump to matching
|
|
opening '(' or '{' or '[' as
|
|
showmatch soon as a closing ')' or '}' or ']' is typed; beep if no match
|
|
ruler show cursor line and column in status line some characters, such as '.'
|
|
magic and '*', have special meanings in search and replace patterns.
|
|
</code>
|
|
|
|
Typing help in a vim window shows the explanations for these options and many
|
|
more besides.
|
|
|
|
<sect1>
|
|
WYSIWYG
|
|
<p>
|
|
'WYSIWYG' has two parts to it. To begin with is the fact that Netscape under
|
|
Unix (and Linux) can be controlled remotely.
|
|
|
|
That is, you may control the behavior of an already running Netscape through
|
|
commands of the form
|
|
|
|
<code>
|
|
netscape -remote -noraise 'openFile(/home/mlaha/html/index.html)'
|
|
</code>
|
|
|
|
(If no Netscape is running, the command just exits with an error message.) This
|
|
command causes the Netscape browser window to attempt to open the file
|
|
/home/mlaha/html/index.html. For more on remote controlling Netscape, see
|
|
<url url="http://home.netscape.com/newsref/std/x-remote.html">.
|
|
|
|
And then, there is atchange . Jeffrey Copeland and Jeffrey Haemer
|
|
(<url url="http://alumni.caltech.edu/~copeland/work/edit-web.html"> ,
|
|
<url url="ftp://ftp.ncifcrf.gov/pub/delila/atchange">
|
|
and <url url="http://www.lecb.ncifcrf.gov/~toms/atchange.html"> )
|
|
describe a little shell script, called atchange, that waits in the
|
|
background for a named file to change and then invokes a specified command. Thus,
|
|
|
|
<code>
|
|
atchange index.html 'netscape -noraise -remote 'openFile(/home/mlaha/html/index.html)'' &
|
|
</code>
|
|
|
|
would cause atchange to run in the background, watching the file index.html
|
|
and, as soon as it changed, ask Netscape to display it afresh. If you were
|
|
editing index.html with vi, then, when you saved it (with :w, say), atchange
|
|
would spring into action and Netscape would update its display.
|
|
|
|
If you wish to edit another HTML file, you have to quit vim, kill the current
|
|
invocation of atchange, then start it again with the name of the new file in
|
|
place of index.html and begin editing that file with vim.
|
|
|
|
<sect1>
|
|
Other 'WYSIWYG' uses
|
|
<p>
|
|
As you may have guessed, atchange can be used in other instances, too. You can
|
|
make a handy 'WYSIWYG' LaTeX editor by having atchange monitor your LaTeX
|
|
source and, when it changed, run the necessary programs to convert it to
|
|
Postscript. The 'WYSIWYG' capability is provided in this case by invoking
|
|
Ghostview with the monitoring option (-watch) that causes it to redisplay its
|
|
current Postscript file whenever that file changes. Thus, every time you saved
|
|
your LaTeX source file in the editor, the Postscript output with the latest
|
|
changes would be automatically displayed in the Ghostscript window.
|
|
|
|
|
|
<sect1> Source code for atchange
|
|
<p>
|
|
<code>
|
|
#!/usr/local/bin/perl
|
|
# by Jeff Haemer
|
|
# and a tip o' the hat to Tom Schneider
|
|
# who wrote the original version as a shell script
|
|
|
|
# version = 2.07 of atchange 1999 Dec 30
|
|
|
|
# 1999 Dec 18: Added shell call to /bin/csh so that
|
|
# atchange works under Linux.
|
|
|
|
# 1999 Feb 5: By setting the PERLCSH variable, the new shell can tell
|
|
# it has been called by atchange.
|
|
# The test inside the .cshrc is:
|
|
#if ( (! $?PERLCSH ) && $?prompt) then
|
|
# stty erase '^H'
|
|
# set prompt = "`uname -n` \!% "
|
|
#endif
|
|
# This is necessary under Sun Solaris 2.6 because otherwise the
|
|
# call to stty gives an error message now.
|
|
|
|
# previous change: 1997 Jan 9
|
|
# delay time is 0.25 seconds
|
|
|
|
# For current version and other information about this program, see:
|
|
# http://www.lecb.ncifcrf.gov/~toms/atchange.html
|
|
|
|
# Tom Schneider
|
|
# National Cancer Institute
|
|
# Laboratory of Mathematical Biology
|
|
# Frederick, Maryland 21702-1201
|
|
# toms@ncifcrf.gov
|
|
# http://www.lecb.ncifcrf.gov/~toms/
|
|
|
|
# 1999 Dec 30: James Haefner (jhaefner@biology.usu.edu)
|
|
# has found that some changes are needed to make atchange
|
|
# work under Linux. See the web site for details.
|
|
# This code will be revised when a good solution is found.
|
|
|
|
$0 =~ s(.*/)(); # basename
|
|
$usage = "usage: $0 filename cmd | $0 command_file";
|
|
@ARGV || die $usage; # check for proper invocation
|
|
|
|
# This allows the .cshrc to know that atchange has called it:
|
|
$ENV{'PERLCSH'} = "TRUE";
|
|
|
|
# Haefner Suggestion 1999 Dec 18:
|
|
##if default SHELL is sh or csh or tcsh use the following line
|
|
###$shell = $ENV{"SHELL"} ? $ENV{"SHELL"} : "/bin/sh";
|
|
##if default SHELL is bash (eg, Linux) use the following line
|
|
# 1999 Dec 28 - this is not a good idea - untestable by me
|
|
# $shell = "/bin/csh";
|
|
|
|
$shell = $ENV{"SHELL"} ? $ENV{"SHELL"} : "/bin/sh";
|
|
open(SHELL, "|$shell") || die "Can't pipe to $shell: $!";
|
|
select(SHELL); $| = 1;
|
|
|
|
if (@ARGV > 1) { # it's a file and a command
|
|
$file = shift; # peel off the filename
|
|
$cmd{$file} = join(" ", @ARGV) . "\n"; # and the command
|
|
$old{$file} = (stat($file))[9]; # mod time.
|
|
} else { # it's a program
|
|
open(PGM, shift) || die "Can't open $_: $!";
|
|
$/ = ""; # paragraph mode
|
|
while(<PGM>) { # first read the program
|
|
s/#.*\n/\n/g;
|
|
($file, $cmd) = /(\S*)\s+([^\000]+)/;
|
|
$cmd{$file} = $cmd;
|
|
unless ($file) { print $cmd{$file}; next; }
|
|
if ($file && ! $cmd{$file}) { warn "odd line"; next; };
|
|
$old{$file} = (stat($file))[9]; # mod time.
|
|
}
|
|
}
|
|
|
|
while(1) {
|
|
# sleep 1; # wait a second, then
|
|
select(undef, undef, undef, 0.25); # wait a quarter second, then
|
|
foreach (keys %cmd) { # rip through the whole list
|
|
atchange($_);
|
|
}
|
|
}
|
|
close(SHELL);
|
|
|
|
sub atchange { # if $file has changed, do $cmd{$file}
|
|
my($file) = @_;
|
|
my($new);
|
|
|
|
$new = (stat($file))[9];
|
|
return 0 if ($old{$file} == $new);
|
|
while (1) { # wait until it stops changing
|
|
$old{$file} = $new;
|
|
sleep 1;
|
|
$new = (stat($file))[9];
|
|
if ($old{$file} == $new) {
|
|
print $cmd{$file};
|
|
return 1;
|
|
}
|
|
}
|
|
}
|
|
</code>
|
|
|
|
|
|
<sect> Related URLs
|
|
<p>
|
|
Related VIM URLs are at -
|
|
<itemize>
|
|
<item> C and C++ Beautifer <url url="http://www.metalab.unc.edu/LDP/HOWTO/C-C++Beautifier-HOWTO.html">
|
|
<item>
|
|
Linux goodies main site is at <url url="http://24.221.230.253">
|
|
and secondary site at <url url="http://www.milkywaygalaxy.freeservers.com">
|
|
Mirror sites are at -
|
|
<url name="angelfire" url="http://www.angelfire.com/country/aldev0">,
|
|
<url name="geocities" url="http://www.geocities.com/alavoor/index.html">,
|
|
<url name="virtualave" url="http://aldev0.virtualave.net">,
|
|
<url name="Fortunecity" url="http://members.fortunecity.com/aldev">,
|
|
<url name="Freewebsites" url="http://aldev.freewebsites.com">,
|
|
<url name="Tripod" url="http://members.tripod.lycos.com/aldev">,
|
|
<url name="101xs" url="http://www.101xs.com/101xs/aldev">,
|
|
<url name="50megs" url="http://aldev0.50megs.com">,
|
|
|
|
</itemize>
|
|
|
|
|
|
<sect> Other Formats of this Document
|
|
<p>
|
|
This document is published in 14 different formats namely - DVI, Postscript,
|
|
Latex, Adobe Acrobat PDF,
|
|
LyX, GNU-info, HTML, RTF(Rich Text Format), Plain-text, Unix man pages, single
|
|
HTML file, SGML (Linuxdoc format), SGML (Docbook format), MS WinHelp format.
|
|
|
|
This howto document is located at -
|
|
<itemize>
|
|
<item> <url url="http://www.linuxdoc.org"> and click on HOWTOs and search
|
|
for howto document name using CTRL+f or ALT+f within the web-browser.
|
|
</itemize>
|
|
|
|
You can also find this document at the following mirrors sites -
|
|
<itemize>
|
|
<item> <url url="http://www.caldera.com/LDP/HOWTO">
|
|
<item> <url url="http://www.linux.ucla.edu/LDP">
|
|
<item> <url url="http://www.cc.gatech.edu/linux/LDP">
|
|
<item> <url url="http://www.redhat.com/mirrors/LDP">
|
|
|
|
<item> Other mirror sites near you (network-address-wise) can be found at
|
|
<url url="http://www.linuxdoc.org/mirrors.html">
|
|
select a site and go to directory /LDP/HOWTO/xxxxx-HOWTO.html
|
|
</itemize>
|
|
|
|
|
|
<itemize>
|
|
<item>
|
|
You can get this HOWTO document as a single file tar ball in HTML, DVI,
|
|
Postscript or SGML formats from -
|
|
<url url="ftp://www.linuxdoc.org/pub/Linux/docs/HOWTO/other-formats/">
|
|
and <url url="http://www.linuxdoc.org/docs.html#howto">
|
|
<p>
|
|
<item>Plain text format is in: <url url="ftp://www.linuxdoc.org/pub/Linux/docs/HOWTO">
|
|
and <url url="http://www.linuxdoc.org/docs.html#howto">
|
|
<p>
|
|
<item>Single HTML file format is in:
|
|
<url url="http://www.linuxdoc.org/docs.html#howto">
|
|
<p> Single HTML file can be created with command (see man sgml2html) -
|
|
sgml2html -split 0 xxxxhowto.sgml
|
|
<p>
|
|
<item>Translations to other languages like French, German, Spanish,
|
|
Chinese, Japanese are in
|
|
<url url="ftp://www.linuxdoc.org/pub/Linux/docs/HOWTO">
|
|
and <url url="http://www.linuxdoc.org/docs.html#howto">
|
|
Any help from you to translate to other languages is welcome.
|
|
</itemize>
|
|
The document is written using a tool called "SGML-Tools" which can be got from -
|
|
<url url="http://www.sgmltools.org">
|
|
Compiling the source you will get the following commands like
|
|
<itemize>
|
|
<item>sgml2html xxxxhowto.sgml (to generate html file)
|
|
<item>sgml2html -split 0 xxxxhowto.sgml (to generate a single page html file)
|
|
<item>sgml2rtf xxxxhowto.sgml (to generate RTF file)
|
|
<item>sgml2latex xxxxhowto.sgml (to generate latex file)
|
|
</itemize>
|
|
|
|
|
|
<sect1> Acrobat PDF format <label id="acrobatpdf">
|
|
<p>
|
|
PDF file can be generated from postscript file using
|
|
either acrobat <bf>distill</bf> or <bf>Ghostscript</bf>.
|
|
And postscript file is generated
|
|
from DVI which in turn is generated from LaTex file.
|
|
You can download distill software from <url url="http://www.adobe.com">. Given below
|
|
is a sample session:
|
|
<code>
|
|
bash$ man sgml2latex
|
|
bash$ sgml2latex filename.sgml
|
|
bash$ man dvips
|
|
bash$ dvips -o filename.ps filename.dvi
|
|
bash$ distill filename.ps
|
|
bash$ man ghostscript
|
|
bash$ man ps2pdf
|
|
bash$ ps2pdf input.ps output.pdf
|
|
bash$ acroread output.pdf &
|
|
</code>
|
|
Or you can use Ghostscript command <bf>ps2pdf</bf>.
|
|
ps2pdf is a work-alike for nearly all the functionality of
|
|
Adobe's Acrobat Distiller product: it
|
|
converts PostScript files to Portable Document Format (PDF) files.
|
|
<bf>ps2pdf</bf> is implemented as a very small command script
|
|
(batch file) that invokes Ghostscript, selecting a special "output device"
|
|
called <bf>pdfwrite</bf>. In order to use ps2pdf, the pdfwrite
|
|
device must be included in the makefile when Ghostscript was compiled;
|
|
see the documentation on building Ghostscript for details.
|
|
|
|
|
|
<sect1> Convert Linuxdoc to Docbook format <label id="linuxdoc2docbook">
|
|
<p>
|
|
This document is written in linuxdoc SGML format. The Docbook SGML format
|
|
supercedes the linuxdoc format and has lot more features than linuxdoc.
|
|
The linuxdoc is very simple and is easy to use. To convert linuxdoc SGML
|
|
file to Docbook SGML use the program <bf>ld2db.sh</bf> and some perl scripts.
|
|
The ld2db output is not 100% clean and you need to use the <bf>clean_ld2db.pl</bf>
|
|
perl script. You may need to manually correct few lines in the document.
|
|
<itemize>
|
|
<item> Download ld2db program from <url url="http://www.dcs.gla.ac.uk/~rrt/docbook.html">
|
|
or from <url name="Al Dev site" url="http://www.milkywaygalaxy.freeservers.com">
|
|
<item> Download the cleanup_ld2db.pl perl script from
|
|
from <url name="Al Dev site" url="http://www.milkywaygalaxy.freeservers.com">
|
|
</itemize>
|
|
The ld2db.sh is not 100% clean, you will get lots of errors when you run
|
|
<code>
|
|
bash$ ld2db.sh file-linuxdoc.sgml db.sgml
|
|
bash$ cleanup.pl db.sgml > db_clean.sgml
|
|
bash$ gvim db_clean.sgml
|
|
bash$ docbook2html db.sgml
|
|
</code>
|
|
And you may have to manually edit some of the minor errors after
|
|
running the perl script. For e.g. you may need to put closing tag <
|
|
/Para> for each <
|
|
Listitem>
|
|
|
|
|
|
<sect1> Convert to MS WinHelp format <label id="mswinhelp">
|
|
<p>
|
|
You can convert the SGML howto document to Microsoft Windows Help file,
|
|
first convert the sgml to html using:
|
|
<code>
|
|
bash$ sgml2html xxxxhowto.sgml (to generate html file)
|
|
bash$ sgml2html -split 0 xxxxhowto.sgml (to generate a single page html file)
|
|
</code>
|
|
Then use the tool <url name="HtmlToHlp" url="http://javadocs.planetmirror.com/htmltohlpe.html">.
|
|
You can also use sgml2rtf and then use the RTF files for generating winhelp files.
|
|
|
|
|
|
<sect1> Reading various formats <label id="readformats">
|
|
<p>
|
|
In order to view the document in dvi format, use the xdvi program. The xdvi
|
|
program is located in tetex-xdvi*.rpm package in Redhat Linux which can be
|
|
located through ControlPanel | Applications | Publishing | TeX menu buttons.
|
|
To read dvi document give the command -
|
|
<tscreen><verb>
|
|
xdvi -geometry 80x90 howto.dvi
|
|
man xdvi
|
|
</verb></tscreen>
|
|
And resize the window with mouse.
|
|
To navigate use Arrow keys, Page Up, Page Down keys, also
|
|
you can use 'f', 'd', 'u', 'c', 'l', 'r', 'p', 'n' letter
|
|
keys to move up, down, center, next page, previous page etc.
|
|
To turn off expert menu press 'x'.
|
|
|
|
You can read postscript file using the program 'gv' (ghostview) or
|
|
'ghostscript'.
|
|
The ghostscript program is in ghostscript*.rpm package and gv
|
|
program is in gv*.rpm package in Redhat Linux
|
|
which can be located through ControlPanel | Applications | Graphics menu
|
|
buttons. The gv program is much more user friendly than ghostscript.
|
|
Also ghostscript and gv are available on other platforms like OS/2,
|
|
Windows 95 and NT, you view this document even on those platforms.
|
|
|
|
<itemize>
|
|
<item>Get ghostscript for Windows 95, OS/2, and for
|
|
all OSes from <url url="http://www.cs.wisc.edu/~ghost">
|
|
</itemize>
|
|
|
|
To read postscript document give the command -
|
|
<tscreen><verb>
|
|
gv howto.ps
|
|
ghostscript howto.ps
|
|
</verb></tscreen>
|
|
|
|
You can read HTML format document using Netscape Navigator, Microsoft Internet
|
|
explorer, Redhat Baron Web browser or any of the 10 other web browsers.
|
|
|
|
You can read the latex, LyX output using LyX a X-Windows front end to latex.
|
|
|
|
|
|
<sect> Copyright Notice
|
|
<p>
|
|
Copyright policy is GNU/GPL as per LDP (Linux Documentation project).
|
|
LDP is a GNU/GPL project.
|
|
Additional restrictions are - you must retain the author's name, email address
|
|
and this copyright notice on all the copies. If you make any changes
|
|
or additions to this document then you should
|
|
notify all the authors of this document.
|
|
|
|
|
|
</article>
|