Sourcing .vimrc for use in bash shell?

233 views
Skip to first unread message

Sonny Chee

unread,
Jun 4, 2015, 2:31:24 AM6/4/15
to vim...@googlegroups.com
Hey Guys,

Is it possible to source .vimrc so that the mappings and settings within are available for command line editing in the shell?

Paul Isambert

unread,
Jun 4, 2015, 3:18:32 AM6/4/15
to vim...@googlegroups.com
> Is it possible to source .vimrc so that the mappings and settings
> within are available for command line editing in the shell?

Command line editing as in ZSH’s ZLE? You can always write some script
that reads the .vimrc and adapts it to whatever line editor you’re
using, but I guess that’s non-trivial.

Best,
Paul

Marc Weber

unread,
Jun 4, 2015, 4:52:49 AM6/4/15
to vim_use
> Is it possible to source .vimrc so that the mappings and settings
> within are available for command line editing in the shell?
.vimrc is interpreted in viml - zsh does not have a viml interpreter
embedded. So you need some kind of rewriting - you may even find ways to
automate it in some way - but because zsh/vim are independent
implementations you may hit cases which don't work.

Marc Weber

Nikolay Pavlov

unread,
Jun 4, 2015, 9:49:27 AM6/4/15
to vim...@googlegroups.com
Why you both reply about zsh? I do not see anything regarding what
exact shell was meant in the original post. For -bash- anything
readline-based there is an interesting project:
https://github.com/ardagnir/athame (alpha).

>
> Marc Weber
>
> --
> --
> You received this message from the "vim_use" 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_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Paul

unread,
Jun 6, 2015, 10:58:32 PM6/6/15
to vim...@googlegroups.com
On Thursday, June 4, 2015 at 2:31:24 AM UTC-4, Sonny Chee wrote:
> Hey Guys,
>
> Is it possible to source .vimrc so that the mappings and settings within are available for command line editing in the shell?

I don't find that my vimrc settings take effect when using vi editing mode in readline. However, I can use the fc commad to switch into full fledged vim. Googling hasn't clarified whether it is built-in to bash or a separate command (there's info indicating both cases). In Cygwin, it seems to be a separate executable, so not part of bash.

Eric Christopherson

unread,
Jun 6, 2015, 11:24:25 PM6/6/15
to vim...@googlegroups.com
You can tell for sure what kind of command fc is with

type fc

in the shell. For me it outputs "fc is a shell builtin". There's a
shortcut, though: hitting Ctrl-X Ctrl-E on any line will bring up an
editor for that particular line, like fc does. I think it also uses the
same environment variables as fc does to determine which editor to
launch.

--
Eric Christopherson

Paul

unread,
Jun 6, 2015, 11:33:26 PM6/6/15
to vim...@googlegroups.com
On Saturday, June 6, 2015 at 11:24:25 PM UTC-4, Eric Christopherson
wrote:
Actually, I'm blind. I did in fact use "type -a" and what came back
was

fc is a shell builtin
fc is /c/Windows/system32/fc

The Windows version does something completely unrelated.

As for Ctrl-X Ctrl-E, it doesn't do anything in my setup.

Eric Christopherson

unread,
Jun 6, 2015, 11:44:55 PM6/6/15
to vim...@googlegroups.com
That's strange. I don't have it explicitly enabled in .inputrc, but
`bind -p` shows it as

"\C-x\C-e": edit-and-execute-command

So you should be able to add that to your .inputrc. Or pick a key
binding that suits you better.

--
Eric Christopherson

Paul Domaskis

unread,
Jun 7, 2015, 1:45:17 AM6/7/15
to vim...@googlegroups.com
Hmmm, this is getting into a corner of bash that I'm completely new
to. I appreciate the pointer, but I'm going to squirrel this away for
future reference. I'm pretty happy with the vi functionality for now.

Erik Christiansen

unread,
Jun 7, 2015, 8:24:34 AM6/7/15
to vim...@googlegroups.com
On 06.06.15 22:24, Eric Christopherson wrote:
> On Sat, Jun 06, 2015, Paul wrote:
> > I don't find that my vimrc settings take effect when using vi editing
> > mode in readline. However, I can use the fc commad to switch into
> > full fledged vim. Googling hasn't clarified whether it is built-in to
> > bash or a separate command (there's info indicating both cases). In
> > Cygwin, it seems to be a separate executable, so not part of bash.
>
> You can tell for sure what kind of command fc is with
>
> type fc
>
> in the shell. For me it outputs "fc is a shell builtin".

That, though, is not an answer to the question of the type of the
executable which fc runs - it just shows that the "fc" initiator is
builtin. A brief look in the bash manpage reveals that it merely serves
to launch either $FCEDIT or $EDITOR.

Here, executing:

$ fc 801

confirms that another linux process is spawned, running vim:

$ ps -ef | grep vim
...
erik 4800 3105 1 21:15 pts/1 00:00:00 vim /tmp/bash-fc-4288462453

And .vimrc is sourced by this vim process, just like any other, as
one would expect. In the bash-fc vim instance:

:echo $MYVIMRC
/home/erik/.vimrc

which is additionally confirmed by all the personal settings being
present.

(No need to google any of this stuff. :-)

Erik

--
The rats can clear two hundred square meters in just 20 minutes. It would take
humans with metal detectors five days to cover the same area.
- http://www.abc.net.au/radionational/programs/latenightlive/african-herorats-detect-landmines-and-tuberculosis/6481122
Reply all
Reply to author
Forward
0 new messages