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


UNIX Power Tools

UNIX Power ToolsSearch this book
Previous: 31.9 Good Stuff for Your .exrc File Chapter 31
Creating Custom Commands in vi
Next: 31.11 Typing in Uppercase Without CAPS LOCK
 

31.10 Repeating a vi Keymap

The vi (actually, ex ) command map (31.2 ) lets you build custom vi commands. For example, this map redefines the - key to run the vi commands o (open a new line below), ESCAPE , 75a- (add 75 dashes), and ESCAPE again:

:map - o^[75a-^[

So typing - draws a row of dashes below the current line. The problem is that on many versions of vi , you can't add a repetition number - that is, you can't type the command 10- to add 10 dashed lines.

The workaround is to define another macro that calls the first macro ten times. For example, to make the v key draw ten rows of dashes:

:map v ----------

(Ugly, eh? But it works.) You might want to put the - map in your .exrc file and define "multi-maps" like v while you're running vi .

- JP


Previous: 31.9 Good Stuff for Your .exrc File UNIX Power Tools Next: 31.11 Typing in Uppercase Without CAPS LOCK
31.9 Good Stuff for Your .exrc File Book Index 31.11 Typing in Uppercase Without CAPS LOCK

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