On 2019-06-01, Edward Peschko wrote:
> All,
>
> I was playing around with map and nested autocommands for
> splitting on buffers, and noticed that when I actually do a split
> via a map, ie:
>
> map ,, :split <cfile><CR>
>
> it actually goes through the whole setup process via starting the
> shell, loading the associated rc file, etc etc.
I tried reproducing this and found no evidence that a shell was run.
I executed the following,
$ strace -f -t -o strace.out vim -N -u NONE -i NONE
then within that vim defined you map and executed it. The window
split, as expected. I then exited vim and opened the strace.out
file in vim. There was no line containing "bash" in that file.
The version of vim I was using was 8.1.497 because it's what I had
handy. It's possible that the behavior you're seeing was introduced
since then.
Why do you think that vim spawns a shell when executing your map?
> However, for me this process is exceedingly long because I have an
> involved rc file that takes an order of seconds to execute and the
> commands were hanging as a result. So when I tried to set it to:
>
> export SHELL='/bin/tcsh -f'
>
> to save on startup cost, I got a message from vim saying "Cannot
> execute shell '/bin/tcsh -f'"
Right, because SHELL is the name of the shell, not the command to be
executed when you want to run a shell. You can, however, set the
vim option 'shell' to the full command, including options. See
:help 'shell'
Also, with bash you can determine in your rc file whether or not you
are running an interactive shell by testing for the presence of PS1
or for the presence of i in $-. See the INVOCATION section of the
bash(1) man page. You can thereby avoid executing the
time-consuming parts of your rc file when you're only using bash to
run some command, not establish an interactive shell environment.
> I ended up setting it to /bin/bash just to avoid the hassle.
>
> So a couple of things:
>
> 1. why does vim need to spawn a shell just to open up a new
> buffer? The command I used was "map ,, :split <cfile><CR>".
I don't think it does. We need to look into this further.
> 2. is it possible for vim to accept a SHELL with arguments,
> like the above, to avoid startup cost?
Assuming that whatever you're doing actually spawns a shell, you can
change the arguments given to that shell to prevent from reading
its startup files. For bash, these arguments would be --noprofile
and --norc.
When vim runs a shell to execute external commands, it passes that
shell the options in 'shellcmdflag'. You might be able to add those
two options to the 'shellcmdflag' option to have vim using those
options only when executing an external command and not when
spawning a shell with the :sh command.
> 3. is there a variable, say VIMSHELL that could be used to
> specify the shell to use in the case that #2 is not
> possible?
As I wrote above, use the 'shell' option.
Regards,
Gary
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/vim_dev/20190601205816.GA27734%40phoenix.
For more options, visit https://groups.google.com/d/optout.