Sunday, November 3, 2013

Re: Insert comand output on current text

Am 01.11.2013 20:44, schrieb Cesar Romani:
> On 01/11/2013 01:32 p.m., Ben Fritz wrote:
>> On Friday, November 1, 2013 10:29:12 AM UTC-5, andalou wrote:
>>>>>
>>>>> On the current text I'd like to insert the string "ch007.html"
>>>>> (without quotes) without newlines inserted. Is it possible?
>>>>
>>>> This request I don't understand at all. Please give a
>>>> before-and-after example.
>>>
>>> Let's say, I have before:
>>>
>>> Véase el siguiente enlace en el libro
>>>
>>> and after:
>>>
>>> Véase el siguiente enlace ch007.html en el libro
>>
>> Ok, but you can achieve this by moving the cursor to the end of
>> "enlace", typing 'a' to enter insert mode, then typing " ch007.html".
>> But I'm sure you know how to do that. So what are you really asking?
>> What do you want to do, to get to your resulting text?
>
> If I go after the end of "enlace" and do :1,.s/^# /&/n
> I get, say:
> 8 matches on 8 lines
>
> then I'd like to have ch007.html after "enlace."
>
> If the above command outputs:
> 35 matches on 35 lines
>
> then I'd like to have ch034.html after "enlace."
>
> I suppose, I can do it manually. Thanks anyway.

You didn't mention that 8 is connected with 7.

:substitute sets v:statusmsg
:h v:statusmsg

:let filename = printf('ch%03d.html', matchstr(v:statusmsg, '\d\+')-1)

Append text after EOL:
:call setline('.', getline('.'). filename)
:exec 'normal! A'. filename
:s/$/\=filename

--
Andy

--
--
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 vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

No comments: