Schminitz
Schminitz

Reputation: 334

Detect background vim after :sh

I often use the :sh command while using vim (to do a grep for example).

But sometimes I forgot I had a vim running behind my shell.

Is there a command to detect that I have a vim running behind my shell?

Upvotes: 5

Views: 178

Answers (3)

chaos
chaos

Reputation: 9312

You could check the parent process:

$ ps -p $PPID -o cmd=
vi file

Or to be independent of environment variables:

$ ps -p $(ps -p $$ -o ppid=) -o cmd=
vi file

Upvotes: 0

romainl
romainl

Reputation: 196816

You can see if Vim-specific shell variables are set:

$ echo $VIM
$ echo $VIMRUNTIME
$ echo $MYVIMRC

Upvotes: 3

Marcus Hughes
Marcus Hughes

Reputation: 5503

You should have an environment variable set called VIM, you can see if this is then set

 $ echo $VIM

Note, it's also possible (unlikely) that $VIM is set when you're just in your shell normally.

Upvotes: 2

Related Questions