[buug] [n]vi "vs." vim; terminfo, etc.

Michael Paoli Michael.Paoli at cal.berkeley.edu
Wed Jan 2 02:39:01 PST 2013


> I have been wondering about your complaint about vim, that it is
> subtly incompatible with vi, and in a dumbed down way.
>
> One thing I like about vim is that it tells you when it is in insert
> mode. I never mastered the trick of keeping track in my head. I also
> don't like nvi's flashing of the entire screen when you getto a
> limits of the file with the cursor movement keys.

I don't think I'd (quite) call vim(1) and its "compatible mode" "dumbed
down", so much as I'd more likely generally call vim (stupidly) arrogant and
presumptive.  Or, more precisely, as I said before[1]:
"vim should never have the arrogance to presume it's smarter than those
using it or knows better what they want than they do"
E.g. it acts like it thinks and tries to be a lot smarter
than me, when it is very obviously not.  And it trying to show off its
"smarts", it mostly just causes more problems.

And yes, I know of vim's "compatible" mode - it's *not* very compatible,
E.g. see also [1] for typical examples.

"tells you when it is in insert mode" - that can also be done with [n]vi:
:se showmode
(or of course in .exrc file, or for non-ancient vi via EXINIT)
I typically have it set.  Without it, the algorithm for determining mode
is quite simple - just hit escape until [n]vi alerts one via the
terminal (audible) bell or "visual bell" (screen flash).  That's
[n]vi's way signaling a minor error, in this case "Hey, I'm *already* in
command mode!"  One is then in command mode.  If that's not the mode
one wants to be in, then go into insert/append/replace/etc. mode as
desired by using the appropriate command.  Exception would be : prompt
in ex mode.  If the Escapes just echo back as ^[ or appear to do
nothing, if one types some text (e.g. sequence of "a" characters) and
they echo back, one is likely in insert, append, or similar mode in ex.
Just hit <RETURN>, then . on a line by itself, then <RETURN> again, and
that should then give one a : prompt.  To that, enter vi followed by
<RETURN> and that should get one to vi command mode - unless the
terminal (or specification thereof) is missing or insufficient to
support visual mode, in which case one will generally remain in ex mode.

The flashing of the entire screen is not specifically [n]vi or even vim
behavior, but more a matter of the terminal (or emulation thereof)'s
capabilities and (typically) TERMINFO capabilities entry.  Many
terminals(/emulations) have a (mis?)feature capability to flash the
screen, as a (silent) visual alert.  This is, arguably, often considered
a better or preferred means of alerting than an audible terminal bell.
Terminals/emulations having such a capability generally have it
described in their TERMINFO (or TERMCAP) entry.  Likewise they'll also
indicate their audible bell capability if they have such (almost all
do).  Many programs, including vi, nvi, vim, and many others, if they
find the terminal's capabilities to include flash_screen/flash/vb
("visual bell"), they'll use that in preference over bell/bel/bl,
otherwise they'll use bell/bel/bl.  So, if one doesn't like that
terminal screen flash, the place to address that isn't within
vi/nvi/vim, but rather with (typically) the TERMINFO entry.
One can create a TERMINFO entry, and suitably set TERMINFO and TERM, to
use a capability description that doesn't include the
flash_screen/flash/vb capability.  One can then use those environment
settings for vi/nvi/vim, or any and/or all programs, as may be preferred
regarding that behavior.  With, e.g. TERMINFO, if such a suitable
terminal variant doesn't already exist, creating one is relatively easy,
as the capability entries can also be written about as simply as this:
terminal is just like that other one except it doesn't have
such-and-such capability.  E.g. (I show my comments on lines starting
with //):
// confirm we have the TERMCAP flash capability for xterm
// use of vi(1) also appears to confirm it uses it
$ (unset TERMINFO; TERM=xterm infocmp -1I) | fgrep flash
         flash=\E[?5h$<100/>\E[?5l,
// do we already have something that looks like a suitable variant?
$ echo $(find /lib/terminfo /usr/share/terminfo -name 'xterm*' -print  
| sed -e 's/^.*\/xterm//' | sort -u)
+256color +88color +app +app+pc +decedit +edit +noapp +noapp+pc  
+pc+edit +pcc0 +pcc1 +pcc2 +pcc3 +pce0 +pce1 +pce2 +pce3 +pcf0 +pcf1  
+pcf2 +pcf3 +pcfN +pcfkeys +pcfn +r6f2 +sl +sl-twm +vt+edit -1002  
-1003 -16color -24 -256color -65 -88color -8bit -basic -bold -boldso  
-color -debian -hp -ic -mono -new -nic -noapp -nrc -old -pcolor -r5  
-r6 -rep -sco -sun -vi -vt220 -vt52 -xf86-v32 -xf86-v33 -xf86-v333  
-xf86-v40 -xf86-v43 -xf86-v44 -xfree86 -xi -xmc 1 c m s s-sun
// for sake of exercise, we'll presume none of those are what we want
// where is the xterm TERMINFO entry?
$ find /lib/terminfo /usr/share/terminfo -name 'xterm' -print
/lib/terminfo/x/xterm
// save and set umask
$ saved_umask=$(umask); umask 022
// make directories and symbolic link
$ cd && mkdir .terminfo .terminfo/x && cd .terminfo
$ ln -s /lib/terminfo/x/xterm x/xterm
// what does existing name and long name look like?
$ (unset TERMINFO; TERM=xterm infocmp -1I) | grep '^xterm|'
xterm|X11 terminal emulator,
// create our source file
$ ed xterm-nvb.src
xterm-nvb.src: No such file or directory
0a
xterm-nvb|X11 terminal emulator no visual bell,
         flash@,
         use=xterm,
.
w
83
q
// compile our new TERMINFO entry
$ TERMINFO="$HOME"/.terminfo tic xterm-nvb.src
$ umask "$saved_umask"; unset "$saved_umask"
// and now we try out our new entry - vi now uses the audible bell, as
// it no longer sees a visual bell capability.
$ TERMINFO="$HOME"/.terminfo TERM=xterm-nvb vi
// TERM=linux-m is very handy for getting vim to NOT use any colors,
// also usefully appropriate for monochrome video card or monitor.
// Checking a bit further - are there xterm variants that already don't
// include the flash capability?
$ echo $(unset TERMINFO; for TERM in $(find /lib/terminfo  
/usr/share/terminfo -name 'xterm*' -print | sed -e 's/^.*\///' | sort  
-u); do TERM="$TERM" infocmp -1I | >>/dev/null 2>&1 fgrep flash= ||  
echo "$TERM"; done)
xterm+256color xterm+88color xterm+app xterm+app+pc xterm+decedit  
xterm+edit xterm+noapp xterm+noapp+pc xterm+pc+edit xterm+pcc0  
xterm+pcc1 xterm+pcc2 xterm+pcc3 xterm+pce0 xterm+pce1 xterm+pce2  
xterm+pce3 xterm+pcf0 xterm+pcf1 xterm+pcf2 xterm+pcf3 xterm+pcfN  
xterm+pcfkeys xterm+pcfn xterm+r6f2 xterm+vt+edit xterm-24 xterm-65  
xterm-bold xterm-boldso xterm-color xterm-mono xterm-old xterm-r5  
xterm-r6 xterm-vt52 xtermc xtermm xterms
// Yes, quite a number of them, actually.
// I'll leave as an exercise to determine if any of those are already
// fully suitable, and by exactly what capabilities they differer from
// xterm

references/excerpts/footnotes:

1. http://buug.org/pipermail/buug/2011-April/003724.html
vi(1)
ex(1)
nvi(1)
vim(1)
terminfo(5)
infocmp(1)
tic(1)
ed(1)
sh(1)
find(1)
ln(1)
mkdir(1)
fgrep(1)
sort(1)

terminfo(5)                  File Formats                  terminfo(5)
        Terminal  names  (except for the last, verbose entry) should be
        chosen using the following conventions.  The  particular  piece
        of  hardware  making  up  the terminal should have a root name,
        thus ``hp2621''.  This name should not contain hyphens.   Modes
        that  the  hardware  can  be in, or user preferences, should be
        indicated by appending a hyphen and a  mode  suffix.   Thus,  a
        vt100  in 132 column mode would be vt100-w.  The following suf-
        fixes should be used where possible:
         Suffix                  Meaning                   Example
         -nn      Number of lines on the screen            aaa-60
         -np      Number of pages of memory                c100-4p
         -am      With automargins (usually the default)   vt100-am
         -m       Mono mode; suppress color                ansi-m
         -mc      Magic cookie; spaces when highlighting   wy30-mc
         -na      No arrow keys (leave them in local)      c100-na
         -nam     Without automatic margins                vt100-nam
         -nl      No status line                           att4415-nl
         -ns      No status line                           hp2626-ns
         -rv      Reverse video                            c100-rv
         -s       Enable status line                       vt100-s
         -vb      Use visible bell instead of beep         wy370-vb
         -w       Wide mode (> 80 columns, usually 132)    vt100-w
        For more on terminal naming conventions, see the term(7) manual
        page.
        These are the string capabilities:
                Variable            Cap-    TCap       Description
                 String             name    Code
        bell                        bel     bl     audible signal
                                                   (bell) (P)
        flash_screen                flash   vb     visible bell (may
                                                   not move cursor)
    Similar Terminals
        If  there are two very similar terminals, one (the variant) can
        be defined as being just like the other (the base) with certain
        exceptions.  In the definition of the variant, the string capa-
        bility use can be given with the name  of  the  base  terminal.
        The  capabilities  given  before use override those in the base
        type named by use.  If there  are  multiple  use  capabilities,
        they  are  merged in reverse order.  That is, the rightmost use
        reference is processed first, then the one to its left, and  so
        forth.   Capabilities  given  explicitly  in the entry override
        those brought in by use references.
        A capability can be canceled by placing xx@ to the left of  the
        use reference that imports it, where xx is the capability.  For
        example, the entry
                                 2621-nl, smkx@, rmkx@, use=2621,
        defines a 2621-nl that does not have the smkx or rmkx capabili-
        ties,  and  hence does not turn on the function key labels when
        in visual mode.  This is useful for different modes for a  ter-
        minal, or for different user preferences.




More information about the buug mailing list