How do you do backspace in old school vi? I know I can switch to command mode then hit x
but I would prefer the backspace button to work.
If you use the keys to navigate when in edit (non insert) mode, pressing h moves the cursor to the left.
h - left
j - up
k - down
l - right
It switches to command mode and does nothing.
: stty -a
speed 38400 baud;
rows = 25; columns = 124; ypixels = 0; xpixels = 0;
csdata ?
eucw 1:0:0:0, scrw 1:0:0:0
intr = ^c; quit = ^\; erase = ^?; kill = ^u;
eof = ^d; eol = <undef>; eol2 = <undef>; swtch = <undef>;
start = ^q; stop = ^s; susp = ^z; dsusp = ^y;
rprnt = ^r; flush = ^o; werase = ^w; lnext = ^v;
-parenb -parodd cs8 -cstopb -hupcl cread -clocal -loblk crtscts -crtsxoff -parext
-ignbrk brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl -iuclc
ixon -ixany -ixoff imaxbel
isig icanon -xcase echo echoe echok -echonl -noflsh
-tostop echoctl -echoprt echoke -defecho -flusho -pendin iexten
opost -olcuc onlcr -ocrnl -onocr -onlret -ofill -ofdel tab3
If you want arrow keys to work then your terminal type must be set up to support the appropriate keyboard, such as vt200 or equivalent.
hmm... I'm confused now.
Are you talking about the shell (btw, if so - what shell are we talking about? bash/ksh/etc?) in the vi
command line editing mode?
Or are we talking about being in vi
editing a file?
In the program vi I press i
to go to insert mode. I press backspase
to try to delete something. It looks like it switches to command mode. It doesn't say command mode and insert mode on the bottom so it is hard to tell in vi. Unfortunately it does not delete what I am trying to delete.
@cokedude
have you resized (shrunk it/expanded it) your window?
If so, try resize
in the shell and bring up vi
again - might help to diagnose it a bit better.
What's your OS?
Is your vi
actually vim
under the covers?
What's your terminal emulation type in the window? (echo $TERM
)
It sounds like the Backspace key is sending one code and your vi
program is expecting something different. This often happens when the TERM
environment variable doesn't have the correct terminal type.
To properly diagnose this, I'll need to know:
- Operating system and version
- Version of
vi
(go intovi
and type:vers
and press Enter) - Contents of the
TERM
variable (from the CLI, typeecho $TERM
and press Enter) - The code that the terminal type thinks the Backspace key is sending (from the CLI, type
infocmp
and press Enter, then paste the entire contents into acode
block in your reply) - Your terminal emulator (if you're using one) or the desktop application name
It's likely that the Backspace key in the terminfo is different than your emulator, but there could be other issues as well, hence the request for a lot of information...
Resizing does not help.
Not sure which OS. None of the usual commands I can think of are working.
: cat /etc/os-release
cat: cannot open /etc/os-release
: lsb_release -a
-bash: lsb_release: command not found
: hostnamectl
-bash: hostnamectl: command not found
: uname -r
5.10
: which vi
/usr/bin/vi
: echo $TERM
vt100
: cat /etc/*-version
cat: cannot open /etc/*-version
: cat /etc/*-release
cat: cannot open /etc/*-release
@cokedude
doesn't look like it's Linux...
how about: uname -a
What happens if you force TERM to xterm: TERM='xterm'
and re-invoke vi?
Are you using putty
(or similar) to connect remotely?
That command worked.
: uname -a
SunOS ah5719006ub002 5.10 Generic_150400-64 sun4u sparc SUNW,SPARC-Enterprise
It acts like it is working. The cursor jumps back so I can overwrite what I want to delete. Then my cursor jumps up a line and starts adding random capital D
and P
on new lines.
D
D
Pa
P
P:
P
Can you please work backabcdefghis
Yes I am using putty.
Ugh, SunOS 5. Wow, that's old...
What is putty set to emulate? It's usually vt100 or vt220 or xterm. Whatever putty is set to, make sure your TERM
variable is set to the same thing, then execute tset
and press Enter (that should reset the terminal settings on the server side to what is expected by the emulator).
It almost sounds like the vi
on SunOS is putting the terminal into "application mode", which causes some keys to generate different codes than normal, then vi
doesn't understand them when they arrive.
If the tset
above doesn't work, try these commands at the CLI (see additional instructions, below):
cat | od -ac
<Tap the Backspace key a few times, then the up arrow a few times>
^D
After you press Enter on the first line, above, tap the Backspace and up arrow a few times. Type Control-D to terminate the cat
command and you should get your prompt back. (Might need to type ^D twice.) Then copy/paste the codes printed by od
.
SUNOS
Version SVR4.0, Solaris 2.5.0
: echo $TERM
xterm
: infocmp
# Reconstructed via infocmp from file: /usr/share/lib/terminfo/x/xterm
xterm|vs100|xterm terminal emulator,
am, km, mir, msgr, xenl,
cols#80, it#8, lines#65,
acsc=``aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~,
bel=^G, blink=\E[5m, bold=\E[1m, clear=\E[H\E[2J,
cr=\r, csr=\E[%i%p1%d;%p2%dr, cub=\E[%p1%dD, cub1=\b,
cud=\E[%p1%dB, cud1=\n, cuf=\E[%p1%dC, cuf1=\E[C,
cup=\E[%i%p1%d;%p2%dH, cuu=\E[%p1%dA, cuu1=\E[A,
dch=\E[%p1%dP, dch1=\E[P, dl=\E[%p1%dM, dl1=\E[M,
ed=\E[J, el=\E[K, el1=\E[1K$<3>, enacs=\E(B\E)0,
home=\E[H, ht=\t, hts=\EH, ich=\E[%p1%d@, ich1=\E[@,
il=\E[%p1%dL, il1=\E[L, ind=\n, ka1=\EOq, ka3=\EOs,
kb2=\EOr, kbs=\b, kc1=\EOp, kc3=\EOn, kcub1=\EOD,
kcud1=\EOB, kcuf1=\EOC, kcuu1=\EOA, kent=\EOM,
kf0=\E[21~, kf1=\E[11~, kf10=\EOx, kf2=\E[12~,
kf3=\E[13~, kf4=\E[14~, kf5=\E[15~, kf6=\E[17~,
kf7=\E[18~, kf8=\E[19~, kf9=\E[20~, rc=\E8, rev=\E[7m,
ri=\EM, rmacs=^O, rmkx=\E[?1l\E>, rmso=\E[m,
rmul=\E[m,
rs1=\E>\E[1;3;4;5;6l\E[?7h\E[m\E[r\E[2J\E[H, rs2=@,
sc=\E7,
sgr=\E[0%?%p1%p6%|%t;1%;%?%p2%t;4%;%?%p1%p3%|%t;7%;%?%p4%t;5%;m%?%p9%t^N%e^O%;,
sgr0=\E[m, smacs=^N, smkx=\E[?1h\E=, smso=\E[7m,
smul=\E[4m, tbc=\E[3g,
putty
Ah-ha. The kbs=\b
tells us that vi
will be expecting a normal ^H to be sent by the Backspace key in Putty. Your putty must be sending ^? instead (since that's what stty -a
said and you didn't complain about the Backspace not working at the command line). This means you have two choices.
You can use stty erase '^h'
so that the system thinks the right character is ^H and tell Putty to send the same (I don't use Putty, but I think it's under Settings > Terminal). Or, you can create a terminal configuration for vi
that overrides the one in that default configuration (I'd have to look that up as I don't remember the details for that on Sun's vi
command).
@cokedude
It's been awhile since I dealt with Solaris,
But if memory serves... One of the available term types was dtterm
.
Try TERM=dtterm
and run vi then.
And yes @Azhrei is correct backspace isn't configured what the emulator is I expecting: ^? vs ^H
You can reset it with man stty
specified options. Google should help as well...
Yeah, I think you are right; in any case, you can certainly rebind the backspace key code. However, if the TERM variable is set to something like vt200 (as long as this works with the equipment), you'll probably also get the expected result. I'd try both, experiment, and look at what code is actually produced, and if it's not what you want, change it.
Solaris 2.5 that is old. Full of Y2K bugs.
Get used to
cat /etc/*release
on Solaris will match /etc/release.
Use
export TERM; TERM=xterm
xterm
might be buggy; also try vt100
and vt200
Does this show what you want to see? Looks like od does not have the options you want.
: cat | od -ac
usage: od [-bcCdDfFoOsSvxX] [-] [file] [offset_string]
od [-bcCdDfFoOsSvxX] [-t type_string]... [-A address_base] [-j skip] [-N count] [-] [file...]
^H^H^H^H^[[A^[[A^[[B^[[B