Tuesday, December 21, 2010

Re: How to insert text into buffer from vim commandline?

Thanks. that worked great!

I was thinking of storing the value(PLT_count) into a register(clipboard) and then printing it via 'p'. But now the problem is I am only able to store the value in " register and am not able to store in any other named register(a,b,c etc.,) 

The sequence that works now:
"=PLT_count
p

The sequence which I want to work out fine is:

"v=PLT_count
p

What the syntax to store a global variable's value into register rather than the content from d or y operations?

On Tue, Dec 21, 2010 at 2:01 PM, Karthick Gururaj <karthick.gururaj@gmail.com> wrote:
On Tue, Dec 21, 2010 at 12:09 PM, Phani Deepak Parasuramuni
<phanidee@gmail.com> wrote:
> Hi,
> Is there anyway I can insert some text(say "Phani%d",count) into the buffer
> at cursor position?
> This is my use case.
> I have a code where in at specific places I have some text like "// PLT".
> Now I want to append a serial number to this 'PLT' every where. So that all
> the lines with PLT will now become  "// PLT1", "// PLT2" etc.,
> This is the way I am thinking of doing this.
> 1. Maintain the count in global variable say PLT_count
> 2. First search for "// PLT"
> 3. Now record a macro(a) with these commands
>       a. qa ; record the macro to register a
>       b. call MyFunc which appends the PLT_count to "PLT"
>       c. n ; so that I 'll move cursor to the next PLT line.
>       d. q ; stop recording
> Now since I know that I have 55 occurrences of PLT
> I 'll do 55@a
> Now, the problem is how to write MyFunc, where I specifically need to insert
> text( "%d",PLT_count) at the cursor position.
With the cursor on 'P' of PLT, you can execute:
  :execute 'normal ' . 'RPLT' . PLT_count

--
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 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

No comments: