2

How does one erase characters in ex mode (':' command line) of (n)vi 1.79 or make 'Backspace' behave as in Vim?

'Backspace' and 'Delete' only move the cursor left, from where new keystrokes overwrite instead of preferably inserting. This is the same for insert mode, but I can use 'Esc' to clear everything after the cursor; 'Backspace' does erase at the shell command line.

I am using (n)vi in xterm in fvwm, each of which are included in a new OpenBSD 7.1 installation. Note that Vim and its vi command, i.e. :set compatible, are not the same implementation as (n)vi. Some places I have searched:

3
  • You are describing the way vi behaves when editing a line; Backspace moves the cursor to the left but does not delete characters and subsequently inserted characters overwrites the "deleted" characters. However, vi usually removes the remaining deleted characters from the display once one presses Escape. I've ever seen this behaviour in ex mode though. Commented Jul 15, 2022 at 22:03
  • @Kusalananda I was wrong/unclear. The behavior as described also applies to insert mode, but I am able to use 'Esc' to clear characters (and reenter insert mode). Using 'Esc' in ex mode runs everything up to the cursor. I'd like it to be more like Vim, if possible. Commented Jul 15, 2022 at 22:14
  • @thrig xterm -echoprt -altwerase -noflsh -tostop -flusho pendin -nokerninfo erase = ^?; intr = ^C; kill = ^U; lnext = ^V; min = 1; quit = ^\; time = -; werase = ^W; Commented Jul 15, 2022 at 22:17

1 Answer 1

1

This is historical behavior of the ex-vi present in OpenBSD (usr.bin/vi/vi/v_txt.c under the src repository):

  /*
   * Historically, vi didn't replace the erased characters with
   * <blank>s, presumably because it's easier to fix a minor
   * typing mistake and continue on if the previous letters are
   * already there.

To always blank out the erased characters vi will need to be patched and recompiled, at which point you will be running your own fork of vi:

diff --git vi/v_txt.c vi/v_txt.c
index c1d95e8..9ea1954 100644
--- vi/v_txt.c
+++ vi/v_txt.c
@@ -1014,8 +1014,7 @@ leftmargin:               tp->lb[tp->cno - 1] = ' ';
                 * point in the screen.  So, if incrementally searching, erase
                 * the erased characters from the screen.
                 */
-               if (FL_ISSET(is_flags, IS_RUNNING))
-                       tp->lb[tp->cno] = ' ';
+               tp->lb[tp->cno] = ' ';

                /*
                 * Increment overwrite, decrement ai if deleted.

Or, you could install vim, which is fairly compatible with vim on other platforms:

doas pkg_add vim

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.