save and load a micro

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

save and load a micro

Sand Glass
I will often do the following things next days.
So I want to record the commands as a macro. But I don't know how to save the macro to a file and load the macro next time, so that I open a file just hit a key, can do the repeat things.
input bin file:
0000000: 00ff ffff ffff ff00 39f6 3412 7856 3412  ........9.4.xV4.
0000010: 191a 0103 8059 3278 eaee 91a3 544c 9926  .....Y2x....TL.&
0000020: 0f50 5400 0000 0101 0101 0101 0101 0101  .PT.............
0000030: 0101 0101 0101 08e8 0030 f270 5a80 b058  .........0.pZ..X
0000040: 8a00 22c4 3100 001e 0000 00fc 004e 4f56  ..".1........NOV
0000050: 4153 5441 520a 2020 2020 0000 0011 0000  ASTAR.    ......
0000060: 0000 0000 0000 0000 0000 0000 0000 0011  ................
0000070: 0000 0000 0000 0000 0000 0000 0000 015b  ...............[
0000080: 0203 1cd0 4161 2309 0707 6703 0c00 1000  ....Aa#...g.....
0000090: 203c 67d8 5dc4 0178 c002 e10f 08e8 0030   <g.]..x.......0
00000a0: f270 5a80 b058 8a00 20c2 3100 001e 0000  .pZ..X.. .1.....
00000b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
00000f0: 0000 0000 0000 0000 0000 0000 0000 00a7  ................
0000100: 0a                                       .

output txt file:
0x00,0xff ,0xff,0xff ,0xff,0xff ,0xff,0x00 ,0x39,0xf6 ,0x34,0x12 ,0x78,0x56 ,0x34,0x12,
0x19,0x1a ,0x01,0x03 ,0x80,0x59 ,0x32,0x78 ,0xea,0xee ,0x91,0xa3 ,0x54,0x4c ,0x99,0x26,
0x0f,0x50 ,0x54,0x00 ,0x00,0x00 ,0x01,0x01 ,0x01,0x01 ,0x01,0x01 ,0x01,0x01 ,0x01,0x01,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,0x00 ,0x00,0x00 ,0x00,0xa7

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: save and load a micro

Ni Va
Le dimanche 11 juin 2017 04:52:22 UTC+2, Sand Glass a écrit :

> I will often do the following things next days.
> So I want to record the commands as a macro. But I don't know how to save the macro to a file and load the macro next time, so that I open a file just hit a key, can do the repeat things.
> input bin file:
> 0000000: 00ff ffff ffff ff00 39f6 3412 7856 3412  ........9.4.xV4.
> 0000010: 191a 0103 8059 3278 eaee 91a3 544c 9926  .....Y2x....TL.&
> 0000020: 0f50 5400 0000 0101 0101 0101 0101 0101  .PT.............
> 0000030: 0101 0101 0101 08e8 0030 f270 5a80 b058  .........0.pZ..X
> 0000040: 8a00 22c4 3100 001e 0000 00fc 004e 4f56  ..".1........NOV
> 0000050: 4153 5441 520a 2020 2020 0000 0011 0000  ASTAR.    ......
> 0000060: 0000 0000 0000 0000 0000 0000 0000 0011  ................
> 0000070: 0000 0000 0000 0000 0000 0000 0000 015b  ...............[
> 0000080: 0203 1cd0 4161 2309 0707 6703 0c00 1000  ....Aa#...g.....
> 0000090: 203c 67d8 5dc4 0178 c002 e10f 08e8 0030   <g.]..x.......0
> 00000a0: f270 5a80 b058 8a00 20c2 3100 001e 0000  .pZ..X.. .1.....
> 00000b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
> 00000c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
> 00000d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
> 00000e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
> 00000f0: 0000 0000 0000 0000 0000 0000 0000 00a7  ................
> 0000100: 0a                                       .
>
> output txt file:
> 0x00,0xff ,0xff,0xff ,0xff,0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0x00 ,0x00,0x00 ,0x00,0x00,
> 0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00,
> 0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00,
> 0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0xa7

Try this :
0,$ call setline(line('.'),substitute(join(map(split(getline('.'),'\s')[1:-3], '"0x".v:val[:1]." 0x".v:val[2:]')),'\s',',',"g"))

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: save and load a micro

Ni Va
In reply to this post by Sand Glass
Le dimanche 11 juin 2017 04:52:22 UTC+2, Sand Glass a écrit :

> I will often do the following things next days.
> So I want to record the commands as a macro. But I don't know how to save the macro to a file and load the macro next time, so that I open a file just hit a key, can do the repeat things.
> input bin file:
> 0000000: 00ff ffff ffff ff00 39f6 3412 7856 3412  ........9.4.xV4.
> 0000010: 191a 0103 8059 3278 eaee 91a3 544c 9926  .....Y2x....TL.&
> 0000020: 0f50 5400 0000 0101 0101 0101 0101 0101  .PT.............
> 0000030: 0101 0101 0101 08e8 0030 f270 5a80 b058  .........0.pZ..X
> 0000040: 8a00 22c4 3100 001e 0000 00fc 004e 4f56  ..".1........NOV
> 0000050: 4153 5441 520a 2020 2020 0000 0011 0000  ASTAR.    ......
> 0000060: 0000 0000 0000 0000 0000 0000 0000 0011  ................
> 0000070: 0000 0000 0000 0000 0000 0000 0000 015b  ...............[
> 0000080: 0203 1cd0 4161 2309 0707 6703 0c00 1000  ....Aa#...g.....
> 0000090: 203c 67d8 5dc4 0178 c002 e10f 08e8 0030   <g.]..x.......0
> 00000a0: f270 5a80 b058 8a00 20c2 3100 001e 0000  .pZ..X.. .1.....
> 00000b0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
> 00000c0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
> 00000d0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
> 00000e0: 0000 0000 0000 0000 0000 0000 0000 0000  ................
> 00000f0: 0000 0000 0000 0000 0000 0000 0000 00a7  ................
> 0000100: 0a                                       .
>
> output txt file:
> 0x00,0xff ,0xff,0xff ,0xff,0xff ,0xff,0x00 ,0x39,0xf6 ,0x34,0x12 ,0x78,0x56 ,0x34,0x12,
> 0x19,0x1a ,0x01,0x03 ,0x80,0x59 ,0x32,0x78 ,0xea,0xee ,0x91,0xa3 ,0x54,0x4c ,0x99,0x26,
> 0x0f,0x50 ,0x54,0x00 ,0x00,0x00 ,0x01,0x01 ,0x01,0x01 ,0x01,0x01 ,0x01,0x01 ,0x01,0x01,
> 0x01,0x01 ,0x01,0x01 ,0x01,0x01 ,0x08,0xe8 ,0x00,0x30 ,0xf2,0x70 ,0x5a,0x80 ,0xb0,0x58,
> 0x8a,0x00 ,0x22,0xc4 ,0x31,0x00 ,0x00,0x1e ,0x00,0x00 ,0x00,0xfc ,0x00,0x4e ,0x4f,0x56,
> 0x41,0x53 ,0x54,0x41 ,0x52,0x0a ,0x20,0x20 ,0x20,0x20 ,0x00,0x00 ,0x00,0x11 ,0x00,0x00,
> 0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x11,
> 0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x01,0x5b,
> 0x02,0x03 ,0x1c,0xd0 ,0x41,0x61 ,0x23,0x09 ,0x07,0x07 ,0x67,0x03 ,0x0c,0x00 ,0x10,0x00,
> 0x20,0x3c ,0x67,0xd8 ,0x5d,0xc4 ,0x01,0x78 ,0xc0,0x02 ,0xe1,0x0f ,0x08,0xe8 ,0x00,0x30,
> 0xf2,0x70 ,0x5a,0x80 ,0xb0,0x58 ,0x8a,0x00 ,0x20,0xc2 ,0x31,0x00 ,0x00,0x1e ,0x00,0x00,
> 0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00,
> 0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00,
> 0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00,
> 0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00,
> 0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0x00 ,0x00,0xa7
0,$ call setline(line('.'),substitute(join(map(split(getline('.'),'\s')[1:8], '"0x".v:val[:1]." 0x".v:val[2:]')),'\s',',',"g").',')

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: save and load a micro

Sand Glass
In reply to this post by Sand Glass
I have done the thing use following commands.
GkVjdggww^QjjjjjjjjjjjjjjjjjI,0x^[5l.ww.5l.ww.5l.ww.5l.ww.5lwhhhhl.ww.5l.ww.5l.ww.5.u5l.el.l^QjjjjjjjjjjjjjjjjDjjjjjjjjjjjjjjjx0gg^Qjjjjjjjjjjjjjjjjjjjjelllx
And record a macro in register a. But the macro not completely right like ^Q(it's into block coloumn mode). I want to fix my macro and save it to a file, next time I open a file can load the macro to a reg.
The question is I don't how to fix my macro and load it to a reg next time.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: save and load a micro

Ben Fritz
On Sunday, June 11, 2017 at 5:26:43 AM UTC-5, Sand Glass wrote:
> And record a macro in register a. But the macro not completely right like ^Q(it's into block coloumn mode). I want to fix my macro and save it to a file, next time I open a file can load the macro to a reg.
> The question is I don't how to fix my macro and load it to a reg next time.

By default, it should be saved already, in your .viminfo file. Check your 'viminfo' setting to make sure if you are worried.

You can also paste the contents of your register into a file with this normal-mode command:

  "ap

Then you can save that file if you like. To get your macro back, just yank the content back into a register:

  0"ay$

This may not work in all cases for special characters in the register, etc. The .viminfo method is probably more robust.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: save and load a micro

Nikolay Aleksandrovich Pavlov
2017-06-12 8:05 GMT+03:00 Ben Fritz <[hidden email]>:

> On Sunday, June 11, 2017 at 5:26:43 AM UTC-5, Sand Glass wrote:
>> And record a macro in register a. But the macro not completely right like ^Q(it's into block coloumn mode). I want to fix my macro and save it to a file, next time I open a file can load the macro to a reg.
>> The question is I don't how to fix my macro and load it to a reg next time.
>
> By default, it should be saved already, in your .viminfo file. Check your 'viminfo' setting to make sure if you are worried.
>
> You can also paste the contents of your register into a file with this normal-mode command:
>
>   "ap
>
> Then you can save that file if you like. To get your macro back, just yank the content back into a register:
>
>   0"ay$
>
> This may not work in all cases for special characters in the register, etc. The .viminfo method is probably more robust.

For robust keeping register in a file one should use
`writefile([getregtype('a')] + getreg('a', 1, 1), 'rega', 'b')`. For
restoring then: `let rega = readfile('rega', 'b') | setreg('a',
rega[1:], rega[0])`.

>
> --
> --
> You received this message from the "vim_use" maillist.
> Do not top-post! Type your reply below the text you are replying to.
> For more information, visit http://www.vim.org/maillist.php
>
> ---
> You received this message because you are subscribed to the Google Groups "vim_use" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
> For more options, visit https://groups.google.com/d/optout.

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: save and load a micro

Sand Glass
Thanks for ZyX.
The finial command is following:
qa  "start recording to reg a
"do your command
q   "end recording
:call writefile([getregtype('a')] + [getreg('a', 1)], 'rega.txt', 'b')
:let rega = readfile('rega.txt', 'b')
:call setreg('a', rega[1], rega[0])
@a  "play the macro

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Loading...