sponsor Vim development Vim logo Vim Book Ad

changesqlcase.vim : Upper case sql keywords from a visual mode selection.

 script karma  Rating 4/5, Downloaded by 1434  Comments, bugs, improvements  Vim wiki

created by
culley harrelson
 
script type
utility
 
description
Description:
This plugin is a function that wraps around a big substitution expression.
The goal is to be able up upper case sql keywords from a visual selection.
It is quite similar to this script:

http://www.vim.org/scripts/script.php?script_id=305

which uses insert mode abbreviations to capitalize as you type.  My script
will be useful if you need to clean up existing scripts or if you are
programming in another language and want to format sql inside of a string
variable.  

The sql keyword list is taken from the postgresql 7.4 docs:

http://www.postgresql.org/docs/current/static/sql-keywords-appendix.html#KEYWORDS-TABLE

Please send a patch to include keywords specific to the database you are
working with.

Installation:

Place this script in your ~/.vim/plugin/ directory or source from your vimrc
file. To use the script create a visual map:

vmap <leader>uc  :call ChangeSqlCase()<cr>

Customization:
1. Add the confirmation flag to the substitution if you are mostly doing
single lines.  If you turn on confirmation on a multi-line visual selection
you will need to cancel out of the confirmation for each line.
2. delete any keywords that cause you grief.
3. add any keywords that are missing for your database

Todo:
1. This script could be modified to accept a database variable that altered
the keyword list.
2. lowercase as well as uppercase

Bugs:

As noted in the vim manual |10.3|:

   When using Visual mode to select part of a line, or using CTRL-V to
  select a block of text, the colon commands will still apply to whole
  lines.  This might change in a future version of Vim.

So if you select just the string in side of the quotes in the following
example:

test="select * from example" { dont update me }

the word 'update' after the end quote will also change case.  
 
install details
 

rate this script Life Changing Helpful Unfulfilling 
script versions (upload new version)

Click on the package to download.

package script version date Vim version user release notes
changesqlcase.vim 0.1.2 2003-12-31 6.0 culley harrelson removed confirmation flag-- it was causing too many problems for multi-line selections
changesqlcase.vim 0.1.1 2003-12-31 6.0 culley harrelson set confirmation flag as the default behavior
changesqlcase.vim 0.1 2003-12-31 6.0 culley harrelson Initial upload
ip used for rating: 18.226.251.22

If you have questions or remarks about this site, visit the vimonline development pages. Please use this site responsibly.
Questions about Vim should go to the maillist. Help Bram help Uganda.
   
Vim at Github