10 Aug 2013 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.