Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force bash to use .vimrc in vi mode

Tags:

bash

vim

Bash can be set to operate in vim mode . However, my .vimrc is no longer used. Specifically, my mapping of jj to Esc no longer works. I have to press Esc to exit to insert mode. How do I tell bash to use my .vimrc file?

like image 774
puk Avatar asked Jan 17 '12 05:01

puk


People also ask

How do I set bash to VI mode?

The bash shell (again, via GNU Readline) is able to provide this functionality for us. In order to enable it, you run the command $ set -o vi.

How do I source vimrc?

Sourcing it is the same as typing each command in order. You source with the command :source (usually shortened to :so ). The only file sourced by default is the . vimrc ( _vimrc on windows) so that's a place you can keep all the commands you use to set up Vim every time.


1 Answers

You are looking for bash-'s vi mode (which is just that: a vi input mode for bash, and has nothing at all to do with vi or vim).

It does have to do with readline/inputrc as far as I know so you could see whether you can

  • bind keys the bash way
  • from ~/.inputrc

links:

  • bash vi editing mode
  • .inputrc to make bash command-line editing like ksh
  • [Wikia:]Use vi shortcuts in terminal

The last link contains a somewhat more advanced example of a .inputrc for use with bash:

# Edit options before rerunning previous command, eg: ls a b c -> ls -al a b c
"\e-": "\C-p\C-a\M-f "

# Cycle thru completions.
"\e/": menu-complete

# glob patterns without executing, eg: 'rm *x'
"\ee": glob-expand-word

# Vim style history search
"\e[A": history-search-backward
"\e[B": history-search-forward

"\e[C": forward-char
"\e[D": backward-char

# Two escapes clear command line.
"\e\e": "\C-a\C-k"
like image 182
sehe Avatar answered Oct 14 '22 19:10

sehe