I try to use VIM build my SQL query by concatenate block of strings. For example, I have the followi开发者_如何学JAVAng 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:
- Yank all the lines in tab "block two";
- Paste buffer to tab "block three" at the beginning;
- Yank all the lines in tab "block one";
- 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?
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.
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.
精彩评论