Vim Tips Wiki

Tlgrok/Changed shell prompt when opening shell through Vim

1,612pages on
this wiki

< User:Tlgrok

Revision as of 19:14, May 6, 2009 by Tlgrok (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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):


(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.

Itai prompt standard My standard prompt.
Itai prompt in vim Prompt when a shell is run through Vim.

Around Wikia's network

Random Wiki