Thursday, July 29, 2010

VoraX as a Replacement for Your Fancy Oracle IDE

At the time of writing this post VoraX 1.8 was already released. Frankly, I'm pleased about the results. My target was to have a lightweight, simple and efficient Oracle IDE based on VIM. From this point of view I think that, in many ways, the goal is achieved.

In my opinion, a decent Oracle IDE should have:
- basic features to query the database
- code completion
- plsql editing/compiling support
- a database browser/explorer
- navigation through the package code structure
- SQL statements formatting
- source control support
- the possibility to extend the provided features

Nowadays, it's not very difficult to find out such an IDE (commercial or open source)... but, if you are a VIM addicted guy (like me), you'll soon discover that no editor is better than VI. Furthermore, coming back from VI to a fancy Oracle IDE is such a pain. In those environments I always start editing with "jjj", "kkk"... WTF? It takes a few seconds to realize I'm not in my friendly VI editor.

In this post I'm going to show you how to configure VIM/VoraX as your new Oracle IDE. First of all, dont't forget VoraX is just a plugin therefore is critical to have your VIM properly configured. I know you already know that VIM is highly customizable therefore it's up to you to configure it so that to be the perfect editor you always wanted. Useless to say, VIM provides an "eco-system" of plugins which may prove to be quite useful. You can browse them on the official vim site but, as far as VoraX is concerned, we'll be especially interested in the following ones:

- vcscommand: allows working with various source control systems.
- bufexplorer: provides navigation through VIM buffers.
- supertab: may be used to invoke code completion using the TAB key, much more convenient than C-X C-O.
- NERDTree: a nice file browser directly in VIM.
- NERD Commenter: maybe used to comment the code.
- xptemplate: provides nice snippets/templates. These are met in many modern IDEs.
- taglist: may be used to browse the code structure.
- align and SQLUtilities: provides SQL beautifier functions.

If you look at the above plugins and the features they provide and add all the advanced features of VIM itself, you realize we're quite close to what a modern Oracle IDE might be.

Below is my .vimrc configuration file. Once again, it's up to you to configure it as you want. These are the settings which, over time, proved to be the best for me:

" Maintainer: talek

" Version: 1.0 - 16/04/10 10:09:12


" Description: configuration for vim




"""""""""""""""""""""""""

" => General section


"""""""""""""""""""""""""

" We don't want vi compatibility.


set nocompatible

" How many lines of history to remember


set history=300



" Automatically detect file types.


filetype plugin on

filetype indent on



" Set to auto read when a file is changed from outside


set autoread

 

" Set a more convinient map leader


let mapleader=','

let g:mapleader=','



" Set a shorter timeout


set timeoutlen=250



" Fast exit from insert mode


imap jj <Esc>



" Fast saving


nmap <leader>w :w!<cr>



"""""""""""""""""""""""""

" => VIM user interface


"""""""""""""""""""""""""

if has('gui') && (has('win32') || has('win64'))

  " only on windows GUI version


    set guifont=DejaVu_Sans_Mono:h9

endif



" no toolbar, menu or scroll bars


set guioptions=



" Turn on wild menu


set wildmenu



" Always show current position


set ruler

 

" Set numbering


set nu



" Command bar height


set cmdheight=2



" Change buffer without saving


set hid



" Set backspace config


set backspace=eol,start,indent

set whichwrap+=<,>,h,l



" Ignore case when searching


set ignorecase



" Highlight search things


set hlsearch



" Incremental search please


set incsearch



" We want magic for regular expressions


set magic



" Matching brackets with blink


set showmatch

set mat=2



" We don't like noise on errors


set noerrorbells

set novisualbell

set t_vb=



"""""""""""""""""""""""""

" => Colors and fonts


"""""""""""""""""""""""""

" Enable syntax colloring


syntax enable



" Configure colorscheme


set t_Co=256

set background=light

colorscheme earendel



" In gui mode get rid of the toolbar


if has("gui_running")

  set guioptions-=T

endif



" Set encoding


set encoding=utf8

try

    lang en_US

catch

endtry



" Set default file format


set ffs=unix,dos,mac



set showcmd



"""""""""""""""""""""""""

" => Files and backups


"""""""""""""""""""""""""

" Turn backup off


set nobackup

set nowb

set noswapfile



"""""""""""""""""""""""""

" => Tabbing/indenting


"""""""""""""""""""""""""

set expandtab

set shiftwidth=2

set tabstop=2

set smarttab



set lbr

set tw=500



" Auto indent


set ai

" Smart indent


set si

" No wrap


set nowrap



"""""""""""""""""""""""""

" => Useful mappings


"""""""""""""""""""""""""

" Smart way to move btw. windows


map <C-j> <C-W>j

map <C-k> <C-W>k

map <C-h> <C-W>h

map <C-l> <C-W>l



" Expand/Shrink pane


map <C-Down> <C-W>+

map <C-Up> <C-W>-



" Close the current buffer


map <leader>bd :Bclose<cr>



command! Bclose call <SID>BufcloseCloseIt()

function! <SID>BufcloseCloseIt()

   let l:currentBufNum = bufnr("%")

   let l:alternateBufNum = bufnr("#")



   if buflisted(l:alternateBufNum)

     buffer #

   else

     bnext

   endif



   if bufnr("%") == l:currentBufNum

     new

   endif



   if buflisted(l:currentBufNum)

     execute("bdelete! ".l:currentBufNum)

   endif

endfunction



"""""""""""""""""""""""""

" => Status line configuration


"""""""""""""""""""""""""

" Always hide the statusline


set laststatus=2



" Format the statusline


set statusline=\ %F%m%r%h\ %w\ \ CWD:\ %r%{CurDir()}%h\ \ \ Line:\ %l/%L:%c





function! CurDir()

    let curdir = substitute(getcwd(), '/Users/amir/', "~/", "g")

    return curdir

endfunction



"""""""""""""""""""""""""

" => Abbrevs


"""""""""""""""""""""""""

iab xdate <c-r>=strftime("%d/%m/%y %H:%M:%S")<cr>



"""""""""""""""""""""""""

" => Misc


"""""""""""""""""""""""""

set cf  " Enable error files & error jumping.

set clipboard+=unnamed  " Yanks go on clipboard instead.

 

"""""""""""""""""""""""""

" => Supertab


"""""""""""""""""""""""""

let g:SuperTabDefaultCompletionType = "<c-x><c-o>"

set completeopt+=longest

let g:SuperTabLongestEnhanced=1



"""""""""""""""""""""""""

" => bufExplorer plugin


"""""""""""""""""""""""""

let g:bufExplorerDefaultHelp=0

let g:bufExplorerShowRelativePath=1



"""""""""""""""""""""""""

" => NERDTree config


"""""""""""""""""""""""""

let g:NERDTreeHighlightCursorline = 1

map <leader>ff :NERDTreeToggle<CR>



"""""""""""""""""""""""""

" => XPTemplate config


"""""""""""""""""""""""""

" avoid key conflict


let g:SuperTabMappingForward = '<Plug>supertabKey'



" if nothing matched in xpt, try supertab


let g:xptemplate_fallback = '<Plug>supertabKey'



" xpt uses <Tab> as trigger key


let g:xptemplate_key = '<Tab>'



" use <tab>/<S-tab> to navigate through pum. Optional


let g:xptemplate_pum_tab_nav = 1



" xpt triggers only when you typed whole name of a snippet. Optional


let g:xptemplate_minimal_prefix = 'full'



" Navigate


let g:xptemplate_nav_next = '>>'

let g:xptemplate_nav_prev = '<<'



" Don't like blanks for brackets


let g:xptemplate_brace_complete = '('

let g:xptemplate_vars = "SParg="



"""""""""""""""""""""""""

" => Taglist config


"""""""""""""""""""""""""

" Taglist configuration


let Tlist_Auto_Update=1

let Tlist_Show_One_File = 1

nmap <leader>t :TlistToggle<cr>



"""""""""""""""""""""""""

" => SQL Format config


"""""""""""""""""""""""""

xmap <leader>fo :SQLUFormatter<cr>

 

Okey, now some comments about the above settings, other than the ones directly specified into the script. First of all, what's with the mapleader setting? Well, by default, leader key in Vim is \. On my keyboard this is hard to type and I really don't want to broke my finger reaching for such an used key. Instead, this is remapped to "," which is very convenient to type. Second of all, what's with that "jj" remap? Personally, I don't like to type "ESC" key whenever I want to exit from the insert mode. Pressing "jj" is, again, very convenient.

Pay attention also to all new mappings used to navigate through VIM windows. I think it's much better than C-w j, C-w k etc. <leader>bd is also nice because it allows deleting the last buffer without closing its window, otherwise all remaining windows will be rearranged and this will mess up your layout.

The other settings I guess are obvious and do not deserve the time to explain now here. Of course, customizing VIM is a never-ending story but that's the beauty, really.

1 comment:

Jean said...

Thank you the vimrc was very useful for my VoraX installation, helped me to understand what is a leader and to configure SQLUFormatter.