Monday, November 30, 2009

Re: Specify a register for a custom command



On Mon, Nov 30, 2009 at 2:56 AM, Andy Wokula <anwoku@yahoo.de> wrote:
Christian Brabandt schrieb:
> Hi Nathan!
>
> On Mo, 30 Nov 2009, Nathan Neff wrote:
>
>> I see that there's a "-register" option that I can use when defining
>> a custom command, but I'm having trouble understanding how to use it.
>>
>> For example, I just want to create a command that prints out the contents of
>> a register that is specified by the user.
>>
>> I tried something like this, but can't print out the <reg> part:
>>
>> :command! -register Foo :echo You picked this register: <reg>
>>
>> What am I doing wrong?
>
> You need to expand <reg>, e.g. com! -register Foo :echo expand("<reg>")

You were just guessing?
   :Foo a
executes
   :echo expand("a")

Nathan, try these examples:
   :com! -register  Foo  echo 'Register:' <q-reg>
   :com! -register  Foo  display <reg>

   :h <q-args>

Thanks for the replies, but none of these examples do what I'm looking for.

I'm looking to create a custom command / mapping where I can use the contents of a register that is specified by the user.

Similar to how ["x]p works.  The user can press "ap and the contents of the "a" register will be pasted.  The user can just press p and the contents of the unnamed register are pasted by default.

I want to define a custom command where the user can put the optional ["x] in front of the mapping, and my command will work with the register that the user specified.

If the user doesn't specify a register, then I'm going to use the unnamed register by default.

Is there a way to create a mapping that accepts the optional ["x] in front of it?

Thanks,
--Nate

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

No comments:

Post a Comment