how to use vim in sqlplus
case for unix-like OS
How to configure vim to be a default sqlplus editor, to enable syntax highlightning and keywords completion?
Here's tiny instructions.
- First step is obvious -- we need to add/modify line in ~/login.sql
define _editor=vim
- Second step -- additions to local .vimrc:
set nocompatible " it's vim not vi, for Christ sake! syntax on " why not? " next function allows you to do completion of words by pressing <Tab> function! InsertTabWrapper(direction) let col = col('.') - 1 if !col || getline('.')[col - 1] !~ '\k' return "\<tab>" elseif "backward" == a:direction return "\<c-p>" else return "\<c-n>" endif endfunction inoremap <tab> <c-r>=InsertTabWrapper ("forward")<cr> inoremap <s-tab> <c-r>=InsertTabWrapper ("backward")<cr>
- Next step -- changes in local ~/.vim folder:
- add into folder ~/.vim/after/ file filetype.vim with the following content:
augroup filetypedetect au BufNewFile,BufRead afiedt.buf setf sql augroup END
- add into folder ~/.vim/after/syntax/ file sql.vim with the following content:
set dict+=$HOME/.vim/dict/sql.dict " our own dictionary set cpt=.,k,w,b,t,i " use keywords (k) for completion
- create file ~/.vim/dict/sql.dict with words for which 'completion' should work (remember that completion should already work for standard keywords, defined in $VIMRUNTIME/syntax/sql.vim). It might be words like: dual, v$session, dba_data_files etc.
- add into folder ~/.vim/after/ file filetype.vim with the following content:
That's it.
By the way, do you know that you can easily configure sqlplus to enable command line editing, searching in previous commands and even using words completion? If no, then you will probably like another my article 'how to edit command-line in sqlplus and rman'.