Operating System - HP-UX
1826343 Members
4709 Online
109692 Solutions
New Discussion

weird vi style command line recall / editing gotcha...

 
SOLVED
Go to solution
John Kittel
Trusted Contributor

weird vi style command line recall / editing gotcha...

Using posix shell with command recall and vi style editing, I'm familiar using with the common vi commands to add, change, modify etc the command and resubmit it... do that all the time.

But, sometimes after I recall the command, I accidentally hit the "v" key. It puts me into screen mode vi with the recalled command as the file being edited. Here's the gotcha: I haven't been able to figure out how to exit out of vi without having the original command get executed by the shell. Even if I delete the entire line so that vi shows a blank file, and then do a :q , the shell still executes the original command.

If you don't understand what I mean, you can try it yourself, - enter a benign command, for example "pwd". Recall it with ^k, hit the "v" key, ( should put you into screen mode vi with the pwd command as the whole contents of the file), then try to get out of vi without having the pwd command get executed again.

- John
9 REPLIES 9
Patrick Wallek
Honored Contributor
Solution

Re: weird vi style command line recall / editing gotcha...

You can delete the line and then do a :wq so that vi will save and then exit. Doing just a :q basically just exits and doesn't save what you did so it still executes whatever is in the /var/tmp file for that vi session. Saving the blank file is the key.

When you exit, you will see a file name like /var/tmp/sh16819.3 That file does not exist for very long. I just did that and immediately did an 'll /var/tmp/sh16819.3' and the file does not exist.

Jeff_Traigle
Honored Contributor

Re: weird vi style command line recall / editing gotcha...

Do :wq instead... it saves the deletion to the temp file it created and doesn't execute the original command.
--
Jeff Traigle
John Kittel
Trusted Contributor

Re: weird vi style command line recall / editing gotcha...

Thanks guys. You've saved me again.

- John
Jeff Schussele
Honored Contributor

Re: weird vi style command line recall / editing gotcha...

Hi John,

Switch back to the original screen & do a Ctrl-C & *then* go to the vi screen & close it out. The recalled command will not be executed on the org screen.
What you're interrupting with the Ctrl-C is an fc command that looks like

fc -e "${VISUAL:-${EDITOR:-vi}}" X

where X=command offset number.
In fact you should be able to pull it up out of history.

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
John Kittel
Trusted Contributor

Re: weird vi style command line recall / editing gotcha...

Jeff, how do I switch back to original screen?
Jeff Schussele
Honored Contributor

Re: weird vi style command line recall / editing gotcha...

I should have mentioned that this was the CDE desktop method - i.e. I'm running dtterm sessions. My editor pops up in it's own "Text Editor" screen with the temp file name in the title.
You must just be plain old telnetted or ssh'd in.

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
John Kittel
Trusted Contributor

Re: weird vi style command line recall / editing gotcha...

Thanks Jeff. Yes, I'm in with telnet.

- John
Patrick Wallek
Honored Contributor

Re: weird vi style command line recall / editing gotcha...

Sorry for the off topic question ----

Jeff Schussele -- How do you have your CDE set up so it does that. I'm also working from CDE with dtterm windows to a bunch of my machines, but when I hit 'v' I get the plain ole vi within that terminal window. What give?
Jeff Schussele
Honored Contributor

Re: weird vi style command line recall / editing gotcha...

Hi Patrick,

It's 11.11 out of the box default on a B2600.
I've checked the Style Manager, Application Manager, Window Info, Windows Properties & can find nothing out of the ordinary.
BUT I do find that when I run - in any session
#env | grep -i editor I get
EDITOR=/usr/dt/bin/dtpad
So it has to be set up by dt somehow, although I have nothing explicitly set in .dtprofile
System boots | init runs ttsession -s | then dtsession runs | which serves as a parent for dtwm | which is the parent for all the dtexec commands when I open windows

Rgds,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!