Dani's IT Blog

…moving from Oracle to Software Development

Everybody writes about new stuff from OpenWorld… I write about old fashioned VIM

leave a comment »

Besides trying to beat Kevin Closson in the length of my blog post titles, I try to write about stuff which makes life as a DBA easier and more fun. This time I write about old fashioned VIM (maybe a part of the tricks works also with VI, but I had none handy to test. Sorry, I’m one of those “oh so modern” Linux guys with VIM behind their VI command).

Let’s have a look at the .vimrc file which is in your home directory. In this file you can configure the behavior of your VIM installation (Windows users can find _vimrc in the folder of the GVIM Installation). It is mainly used to define some stuff like:

  • colorscheme
  • font
  • search behavior
  • tabstop width
  • This sounds very simple, but why do I use a .vimrc with more than 200 lines? Because you can even code in a simple scripting language and call this scripts with shortcuts from within VIM.

    One very simple example of this, is a little alias which I use to execute the file, which I’m editing at the moment, with sqlplus. The 2 code lines look like the following.

    let con_str='"/ as sysdba"'
    map  :execute ":w"  :execute "!sqlplus " . con_str . " @%"
    

    When I now press F2 in the Command Mode, the current File gets executed in sqlplus as sysdba. You can, of course, change the value of the con_str variable to execute it as a different user. I think /nolog might also be a useful default value, especially if you use it directly on your database server. To change it within VIM use the following command

    :let con_str='/nolog'
    

    For the GUI guys, there is a possibility to add a menu entry for this. Just add the following two lines to your .vimrc

    :menu Oracle.SQLPLUS<Tab>F2 :execute ":w" <CR> :execute "!sqlplus " . con_str . " @%"<CR>
    :menu Oracle.SQLPLUSW :execute ":w" <CR> :execute "!sqlplusw " . con_str . " @%"<CR>
    

    This will create a new menu entry called Oracle with buttons for SQL*Plus and SQL*PlusW.

    If you like this simple tricks, you will love the sqlplus plugin from Jamis Buck. http://www.vim.org/scripts/script.php?script_id=97 It’s a powerful and easy to use plugin for your vim.

    While working on this post, I started using the sqlplus plugin again and I ended up adding a functionality which I missed for a long time and making some minor changes. At the moment I’m contacting Jamis to get his opinion about my changes. As soon as we agreed on them, the new version will be published on http://www.vim.org. I will then write about the sqlplus plugin.

    Advertisements

    Written by danirey

    October 20, 2009 at 06:26

    Posted in English, Oracle, Tipps&Tricks, VIM

    Tagged with , , , , , ,

    Leave a Reply

    Fill in your details below or click an icon to log in:

    WordPress.com Logo

    You are commenting using your WordPress.com account. Log Out / Change )

    Twitter picture

    You are commenting using your Twitter account. Log Out / Change )

    Facebook photo

    You are commenting using your Facebook account. Log Out / Change )

    Google+ photo

    You are commenting using your Google+ account. Log Out / Change )

    Connecting to %s

    %d bloggers like this: