38

I have vi bindings working in my bash shell using set -o vi in my .bash_profile. But I can't seem to get them to work in the mysql command line client. I only get emacs style bindings. How do you do this?

I also put these lines in my .inputrc, but to with no effect:

set editing-mode vi
set keymap vi
codeforester
  • 39,467
  • 16
  • 112
  • 140
dan
  • 43,914
  • 47
  • 153
  • 254
  • 2
    Embrace the dark-side, learn to use emacs keys! *bwahahaha!* Seriously, I wish I could help you, though I am an emacs aficionado. – Omnifarious Feb 07 '10 at 09:16
  • 2
    mysql doesn't use readline. An ldd on the executable reveals this. – Omnifarious Feb 07 '10 at 09:25
  • 4
    I did get mysql vi-keybindings working somehow on my other computer, so I know this is possible. VI forever. – dan Feb 07 '10 at 15:36
  • I'm having this issue on my CURRENT OsX install, but didn't on the last. I'm reasonably sure this is directly related to the version of MySQL and how it's compiled. I'm currently running 5.6.13 from Mysql.com . Maybe the homebrew installed one would work? – John Hirbour Jun 13 '14 at 13:08
  • @dan please accept the better answer by John Hirbour. What good is vi mode if we lose tab completion? – necromancer Nov 17 '14 at 21:18
  • Sometimes for me it just works. All of a sudden I can use ESC-K to scroll through history etc. I have not changed any settings (have `set -o vi` for my bash) just noticed it has begun working occasionally. Most of the time it does not. Is there some keypress sequence which is triggering it? – Sodved Nov 27 '18 at 03:04

5 Answers5

43

Quick google reveals this... don't know if it helps.

Copied here for convenience:

Add the following on OS X 10.5:

$ cat .editrc
bind -v

This will work for OS X 10.4 and other operating systems:

$ cat .inputrc
set editing-mode vi
Madbreaks
  • 19,094
  • 7
  • 58
  • 72
John Weldon
  • 39,849
  • 11
  • 94
  • 127
21

These two files worked on my previous workstation (not sure of the MySQL version (my old job)). I keep my dotFiles in git.

.editrc

bind -v
bind \\t rl_complete

.inputrc (several of these may or may-not be needed)

set editing-mode vi
set keymap vi
set meta-flag on
set input-meta on
set convert-meta off
set output-meta on
set bell-style none

Posting these because I couldn't post them in my comment above.

amphetamachine
  • 27,620
  • 12
  • 60
  • 72
John Hirbour
  • 536
  • 3
  • 5
  • 7
    The `bind \\t rl_complete` brought back tab completion! Something that I lost using the other solutions. – pedrohdz Jul 03 '14 at 21:18
  • hallelujah! I was really stuck without tab completion. What good is vi mode if I have to type long table and column names. Thank you very much for this complete answer. – necromancer Nov 17 '14 at 21:16
1

This doesn't directly answer your question, but you might want to take a look at the dbext plugin.

This plugin contains functions/mappings/commands to enable Vim to access several databases.

[...]

dbext provides a common interface between your editor and a database. If your company/project moves onto a new database platform, there is no need to learn the new databases tools. While editing your SQL (and without leaving Vim) you can execute database commands, run queries, display results, and view database objects. dbext understands various programming languages, and can parse and prompt the user for [host] variables and execute the resulting statement. See below for more details.

A database client inside Vim!

Community
  • 1
  • 1
Matteo Riva
  • 24,728
  • 12
  • 72
  • 104
0

The voted answer is ok, but if you're encountering problems as it happened to me (I'm currently using Slackware 14.x) then editing /etc/inputrc should be your last hope.

I've tested both .inputrc and .editrc on my home, but on my system only editing /etc/inputrc worked.

Acsor
  • 1,011
  • 2
  • 13
  • 26
0

Also, this is not answer to your question.

You can also use Vimsql like dbext. Vimsql is more convenient way interacting with mysql than mysql if you love vim key map.

Jason Heo
  • 9,956
  • 2
  • 36
  • 64