Document Type | Technical Information
Category | Monitoring/Inspection
Applicable Product Version | All Tibero Versions
Document Number | TMOTI046
Overview
This describes how to utilize the query auto-completion feature provided by SQL development tools in tbsql using vim script to perform tasks more efficiently.
Method
vim script
vim script is used to apply the desired environment options/variables when running the vim utility.
vim script configuration
Set vim utility to be used by default.
$HOME/.bash_profile or $HOME/.bashrc or $HOME/.profile
export EDITOR=vim
[*] Create a vim script file and add the contents.
[*] let assigns the query to be used as a variable.
[*] map defines commands to be used as shortcuts in vim command mode.
$ vi $HOME/.vimrc
"---------------------------------------------------------
" TIBERO tbsql Go to query (tbGTQ)
let q1="SELECT * FROM "
let q2="SELECT * FROM dba_objects WHERE owner not in ('SYS','SYSCAT','OUTLN','PUBLIC','TIBERO','TIBERO1')"
let q3="SELECT b.owner,sum(b.byte) /1024/1024/1024 FROM dba_objects a, dba_segments b WHERE a.object_name = b.segment_name AND a.owner not in ('SYS','SYSCAT','OUTLN','PUBLIC','TIBERO','TIBERO1') GROUP BY b.owner"
let q4=""
let q5=""
let q6=""
let q7=""
let q8=""
let q9=""
let q10=""
" TIBERO Shortcut keys
map <F1> :call setline('.',getline('.').q1)<CR>
map <F2> :call setline('.',getline('.').q2)<CR>
map <F3> :call setline('.',getline('.').q3)<CR>
map <F4> :call setline('.',getline('.').q4)<CR>
map <F5> :call setline('.',getline('.').q5)<CR>
map <F6> :call setline('.',getline('.').q6)<CR>
map <F7> :call setline('.',getline('.').q7)<CR>
map <F8> :call setline('.',getline('.').q8)<CR>
map <F9> :call setline('.',getline('.').q9)<CR>
map <F10> :call setline('.',getline('.').q10)<CR>
" "---------------------------------------------------------
[*] Use these in command mode of the editor within tbsql.
[*] Use the shortcut keys defined in map of .vimrc in command mode.
$ tbsql sys/tibero
F1 shortcut key
SELECT * FROM
~
~
~
:call setline('.',getline('.').q1)
F2 shortcut key
SELECT * FROM dba_objects WHERE owner not in
('SYS','SYSCAT','OUTLN','PUBLIC','TIBERO','TIBERO1')
~
~
~
:call setline('.',getline('.').q2)
F3 shortcut key
SELECT b.owner,sum(b.byte) /1024/1024/1024 FROM dba_objects a, dba_segments b WHERE
a.object_name = b.segment_name AND a.owner not in
('SYS','SYSCAT','OUTLN','PUBLIC','TIBERO','TIBERO1') GROUP BY b.owner
~
~
~
:call setline('.',getline('.').q3)
Separating .vimrc
If you are already using $HOME/.vimrc or want to separate only the query auto-completion feature, proceed as follows.
[*] Create a separate file for only the query auto-completion options.
| $ vi tbGTQ.vim |
"--------------------------------------------------------- " TIBERO tbsql Go to query (tbGTQ) let q1="SELECT * FROM " let q2="SELECT * FROM dba_objects WHERE owner not in ('SYS','SYSCAT','OUTLN','PUBLIC','TIBERO','TIBERO1')" let q3="SELECT b.owner,sum(b.byte) /1024/1024/1024 FROM dba_objects a, dba_segments b WHERE a.object_name = b.segment_name AND a.owner not in ('SYS','SYSCAT','OUTLN','PUBLIC','TIBERO','TIBERO1') GROUP BY b.owner"
let q4="" let q5="" let q6="" let q7="" let q8="" let q9="" let q10=""
" TIBERO Shortcut keys map <F1> :call setline('.',getline('.').q1)<CR> map <F2> :call setline('.',getline('.').q2)<CR> map <F3> :call setline('.',getline('.').q3)<CR> map <F4> :call setline('.',getline('.').q4)<CR> map <F5> :call setline('.',getline('.').q5)<CR> map <F6> :call setline('.',getline('.').q6)<CR> map <F7> :call setline('.',getline('.').q7)<CR> map <F8> :call setline('.',getline('.').q8)<CR> map <F9> :call setline('.',getline('.').q9)<CR> map <F10> :call setline('.',getline('.').q10)<CR> " "--------------------------------------------------------- |
[*] Add a source or so command.
[*] The query auto-completion option file must be specified with an absolute path.
$ vi $HOME/.vimrc
source /home/tibero/tbGTQ.vim
or
so /home/tibero/tbGTQ.vim
Changing query auto-completion shortcut keys
[*] Shortcut keys can be declared in the map section of the query auto-completion script.
You can use shortcut keys combining Ctrl with alphabets or function keys.
" TIBERO Shortcut keys
map <F1> :call setline('.',getline('.').q1)<CR>
" Ctrl can be combined with alphabets a-z (case insensitive).
map <C-a> :call setline('.',getline('.').q1)<CR>
map <C-z> :call setline('.',getline('.').q1)<CR>
" Ctrl+number shortcuts without letters are not supported.
map <C-1> :call setline('.',getline('.').q1)<CR>
map <C-10> :call setline('.',getline('.').q1)<CR>
" Shortcut keys for consecutive keys are not supported.
map <C-a1> :call setline('.',getline('.').q1)<CR>
map <C-a-1> :call setline('.',getline('.').q1)<CR>
" Not supported without Ctrl.
map <a> :call setline('.',getline('.').q1)<CR>