11

Say I have a comment like this:

//This is a comment

And I want to make it like this:

//*****************
//This is a comment
//*****************

Is there an easy way to insert a character repeatedly until even with the next/previous line?

  • To generate patterns like this you might want to use a snippet engine. You can read this question for a comparison of the snippets plugins. For example with ultisnips you could do ibox<key>This is a comment (where <key> is a key you define to trigger snippets) and that will create a box of the right size with this is a comment inside. – statox Dec 30 '16 at 10:33
  • (17a*<Esc> would be something you could use In a similar situation where you know the number of characters you need, or the exact number doesn't matter because it doesn't have to be evenly aligned with another line.) – Aaron Thoma Jan 14 '17 at 16:36
10

Short answer

v $ r *

:help v_r


Longer

y y p / P     Duplicate line to below/above

2 l                    Move to position from where to overwrite (in this case 3rd column ← 2 to the right)

v $                  Select till end of line

r                          Replace all selected characters by char…

*

2

At the occasion°:

Insert mode mappings to replicate the remainder of adjacent line

" Insert the rest of the line below the cursor.
" Mnemonic: Elevate characters from below line
inoremap <A-e> 
    \<Esc>
    \jl
        \y$
    \hk
        \p
        \a
" Insert the rest of the line above the cursor.
" Mnemonic:  Y depicts a funnel, through which the above line's characters pour onto the current line.
inoremap <A-y> 
    \<Esc>
    \kl
        \y$
    \hj
        \p
        \a

Copying single characters from neighbouring lines in Insert mode

…is built-in: :help i_CTRL-E:

CTRL-E   Insert the character which is below the cursor.
CTRL-Y   Insert the character which is above the cursor.

° Not what the question text was about, but what other users might be looking for here, going from the current question title "insert until even with next line".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.