Reputation: 664
I am on windows machine, when I temporarily change to console using :sh
then back to vim with exit
command and then again back to console and it starts over. this causes me to lose my previous directory. Is there other way returning back to vim won't start the shell over?
Upvotes: 1
Views: 52
Reputation: 7678
Not really
https://stackoverflow.com/a/12089631/1427295
GVIM does not retain a "handle" to the shell that launched it in a way that allows it to send commands back to it. Because of they synchronous execution, you also cannot launch a shell from GVIM, keep feeding it commands while also continue working in GVIM.
I'm afraid you have to use the functionality of your window manager to launch (and then later re-activate) a shell window, and send the commands as keystrokes to it. On Windows, this can be done (e.g. in VBScript) via WshShell's Run(), AppActivate() and SendKeys() methods; there are probably similar mechanisms for window control on Linux, too.
If you don't mind having that shell inside your GVIM (emulated, with all its drawbacks), though, there are plugins that enable that.
https://serverfault.com/a/95405
The Windows command interpreter ("cmd.exe") doesn't provide any support for saving/exporting/keeping history, of, if it does, Microsoft didn't document it and nobody was ever able to find it. You can of course try to work around that, like Sean suggested, but there's (or does appear to be) no built-in support for this
You may be able to output your command history using echo %cd% > prev_dir.txt then create a script that cds to the directory in prev_dir.txt, but you'd still have to remember to save your directory to the file before you exit the shell each time.
Upvotes: 2