Wednesday, July 25, 2012

Vim - open a list of files from previous command


Problem : You want to execute a find command and open all the files into vim

find . -name * | xargs vim

Something not working right ?

Try
$> find . -name *
$> vim $(!!)

What just happened ?

The first command executes a "find"

The second command is opening vim and providing an argument list from a previous command. You
could also have executed

$> vim $(find . -name *)

Keywords
output command previous xargs vim to pipe

Tuesday, February 7, 2012

Using key mapping in vi

vi or vim provide a very useful technique whereby user can assign arbitrary functions to control key strokes. For eg, here is one such mapping:

map ^k I/*A*/

When a hits ctrl+k, the line on which the cursor currently is, is commented. To explain the command:
map ^k - assigns the functionality to ctrl+k character
I/*A*/ - concatenation of smaller operations which are
- Move to Esc mode,
I - Insert in the beginning of the line
/* - characters to be inserted
- Move to Esc mode
A - Append at the end of the line
*/ - characters to be appended
- move to Escape mode

The Esc key can be typed by first typing Ctrl+V followed by Esc key.

By adding this mapping to .vimrc file, this mapping can be saved across vim invocations.

Monday, February 6, 2012

Using vi as Line Editor in bash

For folks who are comfortable with vi, use the following command and override the default line editor (emacs) in bash:

$ set -o vi

Now start using vi commands to edit bash commands. It supports both insert and escape modes, just like the vi text editor.

Thursday, February 2, 2012

Sorting in a recursive query

Here is a neat utility from Oracle to query a table recursively, and sort results among siblings:

SELECT e.id, e.name, e.manager_id
FROM employee e
START WITH ID = 1
CONNECT BY manager_ID = PRIOR ID
order siblings by e.name;

Note the 'order siblings by' clause. This can be used only with recursive queries and sorts the siblings by the name.

Sunday, January 15, 2012

Oracle Cascade Delete

http://www.sandeepsinghal.com/2012/01/14/oracle-cascase-delete/

Sunday, October 9, 2011

Oracle SID vs Service Name in JDBC URL

With SID
jdbc:oracle:thin@myhost:port:sid

With Service Name
jdbc:oracle:thin@myhost:port/service

Tuesday, October 4, 2011

Vim - Join Lines with a Comma (or any other character)

Step 1 : Put the desired character at the end of each line. I will use a "," as an example

:%s/$/,/g

Step 2 : Join the lines together

%j!