personal web log written by izabeera and dryobates

mysql vim

Editing SQL query directly in mysql client

by dryobates

Are you bothered moving cursor back and forth in commandline mysql client just for fix some error in long statement? I was also. Now I happily edit them in Vim.

You probably know basic editing keys like “a” for moving at the beginning of line or “e” for moving at the end. When you have long query and you have to edit it in command line mysql program (e.g. through shell connection) then ESC b and ESC w for jumping by words can save you some time. I was doing it for quite long time. But it’s still nothing to editing it in real editor. And now I’ve found a method that enables me to do it exactly right that - editing in editor. When you are during your interactive session:

mysql> select `some`, `long`, `list`, `of`, `parameters`from `long`, `list`, `of`, `tables`

Just put “e” and press enter:

mysql> select `some`, `long`, `list`, `of`, `parameters` from `long`, `list`, `of`, `tables`\e

This will bring you to your favourite editor (defined in $VISUAL or $EDITOR) with statement from mysql client. After editing just save and exit and that’s it.

Of course information on this option is in manual. I really don’t know how I could missed it when I were looking for it.

dryobates
dryobates
Jakub Stolarski. Software engineer. I work professionally as programmer since 2005. Speeding up software development with Test Driven Development, task automation and optimization for performance are things that focus my mind from my early career up to now. If you ask me for my religion: Python, Vim and FreeBSD are my trinity ;) Email: jakub@stolarscy.com

Archive

Tag cloud