🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

4 total messages Started by Pietro Manzoni Thu, 28 Jan 1993 15:52
Centering lines in vi
#2956
Author: Pietro Manzoni
Date: Thu, 28 Jan 1993 15:52
12 lines
899 bytes
Hi,
is there anybody who knows whether there is a :map command to center a
single line in VI?


Thanks 

-- Pietro

Pietro Manzoni                                  | Per andare, dove dobbiamo
email: pietro@nova.bellcore.com                 | andare, per dove dobbiamo
Network Technology Research Lab, Bellcore       | andare?          -- Toto'
Re: Centering lines in vi
#2957
Author: Gordon DeWitte
Date: Thu, 28 Jan 1993 17:13
1 lines
549 bytes
!!ctr[return]
Re: Centering lines in vi
#2951
Author: James C. Hu
Date: Thu, 28 Jan 1993 22:43
76 lines
2554 bytes
pietro@nova.bellcore.com (Pietro Manzoni) writes:

>Hi,
>is there anybody who knows whether there is a :map command to center a
>single line in VI?

There is probably already a package that does this, but I'd put this in
as an example on how to build useful simple filters for vi.  At the end
of this post is a simple program that centers text.  Compile it and
install it in ~/bin/center, or whatever.

Then, make the following map:
:map == !!center^M
(the ^M represents the result of hitting CTRL-V followed by CTRL-M)

Presto, you have a pseudo center "operator".  Now you can do a == to
center a single line, or a 5== to center the next 5 lines.

Enjoy.

/* File:    center.c
 * Creator: James C. Hu (sirius@matt.ksu.ksu.edu)
 *
 * Description:
 *     Centers lines of input.
 * 
 *     Caveats are that lines cannot be longer than the specified
 *     centering line length, if they are, then they may be truncated,
 *     and that the default centering line length is 72.
 *
 * Copyright:
 *     This program is placed into the public doman.
 *
 * Date Started: Thu Jan 28 15:33:44 CST 1993
 *
 * Change Log:
 */

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

static int length = 72;
static char *buf;
static char format[10];         /* should be enough */

int main(int argc, char *argv[])
{
  int i,n,buflen;
  char *p;

  switch(argc) {
  case 2:
    length = atoi(argv[1]);
    if (length == 0) length = 72;
  case 1:
    break;
  default:
    fprintf(stderr, "usage: center [width]");
    exit(1);
  }

  buf = malloc((length + 2) * sizeof(char));
  while (fgets(buf, length+2, stdin) != NULL) {
    if ((p = strrchr(buf, '\n')) != NULL) *p = '\0';
    while (isspace(*buf)) buf++;
    buflen = strlen(buf);
    sprintf(format, "%%%ds\n", length/2 + (buflen+1)/2);
    printf(format, buf);
  }
  return 0;
}

-- 
James C. Hu (jxh@math.ksu.edu), 1804 Denholm Dr., Manhattan, KS 66502
I speak for me, the whole me, and nothing but for me.  So help me me.
Re: Centering lines in vi
#2955
Author: Mr. John T Jensen
Date: Fri, 29 Jan 1993 02:20
18 lines
1108 bytes
gordond@sr.hp.com (Gordon DeWitte) writes:

>!!ctr[return]

Fine if you're running in Unix with the text-processing component available.
Any help for those of us running under ancient (Version 7 and below) Unixes;
Xenix; or elvis for DOS.  In the first two cases the run-time system was
sold without the text-processing system, meaning no ?roff, no ctr, etc.  In
the latter, you have to have a DOS utility (which I haven't).

jj

John Thayer Jensen                      64 9 373 7599 ext. 7543
Commerce Computer Services              64 9 373 7437 (FAX)
Auckland University                     jt.jensen@auckland.ac.nz
Private Bag 92019
AUCKLAND
New Zealand
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads