Dani's IT Blog

…moving from Oracle to Software Development

Posts Tagged ‘trick

use menus in Vim without having a GUI

leave a comment »

While applying changes to sqplus.vim I was looking for the option to execute code only if Vim is running in a GUI ( if has("gui_running") ) While searching for this information I changed my mind, because I found out that you can use the menu also when running Vim on command line.

You just have to add the following lines to you .vimrc

:source $VIMRUNTIME/menu.vim
:set wildmenu
:set cpo-=<
:set wcm=<C-Z>

To use the newly added feature write :emenu plus a SPACE in command mode and press TAB. A menu appears above the command bar. You can change between the menu points with TAB and choose one with ENTER. After this you are in the sub menu, again you can select with TAB and ENTER.

You can also write a part of a menu point and complete it with tab. Or you type :emenu <C-D> (<C-D> means Ctrl+D for those not used this notation) which shows you a list of all possible menu entries.

The cool thing about wildmenu is, it brings you command completion for more than just menus. For example you could use it to show a list of available help entries. To try this type :h spl <C-D> and you will see a list of available help documents about split, vsplit, isplit, display …

Written by danirey

October 27, 2009 at 10:05

improve your working speed… with old technology

leave a comment »

You can massively improve your working speed by using Vim instead of other editors. Full stop.

I think most people will agree, that using Vim is the fastest way to edit files, after they have learned to use it (I’ve decided to write Vim instead of Vi here, because of the visual mode). But what’s about the rest of my working process?

Usually you have to execute and test the scripts you’re writing. Most IDEs are capable of doing this, what about Vim? Although Vim is not really an IDE by itself, it’s quite easy to add functionalities. This is usually done by adding plugins to your Vim. One of the plugins which massively improved my working speed is sqlplus.vim from Jamis Buck.

You can use it to directly execute parts of the script your writing at the moment, or just execute a query on the database without even adding it to your script. You can find the full description on www.vim.org.

While I was writing my last post, I was rethinking my whole working process and decided that some stuff was still missing in sqlplus.vim. And that’s the point where another cool feature of Vim kicks in. All plugins are written in a script language and you can simply edit them yourself, just remember to contact the original author afterwards, for that everybody can profit from your improvements.

After a short discussion with Jamis, I uploaded the newest version of the plugin to sqlplus.vim. Unfortunately I had to fork the script, because www.vim.org doesn’t allow you to change the maintainer of a already published plugin. If you have any questions, ideas or problems with sqlplus.vim feel free to contact me.

Written by danirey

October 24, 2009 at 16:01

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.

    Written by danirey

    October 20, 2009 at 06:26

    Posted in English, Oracle, Tipps&Tricks, VIM

    Tagged with , , , , , ,