On 03/17/12 10:33, stardiviner wrote:
I want a vim script to convert SQL keyword(statement, clause,
those highlight group in file) to be converted to *uppercase*
when I type command `:w` to save file. And another way is when
I am typing: `select`, then vim automatically change to
`SELECT`. (this can be done with abbreviate).

While I don't know of anything that currently exists, if you want a somewhat sloppy version of it, you can use something like

:autocmd BufWrite * %s/\c\<\(select\|insert\|update\|create\|where\|from\|like\|group\_s\+by\|order\_s\+by\|having\)\>/\U&/g

Adjust for whatever SQL keywords you want to include. I did some basic ones, as well as examples of multi-word ones ("group by" and "order by")

The catch is that it only does dumb matching, so if you have something like

  select field1, field2
  from some_table
  where field3 like '%having%'

it will transform the "having" even though it's inside a string. It's a lot more complex to get it to be a little smarter about it (make sure that the current match isn't inside a string-literal on the same line) and a LOT more complex to make sure the match isn't part of a multi-line string such as

  insert into some_table(field1) values (
    'this string
     is one having
     multiple lines'
     )

(again, the "having" will be uppercased).

-tim


--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to