From 2e28d5a885608fddd1e0b7464ba3c9582a9e8ca4 Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Fri, 24 Mar 2017 14:02:59 +1300 Subject: Add exm(1df) to work around Vim's screen-clearing --- README.markdown | 1 + bin/exm | 10 ++++++++++ man/man1/exm.1df | 22 ++++++++++++++++++++++ sh/profile.d/editor.sh | 11 ++++++++++- 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100755 bin/exm create mode 100644 man/man1/exm.1df diff --git a/README.markdown b/README.markdown index 4cd4820c..8b95e1a9 100644 --- a/README.markdown +++ b/README.markdown @@ -469,6 +469,7 @@ Installed by the `install-bin` target: any options, mostly useful for scripts. * `eds(1df)` edits executable script files in `EDSPATH`, defaulting to `~/.local/bin`, for personal scripting snippets. +* `exm(1df)` works around a screen-clearing quirk of Vim's `ex` mode. * `finc(1df)` counts the number of results returned from a set of given `find(1)` conditions. * `fnl(1df)` runs a command and saves its output and error into temporary diff --git a/bin/exm b/bin/exm new file mode 100755 index 00000000..cfae82d4 --- /dev/null +++ b/bin/exm @@ -0,0 +1,10 @@ +#!/bin/sh +# If input is a terminal and ex(1) is the Vim version, force it to use a dumb +# terminal so it doesn't clear the screen +if [ -t 0 ] ; then + ver=$(ex --version | sed '1{s/ .*//;q}') 2>/dev/null + case $ver in + VIM) set -- -T builtin_dumb "$@" ;; + esac +fi +exec ex "$@" diff --git a/man/man1/exm.1df b/man/man1/exm.1df new file mode 100644 index 00000000..892ca326 --- /dev/null +++ b/man/man1/exm.1df @@ -0,0 +1,22 @@ +.TH EXM 1df "March 2017" "Manual page for exm" +.SH NAME +.B exm +\- invoke Vim's ex(1) with a dumb terminal +.SH SYNOPSIS +.B exm +[EX_OPTIONS...] [FILES] +.SH DESCRIPTION +.B exm +works around a quirk of Vim that causes it to clear the screen when invoked as +ex(1) interactively. It applies Vim's -T option to force the terminal to the +builtin "dumb" terminal. +.SH CAVEATS +This doesn't work on its first invocation from any given terminal, but does +work thereafter. I haven't yet figured out why. +.P +This breaks switching to visual mode with :visual somewhat, as the terminal +will persist in its dumb state. I'm not sure there's a way to fix this. If +there were a Vim :autocmd for mode switching, it might be possible, or perhaps +by wrapping :visual somehow to :set terminal=$TERM. +.SH AUTHOR +Tom Ryder diff --git a/sh/profile.d/editor.sh b/sh/profile.d/editor.sh index 5d6b249e..307879fe 100644 --- a/sh/profile.d/editor.sh +++ b/sh/profile.d/editor.sh @@ -1,7 +1,16 @@ -# Set command-line editor; ed if we've got it (!), but ex will do fine +# Ideally, we'd use plain old ed(1), but many Linux distributions don't install +# it by default if command -v ed >/dev/null 2>&1 ; then EDITOR=ed + +# Failing that, if we have both vim(1) and exm(1df) in our $PATH, use the +# latter to work around Vim's ex mode screen-clearing +elif { command -v vim && command -v exm ; } >/dev/null 2>&1 ; then + EDITOR=exm + +# Otherwise, just call ex(1) directly else EDITOR=ex fi + export EDITOR -- cgit v1.2.3