Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!samsung!olivea!oliveb!felix!asylvain@felix.UUCP From: asylvain@felix.UUCP (Alvin "the Chipmunk" Sylvain) Newsgroups: comp.editors Subject: Re: vi for power users Message-ID: <155024@felix.UUCP> Date: 21 Dec 90 19:00:13 GMT References: <109909@convex.convex.com> <1371:Dec1108:11:4090@kramden.acf.nyu.edu> <4672@umbc3.UMBC.EDU> <7150:Dec1309:42:4690@kramden.acf.nyu.edu> <1990Dec14.174605.19649@ddsw1.MCS.COM> Sender: daemon@felix.UUCP Reply-To: asylvain@felix.UUCP (Alvin "the Chipmunk" Sylvain) Organization: FileNet Corp., Costa Mesa, CA Lines: 70 In article it1@ra.MsState.Edu (Tim Tsai) writes: > > New question. Is there a way to get vi to recognize the cursor keys > on input mode? I was playing around with a SYS V version of vi the > other day, and noticed that the arrow keys worked during input mode! > Vi on a Sun, however, doesn't. Is this even possible (I realized > it's terminal dependent) Someone answered this for the Sun, but here is an answer for nearly any terminal in existance. Basically, you must create a `.exrc' file and place it in your HOME directory. That file contains initialization parameters used by vi. (Note: if your SysOp has pre-configured your .profile, .login, or .cshrc file with a "setenv EXINIT" or equiv, you may want to edit the file delete that line. Copy the info into your .exrc, and you can change .exrc anytime you want. If you don't do this, the .exrc file will only take effect when you are in your home directory. Any other directory will default to the EXINIT environment.) Mapping cursor keys, or any other non-standard function key, can be tricky depending on your terminal. Most of them will produce some set of control characters, some of which you will have to `escape'. My ADM-12, for example, produces ^K for "up", etc. Others will produce a whole sequence of characters, including ESC (^[), ^A, etc. (Note the difference between `escaping' a character and the ESCape character.) Your first task is to find out what your terminal produces. Try press- ing the key while in insert mode and watch what comes out. If it leaves insert mode, you'll know there's a ^[ in there somewhere. Try pressing the key from the shell prompt, and see what comes out. You may be forced to write a quick C program that echoes the ASCII equiva- lents of it's input, but if you can't see your input from insert mode in vi, writing C code using cbreak mode is a whole 'nother chapter. If the very first character output is a control character, trying `escaping' the key. Ie, from insert mode, press ^V then your key. OK, let's assume your UP key produces the following sequence, ^[[A, or like mine, ^K. That is, for the first case, ESCape OPEN-BRACKET A, or for the second case, CONTROL-K. Here are the map commands (with exagerated white space for readability): map ^V^[[A k map ^V^K k Notice that the control characters are `escaped': That is, you enter control-V in order to be able to enter ESC. While editing the .exrc file, you will have to enter ^V from insert mode in order to enter ^V! Now, just add a map command for every cursor or function key that you want to define. Using the above technique, you can map every function key on your terminal to whatever editting function you like. This allows you to customize vi to your tastes. Examples: map the HOME key to H, which places the cursor on the top line of the screen. Map the END key to $, PAGE-DN to ^D, F10 to ZZ, SHIFT-F10 to :q!, etc. Warning: don't get too crazy, because if you need to work with someone else on their terminal session instead of yours, you'll hit one of your custom keys by habit, and strange things may happen! Then you'll have forgotten how to do the function in the original way! That can be awfully embarrassing! -- asylvain@felix.UUCP (Alvin "the Chipmunk" Sylvain) ========================= Opinions are Mine, Typos belong to /usr/ucb/vi "We're sorry, but the reality you have dialed is no longer in service. Please check the value of pi, or see your SysOp for assistance." UUCP: hplabs!felix!asylvain ============================================