Nvim :help
頁面,由 產生 自 原始碼,使用 tree-sitter-vimdoc 解析器。
if elseif | elsif else [if] end if [while condition] loop leave break continue exit end loop for leave break continue exit end loop do statements doend case when when default end case merge when not matched when matched create[ or replace] procedure|function|event returns
]] move forward to the next 'begin' [[ move backwards to the previous 'begin' ][ move forward to the next 'end' [] move backwards to the previous 'end'
let g:ftplugin_sql_objects = 'function,procedure,event,table,trigger' .. \ ',schema,service,publication,database,datatype,domain' .. \ ',index,subscription,synchronization,view,variable'已建立以下 Normal 模式和 Visual 模式對應,它們使用以上清單
]} move forward to the next 'create <object name>' [{ move backward to the previous 'create <object name>'重複按下 ]} 將會循環瀏覽每個這些 CREATE 語句
create table t1 ( ... ); create procedure p1 begin ... end; create index i1 on t1 (c1);g:ftplugin_sql_objects 的預設設定為
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'以上內容也將處理以下情況
create table t1 ( ... ); create existing table t2 ( ... ); create global temporary table t3 ( ... );預設情況下,ftplugin 僅搜尋 CREATE 語句。您也可以通過您的 init.vim 使用以下內容覆蓋此設定
let g:ftplugin_sql_statements = 'create,alter'檔案類型外掛程式定義了三種註解類型
1. -- 2. // 3. /* * */已建立以下 Normal 模式和 Visual 模式對應以處理註解
]" move forward to the beginning of a comment [" move forward to the end of a comment
\c\<\(VARIABLE\|DECLARE\|IN\|OUT\|INOUT\)\>這處理了以下程式碼
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;將游標放在此行上的 "myVar1" 上
WHERE c4 = myVar1; ^按下以下任何按鍵
[d [D [CTRL-D
SQLSetType執行此函數時不帶任何參數將會將縮排和語法腳本設定回其預設值,請參閱 sql-type-default。您可以使用
<Tab>
鍵來完成可選參數。:SQLSetType :SQLSetType sqloracle :SQLSetType sqlanywhere :SQLSetType sqlinformix :SQLSetType mysql最簡單的方法是使用
<Tab>
字元,它將首先完成命令名稱 (SQLSetType),在空格和另一個 <Tab>
後,顯示可用的 Vim 腳本名稱清單:SQL<Tab><space><Tab>
SQLGetType這將會回顯
Current SQL dialect in use:sqlanywhere
let g:sql_type_default = 'sqlanywhere' let g:sql_type_default = 'sqlinformix' let g:sql_type_default = 'mysql'如果您在您的 init.vim 中新增了以下內容
let g:sql_type_default = 'sqlinformix'下次編輯 SQL 檔案時,Vim 將會自動載入以下腳本
ftplugin/sql.vim syntax/sqlinformix.vim indent/sql.vim
Unix ~/.config/nvim/syntax/sqlite.vim ~/.config/nvim/indent/sqlite.vimSQLSetType 函數不需要任何變更。當您發出 SQLSetType 命令時,它將自動拾取新的 SQL 檔案並載入它們。
imap <buffer> <C-C>a <C-\><C-O>:call sqlcomplete#Map('syntax')<CR><C-X><C-O> imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword')<CR><C-X><C-O> imap <buffer> <C-C>f <C-\><C-O>:call sqlcomplete#Map('sqlFunction')<CR><C-X><C-O> imap <buffer> <C-C>o <C-\><C-O>:call sqlcomplete#Map('sqlOption')<CR><C-X><C-O> imap <buffer> <C-C>T <C-\><C-O>:call sqlcomplete#Map('sqlType')<CR><C-X><C-O> imap <buffer> <C-C>s <C-\><C-O>:call sqlcomplete#Map('sqlStatement')<CR><C-X><C-O>可以使用以下方式在您的 init.vim 中選擇使用者使用 "<C-C>",因為它可能無法在所有平台上正常運作
let g:ftplugin_sql_omni_key = '<C-C>'
imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword')<CR><C-X><C-O> imap <buffer> <C-C>k <C-\><C-O>:call sqlcomplete#Map('sqlKeyword\w*')<CR><C-X><C-O>此命令分解為
imap - Create an insert map <buffer> - Only for this buffer <C-C>k - Your choice of key map <C-\><C-O> - Execute one command, return to Insert mode :call sqlcomplete#Map( - Allows the SQL completion plugin to perform some housekeeping functions to allow it to be used in conjunction with other completion plugins. Indicate which item you want the SQL completion plugin to complete. In this case we are asking the plugin to display items from the syntax highlight group 'sqlKeyword'. You can view a list of highlight group names to choose from by executing the :syntax list command while editing a SQL file. 'sqlKeyword' - Display the items for the sqlKeyword highlight group 'sqlKeyword\w*' - A second option available with Vim 7.4 which uses a regular expression to determine which syntax groups to use )<CR> - Execute the :let command <C-X><C-O> - Trigger the standard omni completion key stroke. Passing in 'sqlKeyword' instructs the SQL completion plugin to populate the popup with items from the sqlKeyword highlight group. The plugin will also cache this result until Vim is restarted. The syntax list is retrieved using the syntaxcomplete plugin.使用 'syntax' 關鍵字是一種特殊情況。這指示 syntaxcomplete 外掛程式擷取所有語法項目。因此,這將有效地適用於任何 Vim 的 SQL 語法檔案。在撰寫本文時,這包括 10 個適用於不同 SQL 方言的語法檔案(請參閱上文第 3 節,sql-dialects)。
All - Contains the contents of all syntax highlight groups Statements - Select, Insert, Update, Delete, Create, Alter, ... Functions - Min, Max, Trim, Round, Date, ... Keywords - Index, Database, Having, Group, With Options - Isolation_level, On_error, Qualify_owners, Fire_triggers, ... Types - Integer, Char, Varchar, Date, DateTime, Timestamp, ...
Table List - All tables for all schema owners Procedure List - All stored procedures for all schema owners View List - All stored procedures for all schema owners Column List - For the selected table, the columns that are part of the table若要在「插入」模式下啟用彈出視窗,請針對每個群組使用以下按鍵組合(其中
<C-C>
表示在按下空白鍵的同時按住 CTRL 鍵):表格清單 - <C-C>
t<C-X>
<C-O>
(預設映射假設為表格) 預存程序清單 - <C-C>
p 檢視清單 - <C-C>
v 欄位清單 - <C-C>
c<Right>
,這會將目前反白的表格替換為該表格的欄位清單。<Left>
,這會將欄位清單替換為表格清單。<Right>
和 <Left>
let g:ftplugin_sql_omni_key_right = '<Right>' let g:ftplugin_sql_omni_key_left = '<Left>'SQL 自動完成外掛程式會快取彈出視窗中顯示的各種清單。這使得重新顯示這些清單的速度非常快。如果將新表格或欄位新增至資料庫,可能需要清除外掛程式快取。此操作的預設映射為
imap <buffer> <C-C>R <C-\><C-O>:call sqlcomplete#Map('ResetCache')<CR><C-X><C-O>------------------------------------------------------------------------------ 4.3 SQL 教學 sql-completion-tutorial
a) You gain familiarity with the plugin b) You are introduced to some of the more common features c) Show how to customize it to your preferences d) Demonstrate "Best of Use" of the plugin (easiest way to configure).首先,建立一個新的緩衝區
:e tutorial.sql
<C-C>
s (顯示 SQL 陳述式) 此時,您可以向下翻頁瀏覽清單,直到找到 "select"。如果您熟悉要尋找的項目,例如您知道該陳述式以字母 "s" 開頭。您可以預先輸入(不含引號)"se",然後按下:<C-Space>
t 假設 "select" 在彈出清單中反白顯示,請按下 <Enter>
以選擇該項目。現在輸入:* fr<C-C>
a (顯示所有語法項目) 從彈出清單中選擇 "from"。BEGIN DECLARE customer_id <C-C>T <-- Choose a type from the list
<C-C>
t 來顯示表格清單。dbext 建立表格清單時會有一段延遲。顯示清單後,按下 <C-W>
。這會移除彈出視窗和清單變成作用中時已選擇的表格名稱。<C-C>
t 以顯示您已透過 dbext 外掛程式連線之資料庫中的表格清單。注意:所有 SQL 自動完成彈出視窗都支援在按下按鍵映射之前輸入字首。這會將彈出視窗的內容限制為僅以這些字元開頭的項目。<C-C>
c 觸發的。<Right>
在彈出視窗處於作用中時觸發欄位清單。<C-C>
t 以顯示表格清單。<Right>
,這會將表格清單替換為反白顯示表格的欄位清單(在經過相同的短暫延遲後)。<Left>
,這會再次將欄位清單替換為表格清單。這讓您可以快速鑽研表格和欄位清單。<Right>
。您會注意到沒有延遲,因為欄位清單已快取。如果您變更快取表格的結構描述,您可以按下 <C-C>
R,這會清除 SQL 自動完成快取。<Right>
和 <Left>
設計為在自動完成視窗處於作用中時運作。如果自動完成彈出視窗未處於作用中,則會執行一般的 <Right>
或 <Left>
。One column at a time:
<C-C>
t 以顯示表格清單。2. 從清單中選擇一個表格。3. 按下 <Right>
以顯示欄位清單。4. 從清單中選擇欄位,然後按下 Enter。5. 輸入 "," 並按下 <C-C>
c。產生欄位清單通常需要在表格名稱上放置游標。外掛程式會使用此名稱來判斷要擷取哪個表格的欄位清單。在此步驟中,由於我們在游標不在表格名稱上時按下 <C-C>
c,因此顯示的欄位清單將是上一個表格的欄位清單。選擇不同的欄位並繼續。6. 根據需要經常重複步驟 5。All columns for a table:
<C-C>
t 以顯示表格清單。2. 反白顯示您需要欄位清單的表格。3. 按下 <Enter>
以從清單中選擇表格。4. 按下 <C-C>
l 以要求此表格的所有欄位的逗號分隔清單。5. 根據步驟 3 中選擇的表格名稱,外掛程式會嘗試決定合理的表格別名。然後,系統會提示您接受或變更別名。按下「確定」。6. 表格名稱會替換為表格的欄位清單,並以逗號分隔的欄位清單替換,且每個欄位都預先加上別名。7. 步驟 3 和 4 可以透過按下 <C-C>
L 來取代,該映射中嵌入了 <C-Y>
以選擇清單中目前反白顯示的表格。select * from customer c, contact cn, department as dp, employee e, site_options so where c.在輸入模式中,在輸入最後的 "c." (這是 "customer" 表格的別名) 之後,您可以按下
<C-C>
c 或 <C-X>
<C-O>
。這會彈出 customer 表格的欄位清單。它會回頭查看 SELECT 陳述式的開頭,並尋找 FROM 子句中指定的表格清單。在此案例中,它會注意到在字串 "customer c" 中,"c" 是 customer 表格的別名。也支援選用的 "AS" 關鍵字 "customer AS c"。<C-C>
p 會顯示儲存在資料庫中的預存程序清單。<C-C>
v 會顯示資料庫中的檢視清單。omni_sql_no_default_maps
<C-C>
l。產生欄位清單時,可以在每個欄位的開頭加上別名,例如:e.emp_id、e.emp_name。此選項有三個設定n - do not use an alias d - use the default (calculated) alias a - ask to confirm the alias name
MY_TABLE_NAME --> MTN my_table_name --> mtn My_table_NAME --> MtN
MyTableName --> MTN
mytablename --> m MYTABLENAME --> M omni_sql_ignorecase
omni_sql_include_owner
omni_sql_precache_syntax_groups
<C-C>a
<C-C>k
<C-C>f
<C-C>o
<C-C>T
<C-C>s
<C-C>t
<C-C>p
<C-C>v
<C-C>c
<C-C>l
<C-C>L
<Right>
<Right>
在大多數 Unix 系統上無法識別,因此此對應僅在 Windows 平台上建立。如果您希望在 Unix 上使用相同的功能,請選擇不同的按鍵並在您的 vimrc 中建立相同的對應。<Left>
<Left>
在大多數 Unix 系統上無法識別,因此此對應僅在 Windows 平台上建立。如果您希望在 Unix 上使用相同的功能,請選擇不同的按鍵並在您的 vimrc 中建立相同的對應。<C-C>R
let g:omni_sql_no_default_maps = 1不要直接編輯 ftplugin/sql.vim!如果您變更此檔案,您的變更將在未來的更新中被覆寫。Vim 有一個特殊的目錄結構,允許您在不變更 Vim 發行版中包含的檔案的情況下進行自訂。如果您想要自訂對應,請建立一個 after/ftplugin/sql.vim (請參閱 after-directory) 並將 ftplugin/sql.vim 中的相同對應放入其中,並使用您自己的按鍵。選擇
<C-C>
是因為它可以在 Windows 和 unix 平台上運作。在 Windows 平台上,您也可以使用 <C-Space>
或 ALT 鍵。1. :e test.pl 2. :set filetype=sql 3. :set ft=perl
<C-X>
<C-O>
會顯示包含 Perl 語法項目的 omni 快顯視窗。<C-C>
開頭,因此這些對應在使用時將切換 'omnifunc'。因此,您可以使用 <C-X>
<C-O>
繼續使用 Perl 的補全(使用語法補全外掛程式),並使用 <C-C>
使用 SQL 補全功能。