Tip #41: Command-history facilities for Oracle/sqlplus user
tip karma |
Rating 13/6, Viewed by 6438
|
Read and edit this tip on the
Vim tip wiki.
The wiki may have a more recent version of this tip.
created: |
|
March 8, 2001 21:26 |
|
complexity: |
|
advanced |
author: |
|
[email protected] |
|
as of Vim: |
|
5.7 |
First of all, thanks Benji fisher, Stefan Roemer...
and others in [email protected] which spend much time to
answer questions, sometimes foolish question asked by
someone like me. Without their I can't get the final
solution for my sqlplus work descripted follows.
As Oracle user known, sqlplus has a very bad
command-line edition environment. It has no
command-history, don't support most of getline
facilities. which MySQL and shell does it well.
Even Microsoft recogonize this point. In Windows2000,
doskey is installed by default.
Below is my vim-solution to sqlplus, which
record the command-history when you use
edit(sqlplus builtin command) to open the editor
specified by EDITOR environment variable. It saves
the SQL statement into a standalone file such as
.sqlplus.history
Every time you open the file
afiedt.buf(sqlplus's default command-buffer file),
you get two splited windows, the buffer above is
afiedt.buf, the buffer below is .sqlplus.history,
you can see every SQL statement in the windows.
If you want to use SQL statement in line 5 to replace
the current command-buffer, just press 5K, then
:xa
to back to you sqlplus. and use / to repeat the command
saved in command-buffer file called afiedt.buf by default.
It can't process multi-line SQL statement convinencely.
Todo this, just use you favorite vim trick to do that:
fu! VimSQL()
nnoremap <C-K> :<C-U>
exe "let linenum=".v:count<CR>:1,$-1d<CR><C-W>j:exe lin
enum."y"<CR><C-W>kP
let linenum=line("$")
1,$-1w! >> ~/.sqlplus.history
e ~/.sqlplus.history
execute ":$-".(linenum-1).",$m0"
%!uniq
if line("$")>100
101,$d
endif
b#
set splitbelow
sp ~/.sqlplus.history
au! BufEnter afiedt.buf
endf
au BufEnter afiedt.buf call VimSQL()
<< Insert a file |
Using marks >>
Additional Notes
[email protected],
April 19, 2001 5:59
|
I added the following:
set syntax=sql
at the start of the function and after loading the history file, this way the files will be shown with syntax highlighting.
Also the following map
map ZZ :close<cr>:b afiedt.buf<cr>:xit<cr>
will let the ZZ function close the second window and save the afiedt.buf file and then exit (if the user has no other dirty buffers).
Stephen
|
[email protected],
October 19, 2002 11:39
|
Another solution (but not olny for vim editor) :
If your operating system is HP-UX, try below.
$ ied sqlplus <user>/<pass>@<db>
SQL> [Escape-Key]
SQL> [K-Key] or [J-Key]
ied is a utility command that is intended to act as an interface
between the user and an interactive program such as bc, sqlplus,
providing most of the line editing and history functionality found in the Korn shell.
mako
|
|