Xref: utzoo comp.editors:931 comp.unix.questions:16301 Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!rpi!nyser!rodan!jdpeek From: jdpeek@rodan.acs.syr.edu (Jerry Peek) Newsgroups: comp.editors,comp.unix.questions Subject: Re: Centering lines in vi Message-ID: <745@rodan.acs.syr.edu> Date: 13 Sep 89 04:51:53 GMT References: <2283@umbc3.UMBC.EDU> Reply-To: jdpeek@rodan.acs.syr.edu (Jerry Peek) Organization: Syracuse University, Syracuse, NY Lines: 39 In article <2283@umbc3.UMBC.EDU> rostamia@umbc3.UMBC.EDU (Rouben Rostamian) writes: > Is there a command that returns the current column position of the cursor > in vi? Here's something that gets close. I just dreamed this up, so I haven't tested it real thoroughly. It's a kludge, but it seems to work. First part: Define this vi macro named "v": :map v i^A^[:.w !colpos^[0f^Ax where the ^A is a real control-A character (I listed it here as a ^ followed by an A) and ^[ is a real ESC character (type it as control-V ESC). The ^A isn't important; you can use any character that you won't appear in your file. The macro inserts a ^A character in the line, then writes the line to the standard input of a shell script called "colpos" (COLumn POSition). After that, the macro finds the ^A again and removes it from the line. Second part: the 'colpos' script (written for 4.3 BSD): #! /bin/sh sed 's/.*//' | wc -c # time to read answer: # sleep 1 (sorry, no "shar file"). Again, replace the ^A with a real control-A character. The script reads the line from vi (from the script's standard input), strips off the ^A and the rest of the line, and uses "wc -c" to count how many characters are left on the line. It prints that number to its standard output, which 'vi' displays. I commented out the last line; see below. This kludge has some problems: - sometimes, 'vi' tells me 'press return to continue' and pauses after running the macro. Other times, it doesn't pause. - sometimes, the ^A is removed from the line. Other times, it isn't. I don't have time to work on this more. If I wait to clean it up, I'll never get to it! I posted this in case someone wants to clean it up. Hope it helps. --Jerry Peek; Syracuse University Academic Computing Services; Syracuse, NY jdpeek@rodan.acs.syr.edu///JDPEEK@SUVM.BITNET///GEnie: J.PEEK1 +1 315 443-3995