I use vim a lot and often find it useful to drop into the command line using !bash.
However, I need to type exit to return to vim and sometimes I’m not sure whether I’m in a subshell or whether that will close my session.
What I’d really like to do is type something like !bash -prompt "subshell" so that I get something like this:
subshell$ <commands go here>
Is this possible?
The most direct way to do this is to set the
PS1environment variable within vim:And start your sub-shells using the command
:shellinstead of:!bash.Using the
$sign withletmodifies an environment variable. Add this to your .vimrc to persist the setting.Alternately, using
:shellyou can specify a more specific command, including arguments, using the shell option, seehelp shellandhelp 'shell'.So:
In .vimbashrc add
PS1="subshell ", and invoke the sub-shells using:shellinstead of!bash. Add this to your .vimrc to persist the setting.So you have two options:
let $PS1="subshell "to your .vimrc, and start sub-shells using:shellinstead of:!bash.PS1="subshell "to it, and modify theshelloption in your .vimrc:set shell=bash\ --rcfile\ ~/.vimbashrc.Finally, if you must use
:!bashto start the sub-shells there are a couple of more options. Note that you can also pass a more specific command line using!, e.g.::PS1="subshell$ " bashshould work.:!bash\ --rcfile\ ~/.vimbashrc, and setPS1in .vimbashrc as aboveBut you’ll need to type these every time, or define a mapping for it.