VIM, when I shell to prompt using :!bash I'd like the command prompt to reflect me being in a shell
I am in vim all day lately, practicing code. Often times when I want to do something from the prompt - I will use a key binding for :!bash and do what ever I need to do, then type exit to return to the vim script I am working on.
sometimes I forget that I am in a shell and need to poke around to find my script. Is there a way to set it up so that my prompt says "vim $:" or something similar?
I suppose I could try to create a .bashrc_for_vim
and run source .bashrc_for_vim
or something like that, but that seems pretty clunky.
Has anyone here figured out an elegant way to do this?
bash vim prompt
add a comment |
I am in vim all day lately, practicing code. Often times when I want to do something from the prompt - I will use a key binding for :!bash and do what ever I need to do, then type exit to return to the vim script I am working on.
sometimes I forget that I am in a shell and need to poke around to find my script. Is there a way to set it up so that my prompt says "vim $:" or something similar?
I suppose I could try to create a .bashrc_for_vim
and run source .bashrc_for_vim
or something like that, but that seems pretty clunky.
Has anyone here figured out an elegant way to do this?
bash vim prompt
add a comment |
I am in vim all day lately, practicing code. Often times when I want to do something from the prompt - I will use a key binding for :!bash and do what ever I need to do, then type exit to return to the vim script I am working on.
sometimes I forget that I am in a shell and need to poke around to find my script. Is there a way to set it up so that my prompt says "vim $:" or something similar?
I suppose I could try to create a .bashrc_for_vim
and run source .bashrc_for_vim
or something like that, but that seems pretty clunky.
Has anyone here figured out an elegant way to do this?
bash vim prompt
I am in vim all day lately, practicing code. Often times when I want to do something from the prompt - I will use a key binding for :!bash and do what ever I need to do, then type exit to return to the vim script I am working on.
sometimes I forget that I am in a shell and need to poke around to find my script. Is there a way to set it up so that my prompt says "vim $:" or something similar?
I suppose I could try to create a .bashrc_for_vim
and run source .bashrc_for_vim
or something like that, but that seems pretty clunky.
Has anyone here figured out an elegant way to do this?
bash vim prompt
bash vim prompt
asked Feb 1 at 2:03
Robert BakerRobert Baker
8210
8210
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
I make use of the $SHLVL
environment variable, described in man bash
as
SHLVL Incremented by one each time an instance of bash is started.
In my ~/.bashrc
:
# set a variable to reflect SHLVL > 1
if [[ $SHLVL -gt 1 ]] ; then
export SUBSHELL="${SUBSHELL:+$SUBSHELL}+"
else
export SUBSHELL=""
fi
I use this later in setting up my PS1
to add a "+" for each level down.
if [[ "$color_prompt" = yes ]]; then
# chroot? Depth green user@host nocolor : green $PWD ref (status) off $ or # space
PS1='${debian_chroot:+($debian_chroot)}${SUBSHELL}[33[01;32m]u@h[33[00m]:[33[01;34m]w[33[1;31m]($?)[33[00m]$ '
else
PS1='${debian_chroot:+($debian_chroot)}${SUBSHELL}u@h:w$ '
fi
unset color_prompt force_color_prompt
In use, it looks like:
walt@bat:~(0)$ uptime
22:57:48 up 2 days, 9:51, 2 users, load average: 2.23, 0.75, 0.41
# start a subshell, see the first "+" appear
walt@bat:~(0)$ bash
# start a 2nd subshell, see the second "+" appear
+walt@bat:~(0)$ bash
# Start vim, then do :!bash
++walt@bat:~(0)$ vim foo
# here, underneath vim, look at the process tree leading to here
+++walt@bat:~(0)$ ps -fp$$
UID PID PPID C STIME TTY TIME CMD
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802
UID PID PPID C STIME TTY TIME CMD
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732
UID PID PPID C STIME TTY TIME CMD
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732,6662
UID PID PPID C STIME TTY TIME CMD
walt 6662 5932 0 23:10 pts/21 00:00:00 bash
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732,6662,5932
UID PID PPID C STIME TTY TIME CMD
walt 5932 5795 0 Jan29 pts/21 00:00:00 bash
walt 6662 5932 0 23:10 pts/21 00:00:00 bash
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732,6662,5932,5795
UID PID PPID C STIME TTY TIME CMD
walt 5795 5070 0 Jan29 ? 00:00:37 /usr/lib/gnome-terminal/gnome-terminal-server
walt 5932 5795 0 Jan29 pts/21 00:00:00 bash
walt 6662 5932 0 23:10 pts/21 00:00:00 bash
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
# now unwind, returning to vim
+++walt@bat:~(0)$ exit
# back in vim, :q!
Press ENTER or type command to continue
# unwind
++walt@bat:~(0)$ exit
# unwind
+walt@bat:~(0)$ exit
# back at the top level
walt@bat:~(0)$ : and I'm out
Hey thank you very much! That works perfectly when I shell out, differently when I <CTRL Z>. One question though, what value is represented between the ( )'s, in your case (0)? The reason I ask is I did a <CRTL Z> from Vim and it didn't have the +, but it did have a value of (140) in red. there.
– Robert Baker
Feb 1 at 4:44
add a comment |
Vim sets the VIMRUNTIME
(and VIM
) environment variables within the shell from :sh
or :!bash
, so you can detect it that way in your .bashrc
:
if [ "$VIMRUNTIME" ]
then
PS1="vim: $PS1"
fi
The above will prefix your existing prompt with "vim: ". You could change it to something else, like just vim $:
, if you wanted. Put that at the end of the file so that your normal prompt has been set up by then, so you can either use it or replace it.
You can't do the same for Ctrl-Z because that really does return you to your original shell - it's not a new session, it's the one you started vim
from in the first place, so it has the same environment and settings as you started with.
that is really interesting, thank you for the information, I am going to give that a try!
– Robert Baker
Feb 1 at 4:50
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1114597%2fvim-when-i-shell-to-prompt-using-bash-id-like-the-command-prompt-to-reflect%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I make use of the $SHLVL
environment variable, described in man bash
as
SHLVL Incremented by one each time an instance of bash is started.
In my ~/.bashrc
:
# set a variable to reflect SHLVL > 1
if [[ $SHLVL -gt 1 ]] ; then
export SUBSHELL="${SUBSHELL:+$SUBSHELL}+"
else
export SUBSHELL=""
fi
I use this later in setting up my PS1
to add a "+" for each level down.
if [[ "$color_prompt" = yes ]]; then
# chroot? Depth green user@host nocolor : green $PWD ref (status) off $ or # space
PS1='${debian_chroot:+($debian_chroot)}${SUBSHELL}[33[01;32m]u@h[33[00m]:[33[01;34m]w[33[1;31m]($?)[33[00m]$ '
else
PS1='${debian_chroot:+($debian_chroot)}${SUBSHELL}u@h:w$ '
fi
unset color_prompt force_color_prompt
In use, it looks like:
walt@bat:~(0)$ uptime
22:57:48 up 2 days, 9:51, 2 users, load average: 2.23, 0.75, 0.41
# start a subshell, see the first "+" appear
walt@bat:~(0)$ bash
# start a 2nd subshell, see the second "+" appear
+walt@bat:~(0)$ bash
# Start vim, then do :!bash
++walt@bat:~(0)$ vim foo
# here, underneath vim, look at the process tree leading to here
+++walt@bat:~(0)$ ps -fp$$
UID PID PPID C STIME TTY TIME CMD
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802
UID PID PPID C STIME TTY TIME CMD
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732
UID PID PPID C STIME TTY TIME CMD
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732,6662
UID PID PPID C STIME TTY TIME CMD
walt 6662 5932 0 23:10 pts/21 00:00:00 bash
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732,6662,5932
UID PID PPID C STIME TTY TIME CMD
walt 5932 5795 0 Jan29 pts/21 00:00:00 bash
walt 6662 5932 0 23:10 pts/21 00:00:00 bash
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732,6662,5932,5795
UID PID PPID C STIME TTY TIME CMD
walt 5795 5070 0 Jan29 ? 00:00:37 /usr/lib/gnome-terminal/gnome-terminal-server
walt 5932 5795 0 Jan29 pts/21 00:00:00 bash
walt 6662 5932 0 23:10 pts/21 00:00:00 bash
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
# now unwind, returning to vim
+++walt@bat:~(0)$ exit
# back in vim, :q!
Press ENTER or type command to continue
# unwind
++walt@bat:~(0)$ exit
# unwind
+walt@bat:~(0)$ exit
# back at the top level
walt@bat:~(0)$ : and I'm out
Hey thank you very much! That works perfectly when I shell out, differently when I <CTRL Z>. One question though, what value is represented between the ( )'s, in your case (0)? The reason I ask is I did a <CRTL Z> from Vim and it didn't have the +, but it did have a value of (140) in red. there.
– Robert Baker
Feb 1 at 4:44
add a comment |
I make use of the $SHLVL
environment variable, described in man bash
as
SHLVL Incremented by one each time an instance of bash is started.
In my ~/.bashrc
:
# set a variable to reflect SHLVL > 1
if [[ $SHLVL -gt 1 ]] ; then
export SUBSHELL="${SUBSHELL:+$SUBSHELL}+"
else
export SUBSHELL=""
fi
I use this later in setting up my PS1
to add a "+" for each level down.
if [[ "$color_prompt" = yes ]]; then
# chroot? Depth green user@host nocolor : green $PWD ref (status) off $ or # space
PS1='${debian_chroot:+($debian_chroot)}${SUBSHELL}[33[01;32m]u@h[33[00m]:[33[01;34m]w[33[1;31m]($?)[33[00m]$ '
else
PS1='${debian_chroot:+($debian_chroot)}${SUBSHELL}u@h:w$ '
fi
unset color_prompt force_color_prompt
In use, it looks like:
walt@bat:~(0)$ uptime
22:57:48 up 2 days, 9:51, 2 users, load average: 2.23, 0.75, 0.41
# start a subshell, see the first "+" appear
walt@bat:~(0)$ bash
# start a 2nd subshell, see the second "+" appear
+walt@bat:~(0)$ bash
# Start vim, then do :!bash
++walt@bat:~(0)$ vim foo
# here, underneath vim, look at the process tree leading to here
+++walt@bat:~(0)$ ps -fp$$
UID PID PPID C STIME TTY TIME CMD
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802
UID PID PPID C STIME TTY TIME CMD
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732
UID PID PPID C STIME TTY TIME CMD
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732,6662
UID PID PPID C STIME TTY TIME CMD
walt 6662 5932 0 23:10 pts/21 00:00:00 bash
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732,6662,5932
UID PID PPID C STIME TTY TIME CMD
walt 5932 5795 0 Jan29 pts/21 00:00:00 bash
walt 6662 5932 0 23:10 pts/21 00:00:00 bash
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732,6662,5932,5795
UID PID PPID C STIME TTY TIME CMD
walt 5795 5070 0 Jan29 ? 00:00:37 /usr/lib/gnome-terminal/gnome-terminal-server
walt 5932 5795 0 Jan29 pts/21 00:00:00 bash
walt 6662 5932 0 23:10 pts/21 00:00:00 bash
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
# now unwind, returning to vim
+++walt@bat:~(0)$ exit
# back in vim, :q!
Press ENTER or type command to continue
# unwind
++walt@bat:~(0)$ exit
# unwind
+walt@bat:~(0)$ exit
# back at the top level
walt@bat:~(0)$ : and I'm out
Hey thank you very much! That works perfectly when I shell out, differently when I <CTRL Z>. One question though, what value is represented between the ( )'s, in your case (0)? The reason I ask is I did a <CRTL Z> from Vim and it didn't have the +, but it did have a value of (140) in red. there.
– Robert Baker
Feb 1 at 4:44
add a comment |
I make use of the $SHLVL
environment variable, described in man bash
as
SHLVL Incremented by one each time an instance of bash is started.
In my ~/.bashrc
:
# set a variable to reflect SHLVL > 1
if [[ $SHLVL -gt 1 ]] ; then
export SUBSHELL="${SUBSHELL:+$SUBSHELL}+"
else
export SUBSHELL=""
fi
I use this later in setting up my PS1
to add a "+" for each level down.
if [[ "$color_prompt" = yes ]]; then
# chroot? Depth green user@host nocolor : green $PWD ref (status) off $ or # space
PS1='${debian_chroot:+($debian_chroot)}${SUBSHELL}[33[01;32m]u@h[33[00m]:[33[01;34m]w[33[1;31m]($?)[33[00m]$ '
else
PS1='${debian_chroot:+($debian_chroot)}${SUBSHELL}u@h:w$ '
fi
unset color_prompt force_color_prompt
In use, it looks like:
walt@bat:~(0)$ uptime
22:57:48 up 2 days, 9:51, 2 users, load average: 2.23, 0.75, 0.41
# start a subshell, see the first "+" appear
walt@bat:~(0)$ bash
# start a 2nd subshell, see the second "+" appear
+walt@bat:~(0)$ bash
# Start vim, then do :!bash
++walt@bat:~(0)$ vim foo
# here, underneath vim, look at the process tree leading to here
+++walt@bat:~(0)$ ps -fp$$
UID PID PPID C STIME TTY TIME CMD
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802
UID PID PPID C STIME TTY TIME CMD
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732
UID PID PPID C STIME TTY TIME CMD
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732,6662
UID PID PPID C STIME TTY TIME CMD
walt 6662 5932 0 23:10 pts/21 00:00:00 bash
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732,6662,5932
UID PID PPID C STIME TTY TIME CMD
walt 5932 5795 0 Jan29 pts/21 00:00:00 bash
walt 6662 5932 0 23:10 pts/21 00:00:00 bash
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732,6662,5932,5795
UID PID PPID C STIME TTY TIME CMD
walt 5795 5070 0 Jan29 ? 00:00:37 /usr/lib/gnome-terminal/gnome-terminal-server
walt 5932 5795 0 Jan29 pts/21 00:00:00 bash
walt 6662 5932 0 23:10 pts/21 00:00:00 bash
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
# now unwind, returning to vim
+++walt@bat:~(0)$ exit
# back in vim, :q!
Press ENTER or type command to continue
# unwind
++walt@bat:~(0)$ exit
# unwind
+walt@bat:~(0)$ exit
# back at the top level
walt@bat:~(0)$ : and I'm out
I make use of the $SHLVL
environment variable, described in man bash
as
SHLVL Incremented by one each time an instance of bash is started.
In my ~/.bashrc
:
# set a variable to reflect SHLVL > 1
if [[ $SHLVL -gt 1 ]] ; then
export SUBSHELL="${SUBSHELL:+$SUBSHELL}+"
else
export SUBSHELL=""
fi
I use this later in setting up my PS1
to add a "+" for each level down.
if [[ "$color_prompt" = yes ]]; then
# chroot? Depth green user@host nocolor : green $PWD ref (status) off $ or # space
PS1='${debian_chroot:+($debian_chroot)}${SUBSHELL}[33[01;32m]u@h[33[00m]:[33[01;34m]w[33[1;31m]($?)[33[00m]$ '
else
PS1='${debian_chroot:+($debian_chroot)}${SUBSHELL}u@h:w$ '
fi
unset color_prompt force_color_prompt
In use, it looks like:
walt@bat:~(0)$ uptime
22:57:48 up 2 days, 9:51, 2 users, load average: 2.23, 0.75, 0.41
# start a subshell, see the first "+" appear
walt@bat:~(0)$ bash
# start a 2nd subshell, see the second "+" appear
+walt@bat:~(0)$ bash
# Start vim, then do :!bash
++walt@bat:~(0)$ vim foo
# here, underneath vim, look at the process tree leading to here
+++walt@bat:~(0)$ ps -fp$$
UID PID PPID C STIME TTY TIME CMD
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802
UID PID PPID C STIME TTY TIME CMD
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732
UID PID PPID C STIME TTY TIME CMD
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732,6662
UID PID PPID C STIME TTY TIME CMD
walt 6662 5932 0 23:10 pts/21 00:00:00 bash
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732,6662,5932
UID PID PPID C STIME TTY TIME CMD
walt 5932 5795 0 Jan29 pts/21 00:00:00 bash
walt 6662 5932 0 23:10 pts/21 00:00:00 bash
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
+++walt@bat:~(0)$ ps -fp$$,6802,6732,6662,5932,5795
UID PID PPID C STIME TTY TIME CMD
walt 5795 5070 0 Jan29 ? 00:00:37 /usr/lib/gnome-terminal/gnome-terminal-server
walt 5932 5795 0 Jan29 pts/21 00:00:00 bash
walt 6662 5932 0 23:10 pts/21 00:00:00 bash
walt 6732 6662 0 23:10 pts/21 00:00:00 bash
walt 6802 6732 0 23:10 pts/21 00:00:00 vim foo
walt 6803 6802 0 23:10 pts/21 00:00:00 bash
# now unwind, returning to vim
+++walt@bat:~(0)$ exit
# back in vim, :q!
Press ENTER or type command to continue
# unwind
++walt@bat:~(0)$ exit
# unwind
+walt@bat:~(0)$ exit
# back at the top level
walt@bat:~(0)$ : and I'm out
answered Feb 1 at 4:21
waltinatorwaltinator
22.8k74169
22.8k74169
Hey thank you very much! That works perfectly when I shell out, differently when I <CTRL Z>. One question though, what value is represented between the ( )'s, in your case (0)? The reason I ask is I did a <CRTL Z> from Vim and it didn't have the +, but it did have a value of (140) in red. there.
– Robert Baker
Feb 1 at 4:44
add a comment |
Hey thank you very much! That works perfectly when I shell out, differently when I <CTRL Z>. One question though, what value is represented between the ( )'s, in your case (0)? The reason I ask is I did a <CRTL Z> from Vim and it didn't have the +, but it did have a value of (140) in red. there.
– Robert Baker
Feb 1 at 4:44
Hey thank you very much! That works perfectly when I shell out, differently when I <CTRL Z>. One question though, what value is represented between the ( )'s, in your case (0)? The reason I ask is I did a <CRTL Z> from Vim and it didn't have the +, but it did have a value of (140) in red. there.
– Robert Baker
Feb 1 at 4:44
Hey thank you very much! That works perfectly when I shell out, differently when I <CTRL Z>. One question though, what value is represented between the ( )'s, in your case (0)? The reason I ask is I did a <CRTL Z> from Vim and it didn't have the +, but it did have a value of (140) in red. there.
– Robert Baker
Feb 1 at 4:44
add a comment |
Vim sets the VIMRUNTIME
(and VIM
) environment variables within the shell from :sh
or :!bash
, so you can detect it that way in your .bashrc
:
if [ "$VIMRUNTIME" ]
then
PS1="vim: $PS1"
fi
The above will prefix your existing prompt with "vim: ". You could change it to something else, like just vim $:
, if you wanted. Put that at the end of the file so that your normal prompt has been set up by then, so you can either use it or replace it.
You can't do the same for Ctrl-Z because that really does return you to your original shell - it's not a new session, it's the one you started vim
from in the first place, so it has the same environment and settings as you started with.
that is really interesting, thank you for the information, I am going to give that a try!
– Robert Baker
Feb 1 at 4:50
add a comment |
Vim sets the VIMRUNTIME
(and VIM
) environment variables within the shell from :sh
or :!bash
, so you can detect it that way in your .bashrc
:
if [ "$VIMRUNTIME" ]
then
PS1="vim: $PS1"
fi
The above will prefix your existing prompt with "vim: ". You could change it to something else, like just vim $:
, if you wanted. Put that at the end of the file so that your normal prompt has been set up by then, so you can either use it or replace it.
You can't do the same for Ctrl-Z because that really does return you to your original shell - it's not a new session, it's the one you started vim
from in the first place, so it has the same environment and settings as you started with.
that is really interesting, thank you for the information, I am going to give that a try!
– Robert Baker
Feb 1 at 4:50
add a comment |
Vim sets the VIMRUNTIME
(and VIM
) environment variables within the shell from :sh
or :!bash
, so you can detect it that way in your .bashrc
:
if [ "$VIMRUNTIME" ]
then
PS1="vim: $PS1"
fi
The above will prefix your existing prompt with "vim: ". You could change it to something else, like just vim $:
, if you wanted. Put that at the end of the file so that your normal prompt has been set up by then, so you can either use it or replace it.
You can't do the same for Ctrl-Z because that really does return you to your original shell - it's not a new session, it's the one you started vim
from in the first place, so it has the same environment and settings as you started with.
Vim sets the VIMRUNTIME
(and VIM
) environment variables within the shell from :sh
or :!bash
, so you can detect it that way in your .bashrc
:
if [ "$VIMRUNTIME" ]
then
PS1="vim: $PS1"
fi
The above will prefix your existing prompt with "vim: ". You could change it to something else, like just vim $:
, if you wanted. Put that at the end of the file so that your normal prompt has been set up by then, so you can either use it or replace it.
You can't do the same for Ctrl-Z because that really does return you to your original shell - it's not a new session, it's the one you started vim
from in the first place, so it has the same environment and settings as you started with.
answered Feb 1 at 4:48
Michael HomerMichael Homer
1575
1575
that is really interesting, thank you for the information, I am going to give that a try!
– Robert Baker
Feb 1 at 4:50
add a comment |
that is really interesting, thank you for the information, I am going to give that a try!
– Robert Baker
Feb 1 at 4:50
that is really interesting, thank you for the information, I am going to give that a try!
– Robert Baker
Feb 1 at 4:50
that is really interesting, thank you for the information, I am going to give that a try!
– Robert Baker
Feb 1 at 4:50
add a comment |
Thanks for contributing an answer to Ask Ubuntu!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f1114597%2fvim-when-i-shell-to-prompt-using-bash-id-like-the-command-prompt-to-reflect%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown