How to edit a register?

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

How to edit a register?

Venkata Suryam Setty ISSA

Hi,

Say, I have recorded a set of commands in to register "z". Now I want to
modify some of the commands in this register.

Can somebody please tell how to do this?

Regards
Suryam.


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: How to edit a register?

Tim Chase

> Say, I have recorded a set of commands in to register "z". Now
> I want to modify some of the commands in this register.


Depending on the complexity of the commands, you might be able to
just get away with using

   :let @z=subsitute(@z, 'command_a', 'command_b', 'g')

-tim




--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: How to edit a register?

Eric Roberts-7
For the non scripted-inclined just remember the fact that you can always "paste" the commands of the register, edit them, then copy back to the register.
For example:

G <-- go to the bottom of the file
o <-- create a new line
"zp <-- paste contents of register z
*edit the contents of this line
V <-- highlight the line containing the edited contents of register z
"zy <-- yank it back into register z
@z <-- play back macro/register z

On Fri, Jul 25, 2008 at 8:29 AM, Tim Chase <[hidden email]> wrote:

> Say, I have recorded a set of commands in to register "z". Now
> I want to modify some of the commands in this register.


Depending on the complexity of the commands, you might be able to
just get away with using

  :let @z=subsitute(@z, 'command_a', 'command_b', 'g')

-tim







--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: How to edit a register?

Venkata Suryam Setty ISSA


Eric Roberts wrote:
For the non scripted-inclined just remember the fact that you can always "paste" the commands of the register, edit them, then copy back to the register.
For example:

G <-- go to the bottom of the file
o <-- create a new line
"zp <-- paste contents of register z
*edit the contents of this line
V <-- highlight the line containing the edited contents of register z
"zy <-- yank it back into register z
@z <-- play back macro/register z

On Fri, Jul 25, 2008 at 8:29 AM, Tim Chase <[hidden email]> wrote:

> Say, I have recorded a set of commands in to register "z". Now
> I want to modify some of the commands in this register.


Depending on the complexity of the commands, you might be able to
just get away with using

  :let @z=subsitute(@z, 'command_a', 'command_b', 'g')

-tim
That's great! Thanks a lot Eric & Tim










--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: How to edit a register?

Tim Chase
In reply to this post by Eric Roberts-7

> For the non scripted-inclined just remember the fact that you
> can always "paste" the commands of the register, edit them,
> then copy back to the register.

For simple macros, this works nicely.  For more complex macros,
this can have some unintended side-effects, as things like CR vs.
NL or other control-characters (or arrows/pg[up/dn]/fn keys, etc)
can throw a wrinkle in the process.  Additionally, you need to
make sure you copy exactly what was pasted, not picking up any
extra newlines.

-tim




--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: How to edit a register?

Ivan Tishchenko

I use this function/commands below.

Usage:
:ER[!]
:ER[!] {regname}

Opens new window for editing contents of register {register}.  If
{register} is not specified, edits default register.  If [!] is used,
edits in a current window instead of opening new one.

Adds three maps:
<f2> to save contents of a window back to register,
<s-cr> and \<cr> to save contents and close the window.


"{{{ EditRegister (ER)
command! -bar -register -bang EditRegister call
EditRegister(<q-reg>,<q-bang>)
command! -bar -register -bang ER           call
EditRegister(<q-reg>,<q-bang>)
function! EditRegister(r,b) abort
  if a:b == '!'
    enew
  else
    new
  endif
  let r = ( a:r == '' ? '"' : a:r )
  let b:regname = r
  try
    exe 'put' r
  catch /^Vim\%((\a\+)\)\=:E353:/
  endtry
  1 del _
  setlocal nomodified noswapfile
  let &l:statusline = '[@%{b:regname}] %m%y%k%= B(%3b,0x%2B)
L%l(%L),C%-5(%2c/%2v%)'
  if r == '"' || r == '@'
    nmap <buffer> <f2> :%yank <bar> let @@ = strpart(@@,0,strlen(@@)-1)
<bar> setlocal nomodified<cr>
  else
    exe 'nmap <buffer> <f2> :%yank <c-r>=b:regname<cr> <bar> let
@<c-r>=b:regname<cr> =
strpart(@<c-r>=b:regname<cr>,0,strlen(@<c-r>=b:regname<cr>)-1) <bar>
setlocal nomodified<cr>'
  endif
  imap <buffer> <f2> <esc><f2>
  nmap <buffer> <s-cr> <f2>:bw<cr>
  nmap <buffer> \<cr>  <f2>:bw<cr>
endfunction

"}}}

> For simple macros, this works nicely.  For more complex macros,
> this can have some unintended side-effects, as things like CR vs.
> NL or other control-characters (or arrows/pg[up/dn]/fn keys, etc)
> can throw a wrinkle in the process.  Additionally, you need to
> make sure you copy exactly what was pasted, not picking up any
> extra newlines.
>
> -tim
>  

--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---

Reply | Threaded
Open this post in threaded view
|

Re: How to edit a register?

Andy Wokula
In reply to this post by Venkata Suryam Setty ISSA

Venkata Suryam Setty ISSA schrieb:
> Hi,
>
> Say, I have recorded a set of commands in to register "z". Now I want to
> modify some of the commands in this register.
>
> Can somebody please tell how to do this?
>
> Regards
> Suryam.

Here is a script dedicated to the task: clipbrd.vim
http://vim.sourceforge.net/scripts/script.php?script_id=1014

--
Andy


--~--~---------~--~----~------------~-------~--~----~
You received this message from the "vim_use" maillist.
For more information, visit http://www.vim.org/maillist.php
-~----------~----~----~----~------~----~------~--~---