Mercurial > vim
comparison runtime/doc/sql.txt @ 819:23f82b5d2814 v7.0c10
updated for version 7.0c10
author | vimboss |
---|---|
date | Wed, 05 Apr 2006 20:41:53 +0000 |
parents | 1f929f3ca806 |
children | 6675076019ae |
comparison
equal
deleted
inserted
replaced
818:1f929f3ca806 | 819:23f82b5d2814 |
---|---|
1 *sql.txt* For Vim version 7.0c. Last change: Tue Mar 28 2006 9:33:14 PM | 1 *sql.txt* For Vim version 7.0c. Last change: Mon Apr 03 2006 10:34:00 PM |
2 | 2 |
3 by David Fishburn | 3 by David Fishburn |
4 | 4 |
5 This is a filetype plugin to work with SQL files. | 5 This is a filetype plugin to work with SQL files. |
6 | 6 |
24 4.3.1 Complete Tables |sql-completion-tables| | 24 4.3.1 Complete Tables |sql-completion-tables| |
25 4.3.2 Complete Columns |sql-completion-columns| | 25 4.3.2 Complete Columns |sql-completion-columns| |
26 4.3.3 Complete Procedures |sql-completion-procedures| | 26 4.3.3 Complete Procedures |sql-completion-procedures| |
27 4.3.4 Complete Views |sql-completion-views| | 27 4.3.4 Complete Views |sql-completion-views| |
28 4.4 Completion Customization |sql-completion-customization| | 28 4.4 Completion Customization |sql-completion-customization| |
29 4.5 Customizing Maps |sql-completion-maps| | 29 4.5 SQL Maps |sql-completion-maps| |
30 4.6 Using with other filetypes |sql-completion-filetypes| | |
30 | 31 |
31 ============================================================================== | 32 ============================================================================== |
32 1. Navigation *sql-navigation* | 33 1. Navigation *sql-navigation* |
33 | 34 |
34 The SQL ftplugin provides a number of options to assist with file | 35 The SQL ftplugin provides a number of options to assist with file |
319 | 320 |
320 4.1 Static Mode *sql-completion-static* | 321 4.1 Static Mode *sql-completion-static* |
321 --------------- | 322 --------------- |
322 The static popups created contain items defined by the active syntax rules | 323 The static popups created contain items defined by the active syntax rules |
323 while editing a file with a filetype of SQL. The plugin defines (by default) | 324 while editing a file with a filetype of SQL. The plugin defines (by default) |
324 various maps to help the user refine which list of items they wish displayed. | 325 various maps to help the user refine the list of items to be displayed. |
325 The defaults static maps are: > | 326 The defaults static maps are: > |
326 imap <buffer> <C-C>a <C-\><C-O>:let b:sql_compl_type='syntax'<CR><C-X><C-O> | 327 imap <buffer> <C-C>a <C-\><C-O>:call sqlcomplete#Map('syntax')<CR><C-X><C-O> |
327 imap <buffer> <C-C>s <C-\><C-O>:let b:sql_compl_type='sqlStatement'<CR><C-X><C-O> | 328 imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword')<CR><C-X><C-O> |
328 imap <buffer> <C-C>f <C-\><C-O>:let b:sql_compl_type='sqlFunction'<CR><C-X><C-O> | 329 imap <buffer> <C-C>f <C-\><C-O>:call sqlcomplete#Map('sqlFunction')<CR><C-X><C-O> |
329 imap <buffer> <C-C>k <C-\><C-O>:let b:sql_compl_type='sqlKeyword'<CR><C-X><C-O> | 330 imap <buffer> <C-C>o <C-\><C-O>:call sqlcomplete#Map('sqlOption')<CR><C-X><C-O> |
330 imap <buffer> <C-C>o <C-\><C-O>:let b:sql_compl_type='sqlOption'<CR><C-X><C-O> | 331 imap <buffer> <C-C>T <C-\><C-O>:call sqlcomplete#Map('sqlType')<CR><C-X><C-O> |
331 imap <buffer> <C-C>T <C-\><C-O>:let b:sql_compl_type='sqlType'<CR><C-X><C-O> | 332 imap <buffer> <C-C>s <C-\><C-O>:call sqlcomplete#Map('sqlStatement')<CR><C-X><C-O> |
332 < | 333 < |
333 The static maps (which are based on the syntax highlight groups) follow this | 334 The static maps (which are based on the syntax highlight groups) follow this |
334 format: > | 335 format: > |
335 imap <buffer> <C-C>k <C-\><C-O>:let b:sql_compl_type='sqlKeyword'<CR><C-X><C-O> | 336 imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword')<CR><C-X><C-O> |
336 < | 337 < |
337 This command breaks down as: > | 338 This command breaks down as: > |
338 imap - Create an insert map | 339 imap - Create an insert map |
339 <buffer> - Only for this buffer | 340 <buffer> - Only for this buffer |
340 <C-C>k - Your choice of key map | 341 <C-C>k - Your choice of key map |
341 <C-\><C-O> - Execute one command, return to Insert mode | 342 <C-\><C-O> - Execute one command, return to Insert mode |
342 :let b:sql_compl_type= - Choose the highlight group's entries to display. | 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'. | |
343 You can view a list of highlight group names to | 351 You can view a list of highlight group names to |
344 choose from by executing the | 352 choose from by executing the |
345 :syntax list | 353 :syntax list |
346 command while editing a SQL file. | 354 command while editing a SQL file. |
347 'sqlKeyword' - Display the items for the sqlKeyword highlight | 355 'sqlKeyword' - Display the items for the sqlKeyword highlight |
348 group | 356 group |
349 <CR> - Execute the :let command | 357 )<CR> - Execute the :let command |
350 <C-X><C-O> - Trigger the standard omni completion key stroke. | 358 <C-X><C-O> - Trigger the standard omni completion key stroke. |
351 By setting the b:sql_compl_type variable, this | 359 Passing in 'sqlKeyword' instructs the SQL |
352 instructs the SQL completion plugin to populate | 360 completion plugin to populate the popup with |
353 the popup with items from the sqlKeyword highlight | 361 items from the sqlKeyword highlight group. The |
354 group. The plugin will also cache this result | 362 plugin will also cache this result until Vim is |
355 until Vim is restarted. The syntax list is | 363 restarted. The syntax list is retrieved using |
356 retrieved using the syntaxcomplete plugin. | 364 the syntaxcomplete plugin. |
357 < | 365 < |
358 Setting b:sql_compl_type = 'syntax' is a special case. This instructs the | 366 Using the 'syntax' keyword is a special case. This instructs the |
359 syntaxcomplete plugin to retrieve all syntax items. So this will effectively | 367 syntaxcomplete plugin to retrieve all syntax items. So this will effectively |
360 work for any of Vim's SQL syntax files. At the time of writing this includes | 368 work for any of Vim's SQL syntax files. At the time of writing this includes |
361 10 different syntax files for the different dialects of SQL (see section 3 | 369 10 different syntax files for the different dialects of SQL (see section 3 |
362 above, |sql-dialects|). | 370 above, |sql-dialects|). |
363 | 371 |
381 Dynamic mode populates the popups with data directly from a database. In | 389 Dynamic mode populates the popups with data directly from a database. In |
382 order for the dynamic feature to be enabled you must have the dbext.vim | 390 order for the dynamic feature to be enabled you must have the dbext.vim |
383 plugin installed, (http://vim.sourceforge.net/script.php?script_id=356). | 391 plugin installed, (http://vim.sourceforge.net/script.php?script_id=356). |
384 | 392 |
385 Dynamic mode is used by several features of the SQL completion plugin. | 393 Dynamic mode is used by several features of the SQL completion plugin. |
386 After installing the dbext plugin see the |dbext-tutorial| for additional | 394 After installing the dbext plugin see the dbext-tutorial for additional |
387 configuration and usage. The dbext plugin allows the SQL completion plugin | 395 configuration and usage. The dbext plugin allows the SQL completion plugin |
388 to display a list of tables, procedures, views and columns. > | 396 to display a list of tables, procedures, views and columns. > |
389 Table List | 397 Table List |
390 - All tables for all schema owners | 398 - All tables for all schema owners |
391 Procedure List | 399 Procedure List |
401 Table List - <C-C>t | 409 Table List - <C-C>t |
402 - <C-X><C-O> (the default map assumes tables) | 410 - <C-X><C-O> (the default map assumes tables) |
403 Stored Procedure List - <C-C>p | 411 Stored Procedure List - <C-C>p |
404 View List - <C-C>v | 412 View List - <C-C>v |
405 Column List - <C-C>c | 413 Column List - <C-C>c |
406 - .<C-X><C-O> | 414 - Windows platform only |
407 - If <C-X><C-O> is pressed following a period | |
408 it is assumed you are asking for a column list. | |
409 - When viewing a popup window displaying the list | 415 - When viewing a popup window displaying the list |
410 of tables, you can press <C-Right>, this will | 416 of tables, you can press <C-Right>, this will |
411 replace the table currently highlighted with | 417 replace the table currently highlighted with |
412 the column list for that table. | 418 the column list for that table. |
413 - When viewing a popup window displaying the list | 419 - When viewing a popup window displaying the list |
416 | 422 |
417 The SQL completion plugin caches various lists that are displayed in | 423 The SQL completion plugin caches various lists that are displayed in |
418 the popup window. This makes the re-displaying of these lists very | 424 the popup window. This makes the re-displaying of these lists very |
419 fast. If new tables or columns are added to the database it may become | 425 fast. If new tables or columns are added to the database it may become |
420 necessary to clear the plugins cache. The default map for this is: > | 426 necessary to clear the plugins cache. The default map for this is: > |
421 imap <buffer> <C-C>R <C-O>:let b:sql_compl_type='ResetCache'<CR><C-X><C-O> | 427 imap <buffer> <C-C>R <C-\><C-O>:call sqlcomplete#Map('ResetCache')<CR><C-X><C-O> |
422 < | 428 < |
423 | 429 |
424 4.3 SQL Tutorial *sql-completion-tutorial* | 430 4.3 SQL Tutorial *sql-completion-tutorial* |
425 ---------------- | 431 ---------------- |
426 | 432 |
470 What follows assumes dbext.vim has been correctly configured, a simple test | 476 What follows assumes dbext.vim has been correctly configured, a simple test |
471 is to run the command, :DBListTable. If a list of tables is shown, you know | 477 is to run the command, :DBListTable. If a list of tables is shown, you know |
472 dbext.vim is working as expected. If not, please consult the dbext.txt | 478 dbext.vim is working as expected. If not, please consult the dbext.txt |
473 documentation. | 479 documentation. |
474 | 480 |
475 Assuming you have followed the |dbext-tutorial| you can press <C-C>t to | 481 Assuming you have followed the dbext-tutorial you can press <C-C>t to |
476 display a list of tables. There is a delay while dbext is creating the table | 482 display a list of tables. There is a delay while dbext is creating the table |
477 list. After the list is displayed press <C-W>. This will remove both the | 483 list. After the list is displayed press <C-W>. This will remove both the |
478 popup window and the table name already chosen when the list became active. > | 484 popup window and the table name already chosen when the list became active. > |
479 | 485 |
480 4.3.1 Table Completion: *sql-completion-tables* | 486 4.3.1 Table Completion: *sql-completion-tables* |
494 the popup window is active. This map is only available on the Windows | 500 the popup window is active. This map is only available on the Windows |
495 platforms since *nix does not recognize CTRL and the right arrow held down | 501 platforms since *nix does not recognize CTRL and the right arrow held down |
496 together. If you wish to enable this functionality on a *nix platform choose | 502 together. If you wish to enable this functionality on a *nix platform choose |
497 a key and create this mapping (see |sql-completion-maps| for further | 503 a key and create this mapping (see |sql-completion-maps| for further |
498 details on where to create this imap): > | 504 details on where to create this imap): > |
499 imap <buffer> <your_keystroke> <CR><C-\><C-O>:let b:sql_compl_type='column'<CR><C-X><C-O> | 505 imap <buffer> <your_keystroke> <CR><C-\><C-O>:call sqlcomplete#Map('column')<CR><C-X><C-O> |
500 < | 506 < |
501 Example of using column completion: | 507 Example of using column completion: |
502 - Press <C-C>t again to display the list of tables. | 508 - Press <C-C>t again to display the list of tables. |
503 - When the list is displayed in the completion window, press <C-Right>, | 509 - When the list is displayed in the completion window, press <C-Right>, |
504 this will replace the list of tables, with a list of columns for the | 510 this will replace the list of tables, with a list of columns for the |
609 use mixed case then the first letter of the table is used: > | 615 use mixed case then the first letter of the table is used: > |
610 mytablename --> m | 616 mytablename --> m |
611 MYTABLENAME --> M | 617 MYTABLENAME --> M |
612 < | 618 < |
613 | 619 |
614 4.5 Customizing Maps *sql-completion-maps* | 620 4.5 SQL Maps *sql-completion-maps* |
615 -------------------- | 621 ------------ |
616 | 622 |
623 The default SQL maps have been described in other sections of this document in | |
624 greater detail. Here is a list of the maps with a brief description of each. | |
625 | |
626 Static Maps | |
627 ----------- | |
628 These are maps which use populate the completion list using Vim's syntax | |
629 highlighting rules. > | |
630 <C-C>a | |
631 < - Displays all SQL syntax items. > | |
632 <C-C>k | |
633 < - Displays all SQL syntax items defined as 'sqlKeyword'. > | |
634 <C-C>f | |
635 < - Displays all SQL syntax items defined as 'sqlFunction. > | |
636 <C-C>o | |
637 < - Displays all SQL syntax items defined as 'sqlOption'. > | |
638 <C-C>T | |
639 < - Displays all SQL syntax items defined as 'sqlType'. > | |
640 <C-C>s | |
641 < - Displays all SQL syntax items defined as 'sqlStatement'. > | |
642 | |
643 Dynamic Maps | |
644 ------------ | |
645 These are maps which use populate the completion list using the dbext.vim plugin. > | |
646 <C-C>t | |
647 < - Displays a list of tables. > | |
648 <C-C>p | |
649 < - Displays a list of procedures. > | |
650 <C-C>v | |
651 < - Displays a list of views. > | |
652 <C-C>c | |
653 < - Displays a list of columns for a specific table. > | |
654 <C-C>l | |
655 < - Displays a comma separated list of columns for a specific table. > | |
656 <C-C>L | |
657 < - Displays a comma separated list of columns for a specific table. | |
658 This should only be used when the completion window is active. > | |
659 <C-Right> | |
660 < - Displays a list of columns for the table currently highlighted in | |
661 the completion window. <C-Right> is not recognized on most Unix | |
662 systems, so this maps is only created on the Windows platform. | |
663 If you would like the same feature on Unix, choose a different key | |
664 and make the same map in your vimrc. | |
665 This should only be used when the completion window is active. > | |
666 <C-Left> | |
667 < - Displays the list of tables. | |
668 <C-Left> is not recognized on most Unix systems, so this maps is | |
669 only created on the Windows platform. If you would like the same | |
670 feature on Unix, choose a different key and make the same map in | |
671 your vimrc. | |
672 This should only be used when the completion window is active. > | |
673 <C-C>R | |
674 < - This maps removes all cached items and forces the SQL completion | |
675 to regenerate the list of items. | |
676 | |
677 Customizing Maps | |
678 ---------------- | |
617 You can create as many additional key maps as you like. Generally, the maps | 679 You can create as many additional key maps as you like. Generally, the maps |
618 will be specifying different syntax highlight groups. | 680 will be specifying different syntax highlight groups. |
619 | 681 |
620 If you do not wish the default maps created or the key choices do not work on | 682 If you do not wish the default maps created or the key choices do not work on |
621 your platform (often a case on *nix) you define the following variable in | 683 your platform (often a case on *nix) you define the following variable in |
622 your |vimrc|: > | 684 your |vimrc|: > |
623 let g:omni_sql_no_default_maps = 1 | 685 let g:omni_sql_no_default_maps = 1 |
624 < | 686 < |
625 Do no edit ftplugin/sql.vim directly! If you change this file your changes | 687 Do no edit ftplugin/sql.vim directly! If you change this file your changes |
626 will be over written on future updates. Vim has a special directory structure | 688 will be over written on future updates. Vim has a special directory structure |
627 that allows you to make customizations without changing the files that are | 689 which allows you to make customizations without changing the files that are |
628 included with the Vim distribution. If you wish to customize the maps | 690 included with the Vim distribution. If you wish to customize the maps |
629 create an after/ftplugin/sql.vim (see |after-directory|) and place the same | 691 create an after/ftplugin/sql.vim (see |after-directory|) and place the same |
630 maps from the ftplugin/sql.vim in it using your own key strokes. <C-C> was | 692 maps from the ftplugin/sql.vim in it using your own key strokes. <C-C> was |
631 chosen since it will work on both Windows and *nix platforms. On the windows | 693 chosen since it will work on both Windows and *nix platforms. On the windows |
632 platform you can also use <C-Space> or ALT keys. | 694 platform you can also use <C-Space> or ALT keys. |
633 | 695 |
634 | 696 |
697 4.6 Using with other filetypes *sql-completion-filetypes* | |
698 ------------------------------ | |
699 | |
700 Many times SQL can be used with different filetypes. For example Perl, Java, | |
701 PHP, Javascript can all interact with a database. Often you need both the SQL | |
702 completion as well as the completion capabilities for the current language you | |
703 are editing. | |
704 | |
705 This can be enabled easily with the following steps (assuming a Perl file): > | |
706 1. :e test.pl | |
707 2. :set filetype=sql | |
708 3. :set ft=perl | |
709 | |
710 Step 1 | |
711 ------ | |
712 Begins by editing a Perl file. Vim automatically sets the filetype to | |
713 "perl". By default, Vim runs the appropriate filetype file | |
714 ftplugin/perl.vim. If you are using the syntax completion plugin by following | |
715 the directions at |ft-syntax-omni| then the |'omnifunc'| option has been set to | |
716 "syntax#Complete". Pressing <C-X><C-O> will display the omni popup containing | |
717 the syntax items for Perl. | |
718 | |
719 Step 2 | |
720 ------ | |
721 Manually setting the filetype to 'sql' will also fire the appropriate filetype | |
722 files ftplugin/sql.vim. This file will define a number of buffer specific | |
723 maps for SQL completion, see |sql-completion-maps|. Now these maps have | |
724 been created and the SQL completion plugin has been initialized. All SQL | |
725 syntax items have been cached in preparation. The SQL filetype script detects | |
726 we are attempting to use two different completion plugins. Since the SQL maps | |
727 begin with <C-C>, the maps will toggle the |'omnifunc'| when in use. So you | |
728 can use <C-X><C-O> to continue using the completion for Perl (using the syntax | |
729 completion plugin) and <C-C> to use the SQL completion features. | |
730 | |
731 Step 3 | |
732 ------ | |
733 Setting the filetype back to Perl sets all the usual "perl" related items back | |
734 as they were. | |
735 | |
736 | |
635 vim:tw=78:ts=8:ft=help:norl: | 737 vim:tw=78:ts=8:ft=help:norl: |