home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  


12.9 Programming Assistance

vile 's programming assistance capabilities are discussed in this section.

12.9.1 Edit-Compile Speedup

vile uses two straightforward vi mode commands to manage program development, shown in Table 12.6 .


Table 12.6: vile Program Development vi Mode Commands
Command Function
^X ! command [RETURN]

Run command , saving the output in a buffer named [Output] .

^X ^X

Find the next error. vile parses the output and moves to the location of each successive error.

vile understands the Entering directory XXX and Leaving directory XXX messages that GNU make generates, allowing it to find the correct file, even if it's in a different directory.

The error messages are parsed using regular expressions in the buffer [Error Expressions] . vile automatically creates this buffer, and then it uses the buffer when you use ^X ^X . You can add expressions to it as needed, and it has an extended syntax that allows you to specify where filenames, line numbers, columns and so on appear in the error messages. Full details are provided in the online help, but you probably won't need to make any changes, as it works pretty well "out of the box."

vile 's error finder also compensates for changes in the file, keeping track of additions and deletions as you progress to each error.

The error finder applies to the most recent buffer created by reading from a shell command. For example, ^X!command produces a buffer named [Output] , and :e !command produces a buffer named [!command] . The error finder will be set appropriately.

You can point the error finder at an arbitrary buffer (not just the output of shell commands) using the :error-buffer command. This lets you use the error finder on the output of previous compiler or egrep runs.

12.9.2 Syntax Highlighting

vile relies on help from an external program to provide syntax coloring. In fact, there are three programs: one for C programs, one for Pascal programs, and one for UNIX man pages. The vile documentation provides this sample macro for use in a .vilerc file:

30 store-macro
	write-message "[Attaching C/C++ attributes...]"
	set-variable %savcol $curcol
	set-variable %savline $curline
	set-variable %modified $modified
	goto-beginning-of-file
	filter-til end-of-file "vile-c-filt"
	goto-beginning-of-file
	attribute-cntl_a-sequences-til end-of-file
	~if &not %modified
		unmark-buffer
	~endif
	%savline goto-line
	%savcol goto-column
	write-message "[Attaching C/C++ attributes...done ]"
~endm
bind-key execute-macro-30 ^X-q

This runs vile-c-filt over the C source code. This program in turn relies upon the contents of $HOME/.vile.keywords , which specifies the attributes to provide to different text. (B for bold, U for underlined, I for italic, and C for one of 16 different colors.) This is Kevin Buettner's version:

Comments:C2
Literal:U
Cpp:CB
if:B
else:B
for:B
return:B
while:B
switch:B
case:B
do:B
goto:B
break:B

Syntax coloring works on the X11 interface with both Versions 7.4 and 8.0 of vile . Getting it to work on a Linux console is a bit more complicated. It depends upon which screen handling interface it was compiled with.

The ncurses library

Configure vile with --with-screen=ncurses and rebuild. This will then work out of the box.

The termcap library

This is the default way that vile is configured. Using this version requires you to have a correct /etc/termcap entry for the Linux console. The following termcap entry works:[5 ]

console|linux|con80x25|dumb:\
	:do=^J:co#80:li#25:cl=\E[H\E[J:sf=\ED:sb=\EM:\
	:le=^H:bs:am:cm=\E[%i%d;%dH:nd=\E[C:up=\E[A:\
	:ce=\E[K:cd=\E[J:so=\E[7m:se=\E[27m:us=\E[4m:ue=\E[24m:\
	:md=\E[1m:mr=\E[7m:mb=\E[5m:me=\E[m:is=\E[1;25r\E[25;1H:\
	:ll=\E[1;25r\E[25;1H:al=\E[L:dc=\E[P:dl=\E[M:\
	:it#8:ku=\E[A:kd=\E[B:kr=\E[C:kl=\E[D:kb=^H:ti=\E[r\E[H:\
	:ho=\E[H:kP=\E[5~:kN=\E[6~:kH=\E[4~:kh=\E[1~:kD=\E[3~:kI=\E[2~:\
	:k1=\E[[A:k2=\E[[B:k3=\E[[C:k4=\E[[D:k5=\E[[E:k6=\E[17~:\
	:k7=\E[18~:k8=\E[19~:k9=\E[20~:k0=\E[21~:K1=\E[1~:K2=\E[5~:\
	:K4=\E[4~:K5=\E[6~:\
	:pt:sr=\EM:vt#3:xn:km:bl=^G:vi=\E[?25l:ve=\E[?25h:vs=\E[?25h:\
	:sc=\E7:rc=\E8:cs=\E[%i%d;%dr:\
	:r1=\Ec:r2=\Ec:r3=\Ec:\
	:vb=\E[?5h\E[?5l:\
	:ut:\
	:Co#8:\
	:AF=\E[%a+c\036%dm:\
	:AB=\E[%a+c\050%dm:

[5] This entry courtesy of Kevin Buettner. Note that Linux distributions will vary. This was tested under Redhat Linux 4.2; you may not need to change your /etc/termcap file.

On the one hand, because syntax highlighting is accomplished with an external program, it should be possible to write any number of highlighters for different languages. On the other hand, because the facilities are rather low-level, doing so is not for non-programmers. The online help describes how the highlight filters should work.

The directory ftp://ftp.clark.net/pub/dickey/vile/utilities contains user-contributed filters for coloring makefiles, LaTeX input, Perl, HTML, and troff . It even contains a macro that will color the lines in RCS files according to their age!


Previous: 12.8 Improved Editing Facilities Learning the vi Editor Next: 12.10 Interesting Features
12.8 Improved Editing Facilities Book Index 12.10 Interesting Features

The UNIX CD Bookshelf NavigationThe UNIX CD BookshelfUNIX Power ToolsUNIX in a NutshellLearning the vi Editorsed & awkLearning the Korn ShellLearning the UNIX Operating System