开发者

column copy and paste in row

I have a file with follow content:

    sensor_write_reg(client,0x57,0x00);
    sensor_write_reg(client,0x58,0x00);
    sensor_write_reg(client,0x59,0x00);
    sensor_write_reg(client,0xfe,0x00);
    sensor_write_reg(client,0x46,0x00);

I want to column copy the following text to a new file:

struct reg reg_table[] =
{
// paste here
}

int a;
int b;
int c;
// ...

the following content expected:
struct reg reg_table[] =
{
0xfe,0x01   
0x54,0x11
0x55,0x03
0x56,0x00
0x57,0x00
0x58,0x00
0x59,0x00
0xfe,0x00
0x46,0x00
}

int a;
int b;
int c;
// ...

In the source file, I type CTRL+v to enter column mode, select and copy. Type CTRL+W to enter the destination file, and type p to paste. Howe开发者_如何学Cver, the pasted content overrides the following statements. That's not I want.

0xfe,0x01
0x54,0x11}
0x55,0x03int a;
0x56,0x00int b;
0x57,0x00int c;
0x58,0x00

Is the any way to paste it in row mode, in a number of new lines?


To always paste something linewise you can use the :put command.

:put

If you want to convert to characterwise or blockwise you can use the setreg() function as shown in this vim tip or use this plugin, UnconditionalPaste.


Blockwise selection doesn't work like linewise selection.

You are copying text from 6 lines so you have to free 6 lines for pasting. Try 6O<CR>p


You also could try a macro; after some trying, I found this one:

y:tabe^MP:%s/^.*\(0x\x\+,0x\x\+\).*$/\1/^MVggy:tabclose!^M^Wjp

(the ^M and ^W are carriage return and control-W)

The setup of your vim would be...

  • one tab with two windows, horz splitted (via C-W S)
  • the sensor_write_reg-stuff in the upper window,
  • the paste here-source code in the lower one.
  • lower window: got to line "paste here"
  • upper window: visual select (now with capital V) the lines you want
  • then press @q (if the macro is saved to q; or just type the commands on the fly...) and let the magic happen...

what happens here?

  • y
    we yank the text
  • :tabe^MP
    and open a new tab with an empty buffer, paste the text
  • (caution: if you have an unnamed buffer, this will not work)
  • :%s/^.(0x\x+,0x\x+).$/\1/
    here we filter: only two hex-digits, seperated by a comma, will survive.
  • Vggy:tabclose!^M
    yank everything, close the buffer (without saving)
  • (now we are back to the first tab, still in the upper window)
  • ^Wjp
    move one window down, and paste.

Finally you could use a kD to delete the "paste here"-line...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜