tags:

views:

55

answers:

2

I try to use VIM build my SQL query by concatenate block of strings. For example, I have the following strings in three tabs in VIM:

# block one
 where c = '123'
 where c = '2345'
 ... 

# block two
set b = 12
set b = 345
...

# block three
update myTable set a = 'abc', 
update myTable set a = '23423', 
...

each block contains 100 lines (fragments of SQL query). I would like to concatenate those blocks in to one complete SQL query: block one + block two + block three (100 lines) like this:

# sql queries
update myTable set a = 'abc', set b = 12 where c = '123'
update myTable set a = '23423', set b = 345 where c = '2345'
...

Just ignore the first line #..., it is just for explanation. I think that Visual Block can be used do that:

  1. Yank all the lines in tab "block two";
  2. Paste buffer to tab "block three" at the beginning;
  3. Yank all the lines in tab "block one";
  4. Paste the buffer to tab "block three" at the beginning.

However, I tried to the tip in Visual Block Mode(first two y and p examples), I could not get my expected result. The paste does not concatenate the buffer strings to the block. Not sure what I did wrong. Or any other alternative ways?

+2  A: 

I recently ran across a VimCasts episode that describes how to do editing in visual block mode. Check out the video, I believe he describes what you want.

nathan
Yes. I yank the block first, and then P to paste the block to a position where I want to insert the block of text. Thanks!
David.Chu.ca
+2  A: 

Did you try Visual-blockwise (ctrl-v)? They have to be the same width lines, but it works.

# Yank the lines from the other file
gg V G 
# Add whitespace to the end
:%s/$/  /
# Select the whitespace at the end of the other file, and paste it
gg $ ctrl-v $ p

You may have to make a few changes, but hopefully it gave you some ideas at least.

bradlis7