Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

  (email not shown publicly)
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Tuesday May 06, 2008
07:53 AM

Syntax Highlighting While Editing in MySQL Client

[ #36337 ]

You see, the great thing about posting vim stuff here is that people (Smylers, Aristotle, etc.) immediately post corrections. I appreciate that :)

Problem: when in the MySQL client, you can type 'edit' and edit your last SQL statement (can I go back further? I thought so, but I can't recall how). However, I want my syntax highlighting, but the filetype isn't set. After a bit of testing, I found out that the filename is always /var/tmp/sql* (on my system). So the following addition to my .vimrc fixes this:

" this is for MySQL's 'edit' command while in the client
au! BufRead,BufNewFile /var/tmp/sql* :call SetMySQL()
function! SetMySQL()
    set ft=sql
    SQLSetType mysql

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • For this to work it might also be necessary in certain cases for the following to appear in your .vimrc: filetype plugin on
  • Thanks! If anybody use PostgreSQL like I do, use "SQLSetType psql" instead
  • When you set filetype in an autocommand, it’s better to use the setf command instead of set ft=. And why not make it a one-liner?

    au! BufRead,BufNewFile /var/tmp/sql* setf sql | SQLSetType mysql
    • I guess setf is better in this case (didn't know about it until you suggested it), but I had tried to make this a one-liner, but I was using &&. I didn't think to try the bar. Thanks.

      Now to try and integrate SQL::Tidy [] :)