Home Explore Blog CI



neovim

2nd chunk of `runtime/doc/ft_sql.txt`
f5a7f473f90429768820f1905431fa28ba49a85e8f12058f0000000100000fa6
 previous 'end'


------------------------------------------------------------------------------
1.3 Predefined Object Motions			*sql-predefined-objects*

Most relational databases support various standard features, tables, indices,
triggers and stored procedures.  Each vendor also has a variety of proprietary
objects.  The next set of maps have been created to help move between these
objects.  Depends on which database vendor you are using, the list of objects
must be configurable.  The filetype plugin attempts to define many of the
standard objects, plus many additional ones.  In order to make this as
flexible as possible, you can override the list of objects from within your
|vimrc| with the following: >
    let g:ftplugin_sql_objects = 'function,procedure,event,table,trigger' ..
		\ ',schema,service,publication,database,datatype,domain' ..
		\ ',index,subscription,synchronization,view,variable'

The following |Normal| mode and |Visual| mode maps have been created which use
the above list: >
    ]}		    move forward to the next 'create <object name>'
    [{		    move backward to the previous 'create <object name>'

Repeatedly pressing ]} will cycle through each of these create statements: >
    create table t1 (
	...
    );

    create procedure p1
    begin
	...
    end;

    create index i1 on t1 (c1);

The default setting for g:ftplugin_sql_objects is: >
    let g:ftplugin_sql_objects = 'function,procedure,event,' ..
		\ '\\(existing\\\\|global\\s\\+temporary\\s\\+\\)\\\{,1}' ..
		\ 'table,trigger' ..
		\ ',schema,service,publication,database,datatype,domain' ..
		\ ',index,subscription,synchronization,view,variable'

The above will also handle these cases: >
    create table t1 (
	...
    );
    create existing table t2 (
	...
    );
    create global temporary table t3 (
	...
    );

By default, the ftplugin only searches for CREATE statements.  You can also
override this via your |init.vim| with the following: >
    let g:ftplugin_sql_statements = 'create,alter'

The filetype plugin defines three types of comments: >
    1.  --
    2.  //
    3.  /*
	 *
	 */

The following |Normal| mode and |Visual| mode maps have been created to work
with comments: >
    ]"		    move forward to the beginning of a comment
    ["		    move forward to the end of a comment



------------------------------------------------------------------------------
1.4 Macros					   *sql-macros*

Vim's feature to find macro definitions, |'define'|, is supported using this
regular expression: >
    \c\<\(VARIABLE\|DECLARE\|IN\|OUT\|INOUT\)\>

This addresses the following code: >
    CREATE VARIABLE myVar1 INTEGER;

    CREATE PROCEDURE sp_test(
	IN myVar2 INTEGER,
	OUT myVar3 CHAR(30),
	INOUT myVar4 NUMERIC(20,0)
    )
    BEGIN
	DECLARE myVar5 INTEGER;

	SELECT c1, c2, c3
	  INTO myVar2, myVar3, myVar4
	  FROM T1
	 WHERE c4 = myVar1;
    END;

Place your cursor on "myVar1" on this line: >
	 WHERE c4 = myVar1;
		     ^

Press any of the following keys: >
    [d
    [D
    [CTRL-D


==============================================================================
2. SQL Dialects					*sql-dialects* *sql-types*
						*sybase* *TSQL* *Transact-SQL*
						*sqlanywhere*
						*oracle* *plsql* *sqlj*
						*sqlserver*
						*mysql* *postgresql* *psql*
						*informix*

All relational databases support SQL.  There is a portion of SQL that is
portable across vendors (ex. CREATE TABLE, CREATE INDEX), but there is a
great deal of vendor specific extensions to SQL.  Oracle supports the
"CREATE OR REPLACE" syntax, column defaults specified in the CREATE TABLE
statement and the procedural language (for stored procedures and triggers).

The default Vim distribution ships with syntax highlighting based on Oracle's
PL/SQL.  The default SQL indent script works for Oracle and SQL Anywhere.
The default filetype plugin works for all vendors and should remain vendor
neutral, but extendable.

Vim currently has support for a variety of different vendors, currently this
is via syntax

Title: SQL Filetype Plugin: Object Motions, Macros, and Dialect Support
Summary
This section details predefined object motions in the SQL filetype plugin for Vim, allowing navigation between database objects (tables, procedures, etc.) based on configurable object lists. It also covers macro support using Vim's 'define' feature and highlights the plugin's handling of various SQL dialects, including Oracle, SQL Anywhere, and others, noting that the default syntax highlighting is based on Oracle's PL/SQL.