Tlgrok/Changed shell prompt when opening shell through Vim
Talk0this wiki
< User:Tlgrok
This is a draft, quarantined as a subpage of my own userpage until (and if) it is ready to face the world. Feel free to edit it.
Vim allows you to open a shell by typing (in insert mode):
:shell
(See :help :shell.)
It might be useful to be able to tell instantly whether you're in a true shell or in a shell-within-Vim (in which case you might still have files open, and should not, for instance, close the terminal). I do this by prefixing my shell prompt with "[vim]" whenever appropriate. The key to doing this is the environment variable $VIMRUNTIME (see :help :$VIMRUNTIME), which is only set when Vim is running.
In your shell configuration file, add the following below the place you set your prompt (if you're not sure where your prompt is set, add this at the bottom of the file):
[[ -n $VIMRUNTIME ]] && export PS1="[vim] $PS1"
This has been tested for .zshrc (Zsh) and .bashrc (Bash), and will probably work in most shells.
| My standard prompt. | |
| Prompt when a shell is run through Vim. |