robin/laufey
git clone https://git.robinwobin.dev/robin/laufey
1cb1cfead0
master
1*ft_sql.txt* Nvim 2 3by David Fishburn 4 5This is a filetype plugin to work with SQL files. 6 7The Structured Query Language (SQL) is a standard which specifies statements 8that allow a user to interact with a relational database. Vim includes 9features for navigation, indentation and syntax highlighting. 10 11 Type |gO| to see the table of contents. 12 13============================================================================== 141. Navigation *sql-navigation* 15 16The SQL ftplugin provides a number of options to assist with file 17navigation. 18 19 20------------------------------------------------------------------------------ 211.1 Matchit *sql-matchit* 22 23The matchit plugin (https://www.vim.org/scripts/script.php?script_id=39) 24provides many additional features and can be customized for different 25languages. The matchit plugin is configured by defining a local 26buffer variable, b:match_words. Pressing the % key while on various 27keywords will move the cursor to its match. For example, if the cursor 28is on an "if", pressing % will cycle between the "else", "elseif" and 29"end if" keywords. 30 31The following keywords are supported: > 32 if 33 elseif | elsif 34 else [if] 35 end if 36 37 [while condition] loop 38 leave 39 break 40 continue 41 exit 42 end loop 43 44 for 45 leave 46 break 47 continue 48 exit 49 end loop 50 51 do 52 statements 53 doend 54 55 case 56 when 57 when 58 default 59 end case 60 61 merge 62 when not matched 63 when matched 64 65 create[ or replace] procedure|function|event 66 returns 67 68 69------------------------------------------------------------------------------ 701.2 Text Object Motions *sql-object-motions* 71 72Vim has a number of predefined keys for working with text |object-motions|. 73This filetype plugin attempts to translate these keys to maps which make sense 74for the SQL language. 75 76The following |Normal| mode and |Visual| mode maps exist (when you edit a SQL 77file): > 78 ]] move forward to the next 'begin' 79 [[ move backwards to the previous 'begin' 80 ][ move forward to the next 'end' 81 [] move backwards to the previous 'end' 82 83 84------------------------------------------------------------------------------ 851.3 Predefined Object Motions *sql-predefined-objects* 86 87Most relational databases support various standard features, tables, indices, 88triggers and stored procedures. Each vendor also has a variety of proprietary 89objects. The next set of maps have been created to help move between these 90objects. Depends on which database vendor you are using, the list of objects 91must be configurable. The filetype plugin attempts to define many of the 92standard objects, plus many additional ones. In order to make this as 93flexible as possible, you can override the list of objects from within your 94|vimrc| with the following: > 95 let g:ftplugin_sql_objects = 'function,procedure,event,table,trigger' .. 96 \ ',schema,service,publication,database,datatype,domain' .. 97 \ ',index,subscription,synchronization,view,variable' 98 99The following |Normal| mode and |Visual| mode maps have been created which use 100the above list: > 101 ]} move forward to the next 'create <object name>' 102 [{ move backward to the previous 'create <object name>' 103 104Repeatedly pressing ]} will cycle through each of these create statements: > 105 create table t1 ( 106 ... 107 ); 108 109 create procedure p1 110 begin 111 ... 112 end; 113 114 create index i1 on t1 (c1); 115 116The default setting for g:ftplugin_sql_objects is: > 117 let g:ftplugin_sql_objects = 'function,procedure,event,' .. 118 \ '\\(existing\\\\|global\\s\\+temporary\\s\\+\\)\\\{,1}' .. 119 \ 'table,trigger' .. 120 \ ',schema,service,publication,database,datatype,domain' .. 121 \ ',index,subscription,synchronization,view,variable' 122 123The above will also handle these cases: > 124 create table t1 ( 125 ... 126 ); 127 create existing table t2 ( 128 ... 129 ); 130 create global temporary table t3 ( 131 ... 132 ); 133 134By default, the ftplugin only searches for CREATE statements. You can also 135override this via your |init.vim| with the following: > 136 let g:ftplugin_sql_statements = 'create,alter' 137 138The filetype plugin defines three types of comments: > 139 1. -- 140 2. // 141 3. /* 142 * 143 */ 144 145The following |Normal| mode and |Visual| mode maps have been created to work 146with comments: > 147 ]" move forward to the beginning of a comment 148 [" move forward to the end of a comment 149 150 151 152------------------------------------------------------------------------------ 1531.4 Macros *sql-macros* 154 155Vim's feature to find macro definitions, 'define', is supported using this 156regular expression: > 157 \c\<\(VARIABLE\|DECLARE\|IN\|OUT\|INOUT\)\> 158 159This addresses the following code: > 160 CREATE VARIABLE myVar1 INTEGER; 161 162 CREATE PROCEDURE sp_test( 163 IN myVar2 INTEGER, 164 OUT myVar3 CHAR(30), 165 INOUT myVar4 NUMERIC(20,0) 166 ) 167 BEGIN 168 DECLARE myVar5 INTEGER; 169 170 SELECT c1, c2, c3 171 INTO myVar2, myVar3, myVar4 172 FROM T1 173 WHERE c4 = myVar1; 174 END; 175 176Place your cursor on "myVar1" on this line: > 177 WHERE c4 = myVar1; 178 ^ 179 180Press any of the following keys: > 181 [d 182 [D 183 [CTRL-D 184 185 186============================================================================== 1872. SQL Dialects *sql-dialects* *sql-types* 188 *sybase* *TSQL* *Transact-SQL* 189 *sqlanywhere* 190 *oracle* *plsql* *sqlj* 191 *sqlserver* 192 *mysql* *postgresql* *psql* 193 *informix* 194 195All relational databases support SQL. There is a portion of SQL that is 196portable across vendors (ex. CREATE TABLE, CREATE INDEX), but there is a 197great deal of vendor specific extensions to SQL. Oracle supports the 198"CREATE OR REPLACE" syntax, column defaults specified in the CREATE TABLE 199statement and the procedural language (for stored procedures and triggers). 200 201The default Vim distribution ships with syntax highlighting based on Oracle's 202PL/SQL. The default SQL indent script works for Oracle and SQL Anywhere. 203The default filetype plugin works for all vendors and should remain vendor 204neutral, but extendable. 205 206Vim currently has support for a variety of different vendors, currently this 207is via syntax scripts. Unfortunately, to flip between different syntax rules 208you must either create: 209 1. New filetypes 210 2. Custom autocmds 211 3. Manual steps / commands 212 213The majority of people work with only one vendor's database product, it would 214be nice to specify a default in your |init.vim|. 215 216 217------------------------------------------------------------------------------ 2182.1 SQLSetType *sqlsettype* *SQLSetType* 219 220For the people that work with many different databases, it is nice to be 221able to flip between the various vendors rules (indent, syntax) on a per 222buffer basis, at any time. The ftplugin/sql.vim file defines this function: > 223 SQLSetType 224 225Executing this function without any parameters will set the indent and syntax 226scripts back to their defaults, see |sql-type-default|. You can use the <Tab> 227key to complete the optional parameter. 228 229After typing the function name and a space, you can use the completion to 230supply a parameter. The function takes the name of the Vim script you want to 231source. Using the |cmdline-completion| feature, the SQLSetType function will 232search the 'runtimepath' for all Vim scripts with a name containing "sql". 233This takes the guess work out of the spelling of the names. The following are 234examples: > 235 :SQLSetType 236 :SQLSetType sqloracle 237 :SQLSetType sqlanywhere 238 :SQLSetType sqlinformix 239 :SQLSetType mysql 240 241The easiest approach is to the use <Tab> character which will first complete 242the command name (SQLSetType), after a space and another <Tab>, display a list 243of available Vim script names: > 244 :SQL<Tab><space><Tab> 245 246 247------------------------------------------------------------------------------ 2482.2 SQLGetType *sqlgettype* *SQLGetType* 249 250At anytime you can determine which SQL dialect you are using by calling the 251SQLGetType command. The ftplugin/sql.vim file defines this function: > 252 SQLGetType 253 254This will echo: > 255 Current SQL dialect in use:sqlanywhere 256 257 258------------------------------------------------------------------------------ 2592.3 SQL Dialect Default *sql-type-default* 260 261As mentioned earlier, the default syntax rules for Vim is based on Oracle 262(PL/SQL). You can override this default by placing one of the following in 263your |init.vim|: > 264 let g:sql_type_default = 'sqlanywhere' 265 let g:sql_type_default = 'sqlinformix' 266 let g:sql_type_default = 'mysql' 267 268If you added the following to your |init.vim|: > 269 let g:sql_type_default = 'sqlinformix' 270 271The next time edit a SQL file the following scripts will be automatically 272loaded by Vim: > 273 ftplugin/sql.vim 274 syntax/sqlinformix.vim 275 indent/sql.vim 276< 277Notice indent/sqlinformix.sql was not loaded. There is no indent file 278for Informix, Vim loads the default files if the specified files does not 279exist. 280 281 282============================================================================== 2833. Adding new SQL Dialects *sql-adding-dialects* 284 285If you begin working with a SQL dialect which does not have any customizations 286available with the default Vim distribution you can check https://www.vim.org 287to see if any customization currently exist. If not, you can begin by cloning 288an existing script. Read |filetype-plugins| for more details. 289 290To help identify these scripts, try to create the files with a "sql" prefix. 291If you decide you wish to create customizations for the SQLite database, you 292can create any of the following: > 293 Unix 294 ~/.config/nvim/syntax/sqlite.vim 295 ~/.config/nvim/indent/sqlite.vim 296 297No changes are necessary to the SQLSetType function. It will automatically 298pick up the new SQL files and load them when you issue the SQLSetType command. 299 300 301============================================================================== 3024. OMNI SQL Completion *sql-completion* 303 *omni-sql-completion* 304 305Vim 7 includes a code completion interface and functions which allows plugin 306developers to build in code completion for any language. Vim 7 includes 307code completion for the SQL language. 308 309There are two modes to the SQL completion plugin, static and dynamic. The 310static mode populates the popups with the data generated from current syntax 311highlight rules. The dynamic mode populates the popups with data retrieved 312directly from a database. This includes, table lists, column lists, 313procedures names and more. 314 315------------------------------------------------------------------------------ 3164.1 Static Mode *sql-completion-static* 317 318The static popups created contain items defined by the active syntax rules 319while editing a file with a filetype of SQL. The plugin defines (by default) 320various maps to help the user refine the list of items to be displayed. 321The defaults static maps are: > 322 imap <buffer> <C-C>a <C-\><C-O>:call sqlcomplete#Map('syntax')<CR><C-X><C-O> 323 imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword')<CR><C-X><C-O> 324 imap <buffer> <C-C>f <C-\><C-O>:call sqlcomplete#Map('sqlFunction')<CR><C-X><C-O> 325 imap <buffer> <C-C>o <C-\><C-O>:call sqlcomplete#Map('sqlOption')<CR><C-X><C-O> 326 imap <buffer> <C-C>T <C-\><C-O>:call sqlcomplete#Map('sqlType')<CR><C-X><C-O> 327 imap <buffer> <C-C>s <C-\><C-O>:call sqlcomplete#Map('sqlStatement')<CR><C-X><C-O> 328 329The use of "<C-C>" can be user chosen by using the following in your |init.vim| 330as it may not work properly on all platforms: > 331 let g:ftplugin_sql_omni_key = '<C-C>' 332< 333The static maps (which are based on the syntax highlight groups) follow this 334format: > 335 imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword')<CR><C-X><C-O> 336 imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword\w*')<CR><C-X><C-O> 337 338This command breaks down as: > 339 imap - Create an insert map 340 <buffer> - Only for this buffer 341 <C-C>k - Your choice of key map 342 <C-\><C-O> - Execute one command, return to Insert mode 343 :call sqlcomplete#Map( - Allows the SQL completion plugin to perform some 344 housekeeping functions to allow it to be used in 345 conjunction with other completion plugins. 346 Indicate which item you want the SQL completion 347 plugin to complete. 348 In this case we are asking the plugin to display 349 items from the syntax highlight group 350 'sqlKeyword'. 351 You can view a list of highlight group names to 352 choose from by executing the 353 :syntax list 354 command while editing a SQL file. 355 'sqlKeyword' - Display the items for the sqlKeyword highlight 356 group 357 'sqlKeyword\w*' - A second option available with Vim 7.4 which 358 uses a regular expression to determine which 359 syntax groups to use 360 )<CR> - Execute the :let command 361 <C-X><C-O> - Trigger the standard omni completion key stroke. 362 Passing in 'sqlKeyword' instructs the SQL 363 completion plugin to populate the popup with 364 items from the sqlKeyword highlight group. The 365 plugin will also cache this result until Vim is 366 restarted. The syntax list is retrieved using 367 the syntaxcomplete plugin. 368 369Using the 'syntax' keyword is a special case. This instructs the 370syntaxcomplete plugin to retrieve all syntax items. So this will effectively 371work for any of Vim's SQL syntax files. At the time of writing this includes 37210 different syntax files for the different dialects of SQL (see section 3 373above, |sql-dialects|). 374 375Here are some examples of the entries which are pulled from the syntax files: > 376 All 377 - Contains the contents of all syntax highlight groups 378 Statements 379 - Select, Insert, Update, Delete, Create, Alter, ... 380 Functions 381 - Min, Max, Trim, Round, Date, ... 382 Keywords 383 - Index, Database, Having, Group, With 384 Options 385 - Isolation_level, On_error, Qualify_owners, Fire_triggers, ... 386 Types 387 - Integer, Char, Varchar, Date, DateTime, Timestamp, ... 388 389 390------------------------------------------------------------------------------ 3914.2 Dynamic Mode *sql-completion-dynamic* 392 393Dynamic mode populates the popups with data directly from a database. In 394order for the dynamic feature to be enabled you must have the dbext.vim 395plugin installed, (https://www.vim.org/scripts/script.php?script_id=356). 396 397Dynamic mode is used by several features of the SQL completion plugin. 398After installing the dbext plugin see the dbext-tutorial for additional 399configuration and usage. The dbext plugin allows the SQL completion plugin 400to display a list of tables, procedures, views and columns. > 401 Table List 402 - All tables for all schema owners 403 Procedure List 404 - All stored procedures for all schema owners 405 View List 406 - All stored procedures for all schema owners 407 Column List 408 - For the selected table, the columns that are part of the table 409 410To enable the popup, while in INSERT mode, use the following key combinations 411for each group (where <C-C> means hold the CTRL key down while pressing 412the space bar): 413 Table List - <C-C>t 414 - <C-X><C-O> (the default map assumes tables) 415 Stored Procedure List - <C-C>p 416 View List - <C-C>v 417 Column List - <C-C>c 418 419 Drilling In / Out - When viewing a popup window displaying the list 420 of tables, you can press <Right>, this will 421 replace the table currently highlighted with 422 the column list for that table. 423 - When viewing a popup window displaying the list 424 of columns, you can press <Left>, this will 425 replace the column list with the list of tables. 426 - This allows you to quickly drill down into a 427 table to view its columns and back again. 428 - <Right> and <Left> can also be chosen via 429 your |init.vim| > 430 let g:ftplugin_sql_omni_key_right = '<Right>' 431 let g:ftplugin_sql_omni_key_left = '<Left>' 432 433The SQL completion plugin caches various lists that are displayed in 434the popup window. This makes the re-displaying of these lists very 435fast. If new tables or columns are added to the database it may become 436necessary to clear the plugins cache. The default map for this is: > 437 imap <buffer> <C-C>R <C-\><C-O>:call sqlcomplete#Map('ResetCache')<CR><C-X><C-O> 438 439 440------------------------------------------------------------------------------ 4414.3 SQL Tutorial *sql-completion-tutorial* 442 443This tutorial is designed to take you through the common features of the SQL 444completion plugin so that: > 445 a) You gain familiarity with the plugin 446 b) You are introduced to some of the more common features 447 c) Show how to customize it to your preferences 448 d) Demonstrate "Best of Use" of the plugin (easiest way to configure). 449 450First, create a new buffer: > 451 :e tutorial.sql 452 453 454Static features ~ 455 456To take you through the various lists, simply enter insert mode, hit: 457 <C-C>s (show SQL statements) 458At this point, you can page down through the list until you find "select". 459If you are familiar with the item you are looking for, for example you know 460the statement begins with the letter "s". You can type ahead (without the 461quotes) "se" then press: 462 <C-Space>t 463Assuming "select" is highlighted in the popup list press <Enter> to choose 464the entry. Now type: 465 * fr<C-C>a (show all syntax items) 466choose "from" from the popup list. 467 468When writing stored procedures using the "type" list is useful. It contains 469a list of all the database supported types. This may or may not be true 470depending on the syntax file you are using. The SQL Anywhere syntax file 471(sqlanywhere.vim) has support for this: > 472 BEGIN 473 DECLARE customer_id <C-C>T <-- Choose a type from the list 474 475 476Dynamic features ~ 477 478To take advantage of the dynamic features you must first install the 479dbext.vim plugin (https://www.vim.org/scripts/script.php?script_id=356). It 480also comes with a tutorial. From the SQL completion plugin's perspective, 481the main feature dbext provides is a connection to a database. dbext 482connection profiles are the most efficient mechanism to define connection 483information. Once connections have been setup, the SQL completion plugin 484uses the features of dbext in the background to populate the popups. 485 486What follows assumes dbext.vim has been correctly configured, a simple test 487is to run the command, :DBListTable. If a list of tables is shown, you know 488dbext.vim is working as expected. If not, please consult the dbext.txt 489documentation. 490 491Assuming you have followed the dbext-tutorial you can press <C-C>t to 492display a list of tables. There is a delay while dbext is creating the table 493list. After the list is displayed press <C-W>. This will remove both the 494popup window and the table name already chosen when the list became active. 495 496 4.3.1 Table Completion: *sql-completion-tables* 497 498Press <C-C>t to display a list of tables from within the database you 499have connected via the dbext plugin. 500NOTE: All of the SQL completion popups support typing a prefix before pressing 501the key map. This will limit the contents of the popup window to just items 502beginning with those characters. 503 504 4.3.2 Column Completion: *sql-completion-columns* 505 506The SQL completion plugin can also display a list of columns for particular 507tables. The column completion is triggered via <C-C>c. 508 509NOTE: The following example uses <Right> to trigger a column list while 510 the popup window is active. 511 512Example of using column completion: 513 - Press <C-C>t again to display the list of tables. 514 - When the list is displayed in the completion window, press <Right>, 515 this will replace the list of tables, with a list of columns for the 516 table highlighted (after the same short delay). 517 - If you press <Left>, this will again replace the column list with the 518 list of tables. This allows you to drill into tables and column lists 519 very quickly. 520 - Press <Right> again while the same table is highlighted. You will 521 notice there is no delay since the column list has been cached. If you 522 change the schema of a cached table you can press <C-C>R, which 523 clears the SQL completion cache. 524 - NOTE: <Right> and <Left> have been designed to work while the 525 completion window is active. If the completion popup window is 526 not active, a normal <Right> or <Left> will be executed. 527 528Let's look at how we can build a SQL statement dynamically. A select statement 529requires a list of columns. There are two ways to build a column list using 530the SQL completion plugin. > 531 One column at a time: 532< 1. After typing SELECT press <C-C>t to display a list of tables. 533 2. Choose a table from the list. 534 3. Press <Right> to display a list of columns. 535 4. Choose the column from the list and press enter. 536 5. Enter a "," and press <C-C>c. Generating a column list 537 generally requires having the cursor on a table name. The plugin 538 uses this name to determine what table to retrieve the column list. 539 In this step, since we are pressing <C-C>c without the cursor 540 on a table name the column list displayed will be for the previous 541 table. Choose a different column and move on. 542 6. Repeat step 5 as often as necessary. > 543 All columns for a table: 544< 1. After typing SELECT press <C-C>t to display a list of tables. 545 2. Highlight the table you need the column list for. 546 3. Press <Enter> to choose the table from the list. 547 4. Press <C-C>l to request a comma-separated list of all columns 548 for this table. 549 5. Based on the table name chosen in step 3, the plugin attempts to 550 decide on a reasonable table alias. You are then prompted to 551 either accept of change the alias. Press OK. 552 6. The table name is replaced with the column list of the table is 553 replaced with the comma separate list of columns with the alias 554 prepended to each of the columns. 555 7. Step 3 and 4 can be replaced by pressing <C-C>L, which has 556 a <C-Y> embedded in the map to choose the currently highlighted 557 table in the list. 558 559There is a special provision when writing select statements. Consider the 560following statement: > 561 select * 562 from customer c, 563 contact cn, 564 department as dp, 565 employee e, 566 site_options so 567 where c. 568 569In INSERT mode after typing the final "c." which is an alias for the 570"customer" table, you can press either <C-C>c or <C-X><C-O>. This will 571popup a list of columns for the customer table. It does this by looking back 572to the beginning of the select statement and finding a list of the tables 573specified in the FROM clause. In this case it notes that in the string 574"customer c", "c" is an alias for the customer table. The optional "AS" 575keyword is also supported, "customer AS c". 576 577 578 4.3.3 Procedure Completion: *sql-completion-procedures* 579 580Similar to the table list, <C-C>p, will display a list of stored 581procedures stored within the database. 582 583 4.3.4 View Completion: *sql-completion-views* 584 585Similar to the table list, <C-C>v, will display a list of views in the 586database. 587 588 589------------------------------------------------------------------------------ 5904.4 Completion Customization *sql-completion-customization* 591 592The SQL completion plugin can be customized through various options set in 593your |init.vim|: > 594 omni_sql_no_default_maps 595< - Default: This variable is not defined 596 - If this variable is defined, no maps are created for OMNI 597 completion. See |sql-completion-maps| for further discussion. 598> 599 omni_sql_use_tbl_alias 600< - Default: a 601 - This setting is only used when generating a comma-separated 602 column list. By default the map is <C-C>l. When generating 603 a column list, an alias can be prepended to the beginning of each 604 column, for example: e.emp_id, e.emp_name. This option has three 605 settings: > 606 n - do not use an alias 607 d - use the default (calculated) alias 608 a - ask to confirm the alias name 609< 610 An alias is determined following a few rules: 611 1. If the table name has an '_', then use it as a separator: > 612 MY_TABLE_NAME --> MTN 613 my_table_name --> mtn 614 My_table_NAME --> MtN 615< 2. If the table name does NOT contain an '_', but DOES use 616 mixed case then the case is used as a separator: > 617 MyTableName --> MTN 618< 3. If the table name does NOT contain an '_', and does NOT 619 use mixed case then the first letter of the table is used: > 620 mytablename --> m 621 MYTABLENAME --> M 622 623 omni_sql_ignorecase 624< - Default: Current setting for 'ignorecase' 625 - Valid settings are 0 or 1. 626 - When entering a few letters before initiating completion, the list 627 will be filtered to display only the entries which begin with the 628 list of characters. When this option is set to 0, the list will be 629 filtered using case sensitivity. > 630 631 omni_sql_include_owner 632< - Default: 0, unless dbext.vim 3.00 has been installed 633 - Valid settings are 0 or 1. 634 - When completing tables, procedure or views and using dbext.vim 3.00 635 or higher the list of objects will also include the owner name. 636 When completing these objects and omni_sql_include_owner is enabled 637 the owner name will be replaced. > 638 639 omni_sql_precache_syntax_groups 640< - Default: 641 ['syntax','sqlKeyword','sqlFunction','sqlOption','sqlType','sqlStatement'] 642 - sqlcomplete can be used in conjunction with other completion 643 plugins. This is outlined at |sql-completion-filetypes|. When the 644 filetype is changed temporarily to SQL, the sqlcompletion plugin 645 will cache the syntax groups listed in the List specified in this 646 option. 647 648 649------------------------------------------------------------------------------ 6504.5 SQL Maps *sql-completion-maps* 651 652The default SQL maps have been described in other sections of this document in 653greater detail. Here is a list of the maps with a brief description of each. 654 655Static Maps ~ 656 657These are maps which use populate the completion list using Vim's syntax 658highlighting rules. > 659 <C-C>a 660< - Displays all SQL syntax items. > 661 <C-C>k 662< - Displays all SQL syntax items defined as 'sqlKeyword'. > 663 <C-C>f 664< - Displays all SQL syntax items defined as 'sqlFunction. > 665 <C-C>o 666< - Displays all SQL syntax items defined as 'sqlOption'. > 667 <C-C>T 668< - Displays all SQL syntax items defined as 'sqlType'. > 669 <C-C>s 670< - Displays all SQL syntax items defined as 'sqlStatement'. > 671 672Dynamic Maps ~ 673 674These are maps which use populate the completion list using the dbext.vim 675plugin. > 676 <C-C>t 677< - Displays a list of tables. > 678 <C-C>p 679< - Displays a list of procedures. > 680 <C-C>v 681< - Displays a list of views. > 682 <C-C>c 683< - Displays a list of columns for a specific table. > 684 <C-C>l 685< - Displays a comma-separated list of columns for a specific table. > 686 <C-C>L 687< - Displays a comma-separated list of columns for a specific table. 688 This should only be used when the completion window is active. > 689 <Right> 690< - Displays a list of columns for the table currently highlighted in 691 the completion window. <Right> is not recognized on most Unix 692 systems, so this maps is only created on the Windows platform. 693 If you would like the same feature on Unix, choose a different key 694 and make the same map in your vimrc. > 695 <Left> 696< - Displays the list of tables. 697 <Left> is not recognized on most Unix systems, so this maps is 698 only created on the Windows platform. If you would like the same 699 feature on Unix, choose a different key and make the same map in 700 your vimrc. > 701 <C-C>R 702< - This maps removes all cached items and forces the SQL completion 703 to regenerate the list of items. 704 705Customizing Maps ~ 706 707You can create as many additional key maps as you like. Generally, the maps 708will be specifying different syntax highlight groups. 709 710If you do not wish the default maps created or the key choices do not work on 711your platform (often a case on unix) you define the following variable in 712your |init.vim|: > 713 let g:omni_sql_no_default_maps = 1 714 715Do not edit ftplugin/sql.vim directly! If you change this file your changes 716will be over written on future updates. Vim has a special directory structure 717which allows you to make customizations without changing the files that are 718included with the Vim distribution. If you wish to customize the maps 719create an after/ftplugin/sql.vim (see |after-directory|) and place the same 720maps from the ftplugin/sql.vim in it using your own key strokes. <C-C> was 721chosen since it will work on both Windows and unix platforms. On the windows 722platform you can also use <C-Space> or ALT keys. 723 724 725------------------------------------------------------------------------------ 7264.6 Using with other filetypes *sql-completion-filetypes* 727 728Many times SQL can be used with different filetypes. For example Perl, Java, 729PHP, Javascript can all interact with a database. Often you need both the SQL 730completion and the completion capabilities for the current language you are 731editing. 732 733This can be enabled easily with the following steps (assuming a Perl file): > 734 1. :e test.pl 735 2. :set filetype=sql 736 3. :set ft=perl 737 738Step 1 ~ 739 740Begins by editing a Perl file. Vim automatically sets the filetype to 741"perl". By default, Vim runs the appropriate filetype file 742ftplugin/perl.vim. If you are using the syntax completion plugin by following 743the directions at |ft-syntax-omni| then the 'omnifunc' option has been set to 744"syntax#Complete". Pressing <C-X><C-O> will display the omni popup containing 745the syntax items for Perl. 746 747Step 2 ~ 748 749Manually setting the filetype to "sql" will also fire the appropriate filetype 750files ftplugin/sql.vim. This file will define a number of buffer specific 751maps for SQL completion, see |sql-completion-maps|. Now these maps have 752been created and the SQL completion plugin has been initialized. All SQL 753syntax items have been cached in preparation. The SQL filetype script detects 754we are attempting to use two different completion plugins. Since the SQL maps 755begin with <C-C>, the maps will toggle the 'omnifunc' when in use. So you 756can use <C-X><C-O> to continue using the completion for Perl (using the syntax 757completion plugin) and <C-C> to use the SQL completion features. 758 759Step 3 ~ 760 761Setting the filetype back to Perl sets all the usual "perl" related items back 762as they were. 763 764 765vim:tw=78:ts=8:noet:ft=help:norl: