Tuesday, May 31, 2011

Re: Vim scripts: insert new line staying with normal mode

On 2011-05-31, Steven Lee wrote:
> Hi all,
>
> It sounds like some vim users have asked similar question, but not
> exactly what I want.
>
> I attempt to write a function implementing insert new line which
> filled consecutive '=' :
>
> let len = 5
> let @x = '='
> exe 'normal! ' . 'o\\<Esc\\>0' . '"x' . len . 'p'
>
> My solution is below:
> 1. o -- enter new line below current line
> 2. <Esc> -- go back to normal mode
> 3. 0 -- go to head of line
> 4. "x5p -- copy 5 times using register x value, i.e. '='
>
> But with step 2, it did not work as I thought. It did not go back to
> normal mode.
>
> How can I correct above scripts?

It will work if you change the quoting of the <Esc> like this:

exe 'normal! ' . "o\<Esc>0" . '"x' . len . 'p'

Regards,
Gary

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

Post a Comment